How to Backtest a Trading Strategy
ہوم
آرٹیکلز
How to Backtest a Trading Strategy

How to Backtest a Trading Strategy

Intermediate
شائع کردہ Dec 17, 2020اپڈیٹ کردہ Jun 21, 2023
7m

TL;DR

Do you think you have great ideas on the market but don’t know how to put them to the test without risking your funds? Knowing 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.

Introduction

Backtesting is one of the key components of developing your own charting and trading strategy. It entails 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 or not an investment strategy is effective.

What Is Backtesting?

First, if you’d like a deeper dive into backtesting, read our article What Is Backtesting? 

In short, the main purpose of backtesting is to show you whether your trading ideas are valid. You start by using 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?

Before you start backtesting, you must establish what kind of trader you are. Are you a discretionary or a systematic trader?

Discretionary trading is decision-based — traders use their own judgment to decide when to enter and exit. It's a relatively loose and open-ended strategy, where most of the decisions made depend on the trader's assessment of the conditions at hand. As such, backtesting is less relevant when it comes to discretionary trading since the strategy isn’t strictly defined.

Of course, this 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 they usually are with systematic trading.

Systematic trading is more applicable to backtesting. Systematic traders rely on a trading system that defines and tells them exactly when to enter and exit. While systematic traders have control over most aspects of the strategy, it determines the entry and exit signals entirely for them. You could think of a simple systematic strategy in two simple steps:

  1. When A and B happen at the same time, enter a trade. 

  2. 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 you have very specific rules in your system for when to enter or exit positions. A strategy that isn’t well-defined will lead to inconsistent results. As you might expect, this trading style is more popular in algorithmic trading.

There is backtesting software you can buy if you want to automate the process — you simply have to input your own data and the software will do the backtesting for you. In this example, however, we’ll go with a manual backtesting strategy. It involves a little bit more work but it’s completely free.

How to Backtest a Trading Strategy?

You can find a Google Sheets spreadsheet template using this link. This is a rudimentary template you can use as a starting point to creating your own. It gives you a general idea of what information a backtesting sheet may contain. Some traders prefer to use Excel or code it in Python; there aren’t strict rules. You can add as much data as you need to it, alongside anything other information you may deem useful.

Date

Market

Side

Entry

Stop Loss

Take Profit

Risk

Reward

PnL

12/08

BTCUSD

Long

$18,000

$16,200

$21,600

10%

20%

3600

12/09

BTCUSD

Short

$19,000

$20,900

$13,300

10%

30%

-1900


Let’s backtest a simple trading strategy:

  • We buy one Bitcoin at the first daily close after a golden cross. We consider a golden cross to be 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 to be when the 200-day moving average crosses below the 50-day moving average.

As you can see, we’ve also defined the time frame in which the strategy is valid. This means if a golden cross happens on the four-hour chart, we won’t consider it a trading signal.

The time period in this example begins at the start of 2019. However, if you’d like to get more accurate and reliable results, you could go back much further in the history of Bitcoin’s price action.

Now, let’s see what trading signals this system produces for the stipulated time period:

  • Buy @ ~$5,400

  • Sell @ ~$9,200

  • Buy @ ~$9,600

  • Sell @ ~$6,700

  • Buy @ ~$9,000

Here’s how our signals look when overlaid on the chart:

Golden cross-death cross strategy. Source: TradingView

Our first trade turned a profit of about $3,800, while our second trade resulted in a loss of about $2,900. This means our realized PnL is currently $900. 

We’re also in an active trade, which, as of December 2020, had about $9,000 in 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 resulted in a reasonable return but it doesn’t show anything 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.

Even though this is a systematic strategy, it’s also worth considering the context. The unprofitable trade from $9,600 to $6,700 occurred at the time of the March 2020 COVID-19 crash. Such a black swan event can have an outsized influence on any trading system. This is another reason why it’s worth going back further to see if this loss is an outlier or just a by-product of the strategy.

This is one example of a simple backtesting process. This strategy might have promise if we go back and test it with more data or include other technical indicators to potentially strengthen the signals it produces.

But what else can backtesting results show you?

  • Volatility measures: Your maximum upside and drawdown.

  • Exposure: The amount of capital you need to allocate from your entire portfolio to carry out the strategy.

  • Annualized return: The strategy’s percentage return over the course of a year.

  • Win-loss ratio: How many of the trades in the system are likely to result in a win and how many in a loss.

  • Average fill price: The average price of your filled entries and exits when using the strategy.

Do bear in mind that these aforementioned examples do not constitute an exhaustive list. Which metrics you’d like to track are completely up to you. In any case, the more details you include in your trading journal about relevant set-ups, the more opportunities you’ll have to learn from the results. Some traders are very rigorous in their backtesting, which will likely be reflected in their results.

One last thing to consider is optimization. If you’ve read our backtesting article, you’ll know the difference between backtesting and forward-testing (or paper trading). 

Closing Thoughts

We’ve gone through the basic process of how to perform a manual backtest of a trading strategy. However, it’s important to remember that past performance doesn’t guarantee future performance.

Market environments change, and you must adapt to those changes if you want to improve your trading strategy. You should also be careful not to blindly trust the data. Common sense is a useful — albeit often overlooked — tool when it comes to evaluating results.

Further Reading

پوسٹس شیئر کریں
ایک اکاؤنٹ کو رجسٹر کریں
آج ہی ایک Binance اکاؤنٹ کھولتے ہوئے اپنی معلومات عمل میں لائیں