Do you think you have great ideas about the market but don’t know how to put them to the test without risking your funds? Learning how to backtest trade ideas is the bread and butter of a good systematic trader.
The underlying premise of backtesting is that what worked in the past may work in the future. But how do you go about doing this yourself? And how should you evaluate the results? Let’s go through a simple backtesting process.
Backtesting is one of the key components of developing your own charting and trading strategy. It’s done by reconstructing trades that would have happened in the past with a system based on historical data. The results of backtesting should give you a general idea of whether an investment strategy is effective or not.
What is backtesting?
In short, the main purpose of backtesting is to show you whether your trading ideas are valid. You use past market data to see how a strategy would have performed. If the strategy looks like it has potential, it may also be effective in a live trading environment.
What to do before backtesting
Discretionary trading is decision-based - traders use their own judgment for when to enter and exit. It's a relatively loose and open-ended strategy, where most of the decisions are up to the trader's assessment of the conditions at hand. As you’d expect, backtesting is less relevant when it comes to discretionary trading since the strategy isn’t strictly defined.
This, of course, doesn’t mean that if you’re a discretionary trader, you shouldn’t backtest or paper trade at all. It just means that the results may not be as reliable as in the other case.
Systematic trading is more applicable to our topic. Systematic traders rely on a trading system that defines and tells them exactly when to enter and exit. While they have complete control over what the strategy is, the entry and exit signals are determined by the strategy. You could think of a simple systematic strategy as:
- When A and B happen at the same time, enter a trade.
- When X happens after, exit the trade.
Some traders prefer this approach. It can eliminate emotional decisions from trading and provide a reasonable degree of assurance that a trading system is profitable. Of course, there are still no guarantees.
This is why it’s important to make sure that you have very specific rules in your system for when to enter or exit positions. If the strategy isn’t well-defined, the results will be inconsistent as well. As you might expect, this kind of trading style is more popular with algorithmic trading.
There is backtesting software out there that you can buy if you want to do automatic backtesting. You can input your own data, and the software will do the backtesting for you. However, in this example, we’ll go for a manual backtesting strategy. It’ll take a little bit more work, but it’s completely free.
How to backtest a trading strategy
|Date||Market||Side||Entry||Stop Loss||Take Profit||Risk||Reward||PnL|
So, let’s backtest a simple trading strategy. Here’s our idea:
- We buy one Bitcoin at the first daily close after a golden cross. We consider a golden cross when the 50-day moving average crosses above the 200-day moving average.
- We sell one Bitcoin at 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 also defined the time frame where the strategy is valid. This means we won’t consider it a trading signal if a golden cross happens on the 4-hour chart.
For the sake of this example, we’ll only look at the time period going back until the start of 2019. However, if you’d like to get more accurate and reliable results, you could go back much further in Bitcoin’s price action.
Now, let’s see what trading signals this system produced for the period:
- Buy @ ~$5,400
- Sell @ ~$9,200
- Buy @ ~$9,600
- Sell @ ~$6,700
- Buy @ ~$9,000
Here’s how our signals look overlaid on the chart:
Golden cross-death cross strategy. Source: TradingView.
Our first trade would have turned a profit of about $3800, while our second trade resulted in a loss of about $2900. This means our realized PnL is currently $900.
We’re also in an active trade, which, as of December 2020, has about $9000 unrealized profit. If we stick to our initially defined strategy, we’ll close this when the next death cross happens.
Evaluating backtesting results
So, what do these results show? Our strategy would have turned a reasonable return, but it doesn’t show anything that outstanding so far. We could realize the currently open trade to drastically increase our realized PnL, but that would defeat the purpose of backtesting. If we don’t stick to the plan, the results won’t be reliable either.
But what else can backtesting results show you?
- Volatility measures: your maximum upside and drawdown.
- Exposure: the amount of capital you need to allocate for the strategy from your entire portfolio.
- Annualized return: the strategy’s percentage return over a year.
- Win-loss ratio: how much of the trades in the system result in a win and how much in a loss.
- Average fill price: the average price of your filled entries and exits in the strategy.
We’ve gone through the basic process of how to do a manual backtest of a trading strategy. Remember, past performance isn’t a guarantee for future performance.
Market environments change, and you’ll need to adapt to those changes if you’d like to improve your trading. Generally, it’s also useful not to blindly trust the data. Common sense can be a surprisingly useful tool when it comes to evaluating results.