Inspiration
Our inspiration was to gain an understanding of financial markets and see whether by applying theory, careful risk management, and good code structure we can create durable trading strategies.
What it does
We built a framework for selecting and applying trading strategies, which can be modified to account for marketplace limits and connection faults. Our primary strategy performs “dual market hedging” - it places quotes in a less liquid instrument to make competitive best asks and best bids based on prices in the more liquid order book. Then, any outstanding positions will be hedged and quotes updated.
How we built it
We trialled many different strategies, monitoring their resultant PnL and their durability given different market behaviours. Eventually we deduced which techniques worked best (“best” being a tradeoff of risk and profit) and wrote our more advanced dual hedging method.
To optimize our method, we collected data on our PnL for different offsets from the theoretical value of market A, when quoted as a best ask and bid in market B. This is because there is a trade-off between profit from two-sided quoting and loss from hedging, where a greater span earns more when successful, but risks being undercut. This would tell us what the best offset to apply is, and completes the unknown variable in the model.
We also included a robust strategy to manage connection loss. We trade in bursts of high frequency, with breaks while waiting for opportunities to arise, but if disconnected during a burst, it will reconnect as fast as possible and neutralise our position. The code to restore position aims to balance quickly restoring to zero (eliminating further vulnerability to market shifts), with getting good value.
The functionality is all implemented in Python using Optibook’s API.
Challenges we ran into
- Learning terminology and trading concepts - none of us had trading experience before today, but were enthusiastic to learn and got a handle on it using articles online and resources from Optiver.
- What happens if only one order in a two-sided quote is fulfilled - how do we return to 0 (for immunity to market motion) position safely and as quickly as possible?
- Competing against many traders injects extra liquidity into market B, so it becomes harder to exploit. Improving our bots performance when the exchange is filled with other market makers proved difficult, requiring changes in strategy
- Implementation needs to consider what happens when too many positions in A and B are acquired, separately, even if net position is 0, to avoid disconnecting.
- What happens if you lost money? This probably meant, we assumed, that our hedges on average are losing more money than the credit gained from buying and selling simultaneously in the less liquid order book.
What we learned
- If only one order is fulfilled, we need to hedge as fast as possible in the more liquid market to cut long-term losses, hoping that the profit made is greater than hedging loss. As long as quotes are updated often, this means that on average, we expect the quote placed in market B is very close to the actual price in market A.
- More liquid markets will always lead less liquid markets for the same stock, because you have more buyers and sellers so changes occur faster. This does not mean there is less overall change for market B, only that we expect its value to follow that of market A.
- Injecting liquidity is the basis of market making. The dual market strategy ensures the two markets follow each other.
- We should prioritise keeping 0 position (secure algorithm that will not leave us long or short) over short-term PnL.
What's next for Trade charade
- Improving our strategy-running code (bot.py) to safely run multiple strategies at once (sequentially updating each in turn). Namely this involves altering the strategy class to track which orders belong to itself to avoid conflicting with concurrent strategies. This is a feature which we began writing but didn’t quite have time to complete.
- Extending the dual hedging strategy to further optimise it - really the algorithm could be extended forever with improvements and heuristics, but there is eventually a trade-off of code complexity.
- Testing the resilience of our algorithms in other markets. For example, we began writing a “fake exchange” class to simulate other environments - we could also pull data from other real-world exchanges. Ideally, the strategies we developed should work beyond Optibook.
Built With
- optibook
- python



Log in or sign up for Devpost to join the conversation.