vegaprotocol / vega-market-sim

Build and interact with a self-contained Vega chain with controllable passage of time
MIT License
19 stars 8 forks source link

feat: HedgedMarketMaker scenario #258

Closed cdummett closed 1 year ago

cdummett commented 1 year ago

Goal:

Create a scenario to mimic a Market-Maker (MM) who wants to follow a hedging strategy; i.e. making a market on a Vega network (profiting of fees) and hedging its position on a highly liquid external exchange.

Viability of strategy relies on the MM being able to move funds between the exchanges fast enough to prevent close-outs from insufficient margins.

Aim:

Test whether Vega's withdrawal delay is too long or its margin requirements too strict for this strategy to be viable

Scenario

Markets

Scenario will have two markets:

  1. MarketA - represents an expected early Vega market (price_process can follow MarketB)
  2. MarketB - represents a highly liquid external market (price_process can follow an external source)

The MM will operate in both markets and have a separate key for each market (KeyA and KeyB). The keys represent the separate accounts on the Vega network and external exchange. The MM will be able to transfer funds between keys but subject to delays. Moving funds from KeyB too KeyA will have small delays (e.g. 15m) but moving funds from KeyA too KeyB will have large delays (e.g. 24h). This is to mimic Vega's withdrawal delays.

The MM will follow a hedging strategy, posting limit orders on MarketA, and hedging its position on MarketB (the "external" market). The MMs order depths will be determined such that is it able to profit off the liquidity + maker fees. The MM will then move funds between keys to manage it's margins and prevent close-outs.

Agents

In MarketA an InformedTrader who is aware of the next price will generate a position for the MM. We can run two cases one where the InformedTrader is correct (and the MM will have to transfer funds from KeyB to KeyA, encountering no delays) and one where the InformedTrader is incorrect (and the MM will have to transfer funds from KeyA to KeyB, encountering delays)

ToDo:

davidsiska-vega commented 1 year ago

Sounds fun!

TomMcL commented 1 year ago

Instead of the slightly confusing Incorrect InformedTrader can we not just use the Uninformed trader with equally likely buy/sell probabilities?

TomMcL commented 1 year ago

Whilst the two scenarios mentioned above are probably useful to run for testing limits, I think I'd add a third where we use MarketOrderTrader (the uninformed trader) with a reasonable amount of flow. InformedTrader right/wrong can give us extreme cases but predominately random flow should hopefully give a more realistic picture of where the market maker's balance is going to end up.

cdummett commented 1 year ago

Whilst the two scenarios mentioned above are probably useful to run for testing limits, I think I'd add a third where we use MarketOrderTrader (the uninformed trader) with a reasonable amount of flow. InformedTrader right/wrong can give us extreme cases but predominately random flow should hopefully give a more realistic picture of where the market maker's balance is going to end up.

Could we add an accuracy arg (float between 0 and 1) to the InformedTrader just to avoid adding agents to the scenario which aren't used in all cases @TomMcL ? Setting that to 0.5 should give us the more realistic case where a speculating party is right half the time.

Also, spin-off question, any objections to adding a lookahead arg to the InformedTrader also. At the moment if the market-makers spread is too large (fairly often with the hedged market-maker) the InformedTrader never acts as it is only looking one step ahead.