Inspiration

Being interested in the stock market and investment opportunities, we found committing to a project combining informatics and finance to be highly worthwhile. Not only was this something we have never done before, but it was definitely a good opportunity to learn something new. Our primary methodology for this project was understanding how investment and arbitrage situations arise, and putting ourselves into the shoes of real investors - trying to understand when they would buy and sell. Our main inspiration came from hoping to learn something new and possibly apply it in our futures to find arbitrage opportunities in real life.

What it does

The aim of this challenge was to create a bot which makes money on the difference of prices of 2 bundles of stocks (AMAZON and GOOGLE) and their basket (TECH BASKET). In order to achieve this we came up with a novel strategy: We take the sum of the highest bids and lowest asks for both AMAZON and GOOGLE, and the highest bid and lowest ask for the TECH BASKET. We make a trade in 2 scenarios:

  1. when the highest bid of GOOGLE and AMAZON combined is greater than the highest bid of TECH BASKET and the lowest ask of both GOOGLE and AMAZON is higher than the lowest ask of TECH BASKET
  2. when the highest bid of GOOGLE and AMAZON combined is lower than the highest bid of TECH BASKET and the lowest bid of both GOOGLE and AMAZON combined is lower than the lowest bid of TECH BASKET.

In scenario 1 we place ask limit orders for GOOGLE and AMAZON and at the same time we place a bid limit order for TECH BASKET. By countering our ask orders with bid orders we make use of hedging - this allows us to minimize the risk and make money only on the difference in prices of the basket and the two stocks (no speculation). The price of the limit orders for AMAZON and GOOGLE is determined as follows:

  • we take the lowest ask price for each, add the difference in the lowest ask for TECH BASKET and the highest bid for both AMAZON and GOOGLE, finally we add a small margin (set to 0.2). This allows us to hedge and make small profits (equal to the margin) without any risk. The limit price of the TECH BASKET bid is equal to the highest bid of AMAZON + GOOGLE minus the margin.

In scenario 2 we do the opposite: we place bid limit orders for GOOGLE and AMAZON and at the same time we also place an ask limit order for TECH BASKET. The price of those is determined as follows:

  • For AMAZON and GOOGLE it's the lowest ask for each minus the difference in the lowest ask (for both GOOGLE and AMAZON) and the highest bid of the TECH BASKET minus the margin (0.2)
  • For TECH BASKET it's the highest bid of AMAZON and GOOGLE minus the margin

We trade with a frequency of 0.2 seconds (we empirically tested this and this is the most often we can trade without exceeding the request limit) and with a volume of 1 (this decreases the risk further because we make sure that if there are no open orders for a certain instrument we only have a slightly unbalanced portfolio)

How we built it

We first wanted to build the bot using Java in order to get lower execution times, but in the end we decided to use python. That’s because the API provided by Optiver was in python.

Accomplishments that we're proud of

Most importantly, we are extremely proud to have produced a working, profitable, bot. Starting the project we had attempted to implement multiple different strategies, ending up with the one that proved to be the most efficient and profitable in both the short run and longer run. This is definitely something we are proud of. Lastly, we are also proud of how we handled risk. In many cases in the real world, shorting can be very risky as the potential loss is much higher than the maximum gain. However, by hedging and adjusting the volumes and our logic in ioc and limit trades, we believe to have found the optimum risk-profit ratio whilst being neither too risk averse or risk loving. Lastly, we are also very proud of the role our bot had in being market makers by providing liquidity through placing limit orders at a good price.

What we learned

We came into this project hoping for a challenge, and we were not disappointed. From the beginning to the end, we faced situations we never previously encountered. Starting off, we learned a lot about finance and the terminology - hedging, shorting, liquidity and market makers and the relationship between bid and ask. We also learned how to operate a bot successfully and constantly improve it’s logic to adapt to market conditions. Lastly, we definitely learned how to cooperate as a team in creating multiple different trading algorithms and combining them into a single most optimal one which considers multiple scenarios.

What's next for Optiver trading bot

We hope to adapt it in the future and use it in real world scenarios which, from this challenge, we learned can arise!

Built With

Share this project:

Updates