A Taste of HFT Strat Dev
I’ve been working on a high-frequency trading strategy project for the past few months. Unfortunately, the project rests on the university GitLab, so I can’t open source our fantastic repo (my teammate created a fork here!). The project expands around RCM-X’s Strategy Studio, and a full report is here. This article summarizes different components of the project and hopefully serves as insights for others working with Strategy Studio.
Data
Data was the trickiest part. HFT strategies rely heavily on accurate nanosecond scale order by order data almost unattainable by individuals. Even if we find the possible data, we still need parsers to convert raw data to Strategy Studio usable format. In the end, we incorporated three data sources that mimic the actual trade data as close as possible.
IEX DEEP
We heavily relied on this data source because of its high availability. It’s available daily and contains trade and order book depth data. Also, our prof gave us the parser, so we plugged in and played.NASDAQ ITCH
This was another useful data source. However, it’s only available on certain days. Therefore, it did not help with our dev too much. We created a parser by simplifying this original implementation.SIP (from Alpaca)
This data source only contained NBBO data. Even though we wanted to incorporate it (due to the high availability), we did not have much luck since Strategy Studio documentation did not include sections for using SIP data. Nevertheless, we still implemented a parser for it.
Strategies
Strategy is the core and most exciting part. We implemented four strategies and backtested them against the market in April and May (when they were crashing), and all the strategies outperformed buy-and-hold. Here are the strategies:
- Buy last and sell first
Yes, the strategy is literally to buy in the last two minutes of the current trading day and sell them in the first two minutes of the next trading day. It sounded absurd, but we made a profit from SPY when it dropped from 450 to 415. - Mean Reversion Strategy
The strategy assumes that the ticker’s price will move toward the mean price of the last 1000 trades. This was a promising strategy since it doubled our assets within three days. However, due to the volume of trade actions, our VM OOMed, and we could not test on more days. - Arbitrage
A classic strategy trades one ticker based on the movement of another ticker. We picked SPY and AAPL because AAPL is one of the most considerable portions of the SPY. However, we only implemented the Long side, so we did not gain much profit from it in a downward market. - Swing Strategy
Use momentum to track local minimums and maximums, then make trades accordingly. This is like the real-world swing that travels from high to low.
They are implemented by extending StrategyStudio’s Strategy
interface. The interface has several event triggers that allow our strategies to submit/cancel/update orders. For instance, , the onBar
method will be triggered for the bar quote for a specified time interval. Due to the data availability, we focused on using the onTrade
method, which runs whenever a trade is filed.
Analysis && Automation
We wrote a python script to generate visualizations and calculate earnings. We also established Gitlab CI for automatic code linting and wrote Bash script to test strategies automatically since we don’t want to type in the terminal every time.
Was these results ideal?
Definitely not. We did not get the chance to incorporate all the ticker data we wanted, and we could improve our strategies by tuning parameters/picking better base tickers. I guess I had the excuse of a busy final week, but I would improve this if I had more time.