How I Built My First Trading Bot For Hashnode's Hackathon
Hello everyone! I'm excited to showcase a mini project that I've built for Hashnode's Christmas Hackathon. I will be explaining the inspiration behind this project, how I built it, some challenges I faced along the way and what I've learnt from partaking in this spontaneous hackathon. Let's begin!
Financial Technology aka FinTech is a broad term for financial services or products that integrates technology to automate and optimize its uses. As a developer, I've always been interested in stocks and investments; in particular, the use of robo-advisors and trading bots today have piqued my curiosity for quite a while.
Hence, by participating in Hashnode's Hackathon, I thought it will be a good opportunity for me to try something new as a fun challenge.
How I Built It
The algorithm is created and build on QuantConnect (QC) - a browser-based algorithmic trading platform. It is a simple yet powerful platform that empowers anyone to build, backtest and execute their own trading algorithms.
QC supports both Python and C#. I signed up for a free account. Then I spend the next few hours learning on how to navigate and use the platform via its bootcamp courses.
At first glance, it seems overwhelming to use. Just understanding all the tools, different modules and strategies available for use is difficult, maybe even more so for someone without financial knowledge. I recommend reading up on some finance 101 books to know what is a close, open, high, low, RSI, MACD, Bollinger Bands, etc. or else it will be too confusing to learn both the technical and financial aspects at the same time.
After familiarizing myself with the platform, I got down to business (kind of).
The biggest challenge I faced when doing this hackathon is definitely time management. Time was a precious resource in my case. I have a full-time job, as well as other commitments, and so I had to allocate my time wisely and progress patiently on this project. When I have decided to build a trading bot as the project for this hackathon, I researched whenever I am free for 2 days before finally discovering and deciding to go with QC.
Another unforgettable challenge was researching and deep-diving into a not-so-familiar territory for me: the QC platform and trading strategies. The QC platform was incredibly overwhelming, I had to spend hours just reading the documentation to understand their modules and know how to apply them. I have zero clue on how to design profitable algorithms and testing them.
I looked up various trading strategies like pairs trading, momentum-based, short-term reversals, mean-reverting and so on. Risk and return are trade-offs to be carefully managed in every strategy. That is something that I have to bear in mind when implementing my trading bot, and is quite a huge challenge for a beginner like me.
Note: some articles/papers I found helpful are listed below in the Resources section.
Results & Next Steps
After testing my algorithm for several rounds of backtesting, it is clear that the algorithm is unstable. The results show that it is unreliable for live trading and definitely needs more improvement to work on (see Exhibits below).
Exhibit A: Worst profits
Exhibit B: Best profits
The next steps in this project would be to get more financial expertise (from a friend perhaps) to be able to build a better bot. I noticed that on test runs where the returns are high, it is most likely due to overfitting and not because the bot was doing well. Therefore, learning the various modules (i.e. machine learning) and trading strategies on QC will be a good idea to progress and test the algorithm more smoothly.
Thanks for reading! I hope everyone has built something awesome and cool for Hashnode's Hackathon. I shall be reading up on the tag #christmashackathon and I look forward to more interesting reads soon! Happy holidays, stay safe and cheers!
- Bland, G. (2020, November 12). QuantConnect - A Complete Guide - AlgoTrading101 Blog. Retrieved December 23, 2020, from algotrading101.com/learn/quantconnect-guide
- Faber, M. (2010, April 20). Relative Strength Strategies for Investing. Retrieved December 23, 2020, from papers.ssrn.com/sol3/papers.cfm?abstract_id..
- Faber, Meb, A Quantitative Approach to Tactical Asset Allocation (February 1, 2013). The Journal of Wealth Management, Spring 2007, Available at SSRN: ssrn.com/abstract=962461
Volta, V. (n.d.). Profitable Algorithmic Trading Strategies in Mean-Reverting Markets. Retrieved December 23, 2020, from academia.edu/42655318/Profitable_Algorithmi..
Cover image background from freepik.com