DEV Community

loading...

How I Built My First Trading Bot For Hashnode's Hackathon

lo_victoria2666 profile image Victoria Lo Originally published at lo-victoria.com on ・4 min read

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!

Inspiration

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.

image.png

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).

Challenges

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.

image.png

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

image.png

Exhibit B: Best profits

image.png

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.

Overall, this hackathon sure teaches me that there is no limit to learning as a developer. Technology can be found integrated in various sectors, such as Finance. Building a product that synergizes in both the tech and finance industry was thrilling yet challenging. I sure hope to continue learning as much as I can now that this hackathon has given me a head-start. Plus, I like this hackathon allows me to spend some time with my old friend: Python, after coding in JavaScript for a long time.

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!

Resources

Discussion (0)

pic
Editor guide