MultiversX Tracker is Live!

I made an Open source tool to help you backtest your trading or investment strategy

All Cryptocurrencies

by COINS NEWS 12 Views

I made an Open source tool to help you backtest your trading or investment strategy

Backtesting a strategy means applying it to a historical dataset and seeing how it would have performed on past data. The results should then determine if this is a potentially viable strategy to start live trading/investing with, or whether it needs some more fine-tuning.

The problem with backtesting strategies is that it usually requires you to pretty much re-write your backtesting algorithm because each strategy needs to be configured to act in a specific way. To get around this issue, I made a simple tool that allows you to easily create plug-and-play strategies and slot them into the Backtester.

The tool is written in Python and uses the Backtester py library to handle backtesting and reporting. Because it's modular it's very easy to code a strategy and test it. For instance, here's how you'd go about coding a Buy The Dip strategy:

class BuyTheDip(Strategy): def init(self): pass def next(self): current_close = self.data.Close[-1] # Current candle's close previous_close = self.data.Close[-2] # Previous candle's close price_difference = (current_close - previous_close) / previous_close * 100 if price_difference <= -5: self.buy( size=0.1, sl=stop_loss * current_close, tp=take_profit * current_close ) print( f"Bought at {current_close}, which is a {price_difference}% from previous close ({previous_close})" ) else: print(f"Did not buy, price difference is only {price_difference}%") 

Here, we want to buy Bitcoin every time the price drops by more than 5% compared to the previous candle close.
Running the strategy will output its performance like so:

https://preview.redd.it/itzhrks3o3ie1.png?696&format=png&auto=webp&s=191567e62b2d5271c929805c05141aed28e944e6

Buy and Hold Return%, Return %, Win Rate and Profit Factor are metrics you need to look out for.

  • Buy and Hold return tells us whether it's more advantageous to simply buy and hold rather than trade over that specific period
  • Return % is the amount of profit made trading
  • Win Rate is a percentage showing how many of our trades are profitable. As you can see buying dips and selling them at a 5% take profit gives us a 90% profitability rate.
  • Profit Factor represents the gross profit divided by the gross loss

The backtester will also plot the performance, showing you the entry and exit positions on a candlestick chart.

https://preview.redd.it/hjvf15c1o3ie1.png?3771&format=png&auto=webp&s=ff61f16011326f21560cb4bcc4e59f4e89d5aed1

In my example, I used CoinGecko API to fetch historical data, but you may use any data source you wish, as long as you feed it candlestick data.

For those interested in trying out the tool, here's the link to the GitHub repo:

https://github.com/CyberPunkMetalHead/python-backtesting-bot

submitted by /u/CyberPunkMetalHead
[link] [comments]

Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
πŸ’° Install these recommended apps:
πŸ’² SocialGood - 100% Crypto Back on Everyday Shopping
πŸ’² xPortal - The DeFi For The Next Billion
πŸ’² CryptoTab Browser - Lightweight, fast, and ready to mine!
πŸ’° Register on these recommended exchanges:
🟑 Binance🟑 Bitfinex🟑 Bitmart🟑 Bittrex🟑 Bitget
🟑 CoinEx🟑 Crypto.com🟑 Gate.io🟑 Huobi🟑 Kucoin.



Comments