Backtest Bitcoin Trading Strategies
The client, a crypto trader, hired us to backtest two trading strategies. We wrote python scripts to implement the strategies and backtest their performance using historical data from cryptoquant.com and bitmex, while accounting for trading fees (Kraken).
Each strategy output three signals (“Buy”, “Sell”, or “Hold”), for example, at the end of each 24 hours if trading frequency was daily, and every 4 hours if trading frequency was 4-hour. Our python scripts carefully calculated the profit and loss after each trade and tracked the account balance over time, while taking care of stop losses and accounting for all possible fees, including trading fees and margin account open and rollover fees. For each strategy, our scripts gave three scenarios: no leverage, 3x leverage, and 5x leverage. Our scripts also tested what would happen if we short-sold BTC every time when there was a ‘Sell’ signal. Finally, We wrote R scripts to plot account balance over time and analyzed 5-day, 10-day, 15-day, 30-day, 90-day, 180-day, and 365-day returns and risks.
After the project, we realized that we had written a general backtesting tool. Say you have a BTC trading strategy and you want to keep it secret, but you also want to know how well it would’ve performed historically. You can run your strategy over historical data and generate a csv file of two columns: timestamp and trading signal (‘Buy’, ‘Sell’, or ‘Hold’). You can then feed the csv file into our tool, with an exchange selected (Kraken, Binance, Bitmex, and etc.), and you will get a performance report like this.