Team name: team-018

Motivation

Our motivation for this project came from the challenge presented by Optiver at HackUPC 2023, which focused on the relationship between increased trading interest and lower costs for investors in financial products. We were intrigued by the concept of baskets of stocks and their tradable instruments, such as ETFs, which have become increasingly popular in today's financial markets. Through our trading algorithm, we aimed to successfully trade the two baskets of fictive energy companies provided in the challenge, leveraging our knowledge of market behavior and trading strategies to optimize our results.

What it does

Our project aims to implement, develop and integrate a trader algorithm in the Optibook environment that is able to apply two distinctive strategies together, simulating the function of market makers but in the specific use case of this "fictive" energy companies stock market.

The first strategy implemented consists of detecting opportunities in the energy basket's order book and hedging the trades in the order books of the two stocks. To detect opportunities, the fair price of the basket is calculated based on the prices of the two stocks using the following formula: basket_price = SUM(stock_weight * stock_price FOR EACH stock)

If the order book shows that the basket can be sold for a higher price than the fair price, a profit can be made. However, to avoid losses from market moves, it is essential to hedge the trade by buying the stocks in the right ratio, and that has been one of the major challenges we have faced when trying to solve this problem.

In addition, we also aim to simulate the market-maker strategy by continuously quoting in the energy basket's order book and using limit orders to hedge trades in the two underlying stocks. This strategy helps to increase market liquidity and reduce market volatility by narrowing the spread in the order books.

How we built it

The code is developed in Amazon's "Cloud9" environment using Python. The part of the trading algorithm that we have implemented, this is, excluding the settings and connections related to the Optibook environment -which were already provided by the company-, is organized into two python scripts. One is a class that defines all the logic behind the strategy of the trading algorithm, and the other one instantiates this class (optitrader.py) and runs the algorithm to interact with the markets (main.py).

Challenges we ran into

The first main issue was to get used to the different concepts involving stock trading and arbitrage and hedging approaches. Thankfully, Optiver provided some useful introductory tutorials on the topic which were very useful in understanding the problem we were facing and how to approach it.

The second important issue was to find hedging opportunities. This is quite a challenge as one can adapt different methodologies but mainly what we have done is find disconnections between the individual stocks and the basket that aggregates them.

The third challenge we faced was meeting the requirements (especially the hard constraints). The first constraint (1) states that "Total position (positive or negative) per instrument cannot go over 500". To avoid getting ourselves into this situation we always take into account our current positions before inserting any order (IoC or Limit) in the order book. We adapt the volume to bid or ask when inserting each order taking into account the current positions. The second constraint (2) determines that "it is not allowed to have total orders outstanding for over 800 lots per instrument". This one was quite easy to satisfy as we always check the volume of the offers we insert for each instrument before actually sending them. The third constraint (3) "You are only allowed to send 25 updates (inserts/deletes/amends) to the market per second" has been implemented using python decorators; we limit the number of market operations per second by storing a counter variable that accounts for the number of updates in the last second. Due to time constraints, we haven't been able to dive deep into the fourth constraint as much as we would have liked. However, after running our algorithm for some time, we have noticed that we do not break this restriction often and the fact that it is a soft constraint, allows us to keep performing operations without getting disconnected (only with a small penalization).

The fourth challenge was risk management. Our first approach was way too ambitious and we would buy/sell as much volume as the constraint let us when we detected a hedge situation. This approach implied taking too much risk and led to high volatility in our P&L metric. In the final version of the algorithm, however, we have opted to operate with smaller volumes, leading to a more stable and effective trading strategy.

We also faced a problem that didn't think of but that came up when starting to implement the second strategy involving the use of limit orders. What happened was that with a very low probability, the trading bot would bid against an ask order that it has placed previously by us. This would halt the program as this phenomenon is not allowed, since you would be trading your own orders (which doesn't make really sense).

Accomplishments that we're proud of

We are proud of having implemented (mostly) successfully both strategies and having integrated them together into the algorithm. We really wanted to make our trading bot not only effective at getting a high place in the leaderboard but also good at increasing the liquidity of the market and helping with the "general" goal of reducing the cost for investors that want to invest in the green energy market.

Built With

Share this project:

Updates