Summary
Do you think you have a great idea about the markets but don't know how to put it into practice without losing real money? Knowing how to backtest your trading strategies is an essential skill for a good system trader.
The premise behind backtesting is that what worked in the past may also work in the future. But how do you backtest, and how do you evaluate the results? Let's take a look at a simple backtesting process.
Introduction
Backtesting is one of the key elements of developing your own charting and trading strategies. It involves reconstructing possible trades that occurred in the past using a system based on historical data. The results of a backtest will give you a rough idea of whether an investment strategy is working.
What is backtesting?
First, if you want to learn more about what backtesting is, you can read our article What is Backtesting?
In short, the main purpose of backtesting is to show you whether your trading idea is effective. You can first use past market data to see how your strategy performs. If the strategy looks promising, it is likely to work in a real trading environment.
What to do before backtesting?
Before you start backtesting, you need to decide what type of trader you are. Are you a discretionary trader or a systematic trader?
Discretionary trading is based on decision making — traders use their own judgement to decide when to open and close positions. It is a relatively loose and open-ended strategy, with most decisions depending on the trader's assessment of the situation at hand. Therefore, backtesting is less important in discretionary trading, as this strategy does not have strict definitions.
Of course, this doesn't mean that if you are a discretionary trader, you shouldn't use backtesting or paper trading at all. It just means that the results won't be as reliable as those obtained by a systematic trader.
Systematic trading is more suitable for backtesting. Systematic traders rely on a trading system that defines and tells them when to open or close a position. Systematic traders control most aspects of the strategy, but the timing of opening and closing positions is entirely determined by the strategy. You can think of a simple systematic strategy as two steps:
When A and B occur simultaneously, enter the trade.
When X happens, exit the transaction.
Some traders prefer this approach. It can eliminate emotional decision making from trading and provide a reasonable guarantee that the trading system will be profitable. Of course, no guarantee is absolute.
This is why it is important to ensure that you have specific rules in place in your system regarding when to open or close a position. If your strategy is not clearly defined, the results will be inconsistent. As you might expect, this style of trading is more popular in algorithmic trading.
If you want to automate the process, you can buy backtesting software - you just enter your data and the system backtests for you. But for this example, we'll walk you through a manual backtesting strategy. It takes a little more work, but it's completely free.
How to backtest a trading strategy?
You can find a Google Spreadsheet template at this link. You can use this basic template as a base to create your own. It will give you an idea of what information a backtest spreadsheet might contain. Some traders prefer to use code in Excel or Python, and there are no hard and fast rules. You can add the data you need, and any other information you think would be useful.
Let's backtest some simple trading strategies:
We buy one Bitcoin on the first daily close after a golden cross. We consider a golden cross to be when the 50-day moving average is above the 200-day moving average.
We sell one Bitcoin on the first daily close after a death cross. We consider a death cross when the 200-day moving average crosses below the 50-day moving average.
As you can see, we have also defined the timeframe in which the strategy will be effective. That is, if the golden crossover occurs on the 4-hour chart, it will not be considered a trading signal by us.
The time period in this example starts at the beginning of 2019. However, to get more accurate and reliable results, you can go back further into Bitcoin’s price history.
Now, let's take a look at what trading signals the system generated during this period:
Buy in @~$5,400
For sale @ ~$9,200
Buy in @ ~$9,600
For sale @ ~$6,700
Buy in @ ~$9,000
Here is what our signal looks like when overlaid on a chart:
Our first trade will make a profit of about $3800, while the second trade will result in a loss of $2900. This means our realized PNL is $900.
We are also actively trading, with unrealized profits of about $9,000 as of December 2020. If we had stuck to the strategy we originally developed, we would have closed the position at the next death cross.
Evaluating Backtesting Results
So what do these results tell us? Our strategy should have delivered reasonable returns, but it hasn't delivered any stellar performance so far. We could significantly increase our realized P&L by executing our current open trades, but that defeats the purpose of backtesting. If we don't stick to our plan, the results won't be reliable.
Even though this is just a system strategy, the specific context should still be considered. The unprofitable trades from $9600 to $6700 occurred during the crash caused by the COVID-19 pandemic in March 2020. This kind of black swan event can have a huge impact on any trading system. Because of this, we need to backtrack further to understand whether this loss was an anomaly or just a side effect of the strategy.
This is an example of a simple backtesting process. If we backtest and test it with more data, or include other technical indicators it may produce stronger signals, making the strategy more promising.
But what else can backtest results tell you?
Volatility measures: your maximum upswings and drawdowns.
Risk Exposure: The amount of money you need to allocate from your entire portfolio to execute the strategy.
Annualized Return: The percentage return of this strategy in one year.
Profit and Loss: How many trades in the system are likely to be profitable and how many are likely to be losing trades.
Average Transaction Price: The average price of opening and closing positions that you traded in the strategy.
Please know: The examples above are not exhaustive of what backtesting can do. It is up to you to decide which indicators you want to track. Regardless, the more details you record in your trading journal about your setups, the more opportunities you have to learn from your results. Some traders are very rigorous in their backtesting, and this may be reflected in their results.
One final factor to consider is optimization. If you have read our backtesting article, you will know the difference between backtesting and forward testing (paper trading).
Conclusion
We have gone through the basic process of manually backtesting a trading strategy. However, it is important to remember that past performance is not an indicator of future performance.
Market conditions change rapidly, and you must adapt to these changes if you want to improve your trading strategy. You also need to remember not to blindly trust the data. Common sense (although often overlooked) is also a very useful tool when evaluating results.
Further reading
A Beginner's Guide to Swing Trading Cryptocurrencies
What is Carry Trading?
What is a trading journal and how to use it
What is Crypto Scalping?
What is behavioral bias? How to avoid it?