tyrel.cloud


All posts tagged:


Reflecting on 5 years of Algo Trading

Updated by Tyrel on 2021-12-31

Summary

The best algorithm is a simple one...

Listen to this article

The best algorithm is a simple one...

When I started FFB Investments in 2016 I had big dreams of building a High Frequency Trading (HFT) Algorithm that would compete against other HFT systems.

I started my journey by learning Python. I took a course on Coursera called Python for Everybody (PY4E) by Dr. Chuck.

What really made python stick for me was applying the knowledge to a goal. In my case it was this high frequency trading system, although I also found other use cases in my day-to-day job as a network engineer and in my personal life.

The better I got at python the more addicting it really became, I would spend hours and hours working on this project.

The first algorithm that I developed was a modified version of Bollinger Bands, you can learn more about Bollinger Bands Here.

Bollinger Bands were something that I used before the algorithm to trade and try and time entry and exit points in the market and it worked out pretty well for extremely volatile assets such as 3x leveraged funds like TNA.

So this is how it worked... I would use an Application Programmable Interface (API) call to Yahoo finance through pandas data reader module and pull down a year's worth of high, low, and close prices and then I would plug that info into this algorithm and it would tell me if it was a good time to buy or sell.

The next stage was not only knowing when it was a good time to buy or sell but actually placing the trades programmatically, that's where E-Trade came in. I got started using E-Trade's API and at the time it was free and they didn't charge you for real time market data or level 2 access.

This worked well for awhile even though their API was kind of archaic and a lot of it was XML based as opposed to JSON.

The problem that I ran into was this algorithm didn't trigger very often, it definitely wasn't high-frequency so I had to expand my assets.

This is when I began pulling all of the current tickers from this NASDAQ website on a daily basis and then scanning them. There's between 8 and 9 thousand tickers listed on the NASDAQ and New York Stock Exchange. I used this strategy in 2018 and into 2019.

And then comes the race to zero commissions in which exchange brokers reduced their per trade execution charges to fractions of cents. This really opened up a new world of opportunities as you could trade smaller lot sizes more frequently without the overhead of per trade execution charges.

Trade commission's were typically about $7 for either a buy or a sell, this meant that if you bought something for $100 and turn around and sold it for $114 you would have just broken even. As you can see in this model it pays to have large lot sizes in order to reduce the commission overhead percentage.

While effectively eliminating per trade commission fees was a huge win for retail investors it didn't come without downside. Brokers now had to find other sources of income. For some brokerages that also offered investment services it wasn't such a big deal but for others that didn't this was a huge hit and they turned to charging for API access and market data.

Because their API quote system used real-time data to deliver accurate quotes they could not differentiate between delayed market data access and real-time data... because of this if you had API access you also required real-time market data which came at the price tag of about $762 per month or $9,144 per year.

Which needless to say turn something cool into something not so cool especially if you did not require real-time market data for your trading system.

Long story short my API went unused for a couple months and my access was revoked because of the new market agreement requirements. This led to a change in strategy and using browser automation tools like selenium instead of official API access.

The strategy now is a simplified one in which we look at price movement and we placed trades at every single dollar increment, some know this as averaging down or buying the dip. We trade specific lots that we don't use any kind of a cost basis (FIFO, LILO, AVG). Initially we used to 2 to 1 ratio where if we bought it for $100 we would sell it for $102. Once the price drops back down to $100 we re-buy and repeat. This strategy works the best in highly volatile and sideways trading markets.

We have focused in on one very volatile asset to employ this strategy against which is the 3x leveraged fund TNA.

TNA is an ETF that tracks the Russell 2000 index

Fast forward to the end of 2021 and this algorithm has been running for a year consistently and resulted in a profit of roughly $100,000 over 857 trades (3-4 trades per day)...

Feel like I missed something? Let me know in the comments!