Improvements to backtesting crypto trading algorithm & results

Let’s pick up form where we left off last week – we coded a simple backtesting algorithm for our cryptocurrency trading needs. In other words, we wrote a script that will help us asses how profitable out trading strategy would be by running it over historical data.

More importantly, I pointed out how back-testing (or anything that doesn’t include YOLOing your life savings on calls) would probably enrage your /r/wallstreetbets purists.

In this post, I’ll share some improvements that I made to the backtesting crypto algorithm this week, and also share my own results after testing out the same strategy for: BTC, XLM, ICP, ETH and DOT. 

The changes

Multi coin support for downloading historical data. 

  • You can now define which coins to download historical data for in the coins.txt file
  • Data fetching is run on separate threads so the files are generated concurrently
  • Careful not to add to many coins at ones (Binance may temporarily ip-ban you)

Automatic conversion of trade_size

  • In maintester.py trade_size now represents the USDT volume to buy
  • This is then automatically converted into the coin bought (ie: trade_size = 10k is equivalent to a trade order of 0.03 BTCUSDT)
  • This is calculated whenver a historical trade is placed so it’s in line with the historical price at that time.

Multicoin backtesting support:

  • With the addition of threaded historical data download, it makes sense to pass all the data to the backtester
  • this is not threaded and will run sequentially, to avoid making a mess in the logs.

Download the latest backtester for crypto trading here and check out the set-up guide here

The results

I created the following trading strategy and applied to the historical price data for BTC, XLM, ICP, ETH and DOT.

  • Initial balance: $100k
  • Volume / trade: $10k
  • Buy if the price now is higher by at least 1% compared to 1 minute ago
  • Sell at 5% loss
  • Take profit at 10%

Bear in mind that this is a simple strategy that more than anything else displays how the backtester works. You should run your own variables, or include a trailing stop-loss to increase your profits.

BTC – 10% loss

Overall, the this strategy underperformed on BTC, with a final balance of 55k. However, hour value is around 90k which means some trades remain open. There are two issues with this strategy:

  • There is no risk management. Yes we have a stop loss, but this strategy could benefit from a signal that stops us from buying in a bearish market.
  • There is no trailing stop-loss. We could ride the bull for much higher than 10% thus maximising our profits. 

With that in mind, let’s see how the remaining coins have performed (without the above points).

XLM – 37% profit

Looks like we’re 37% in profit on XLM since the start of the year. Doesn’t beat buy and hold though.

ICP – breaking even

And that’s a great result considering ICP did little else but plummet ever since it was listed on Binance.

ETHUSDT – 11% in profit

Similarly to Bitcoin, the bulk of the losses happen during the correction from ATH. Again, a signal to help us stop from buying while the market is in free-fall would help maximise our profits – something to look forward to in the next article.

DOTUSDT – 83% profit

This is really good result! Without any other optimisation we’re almost beating the buy-and-hold for DOT.

Stay tuned, as I’ll be adding more features to the backtesting crypto algorithm, to further improve its profitability and use cases!

Did you enjoy this article? Please consider subscribing to the newsletter for more awesome content.

If you appreciate my content and would like to see more, you can support me by donating here or via the Brave Browser. This is much appreciated as it helps me to keep the content free and open source. Thank you!      

Leave a Reply

Your email address will not be published. Required fields are marked *