How to Backtest a Trading Strategy

[ad_1]

TL;DR

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.

Before we go any further, if you’d like to backtest your own strategies, Binance Futures is a great place to do it. If you’d like to get access to historical data from the platform, please fill out this application form.
First, if you’d like to get a deeper dive into what backtesting is, read our article 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.

Before we start with the backtesting example, there is something you should determine. You’ll need to 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 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.

You can find a Google Sheets spreadsheet template on this link. This is a rudimentary template that you can use as a starting point to create your own. It gives you a general idea of what information a backtesting sheet may contain. Some traders will prefer to use Excel or code it in Python – there aren’t strict rules here. You can add much more data and anything else you may deem useful to it.
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

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. 

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.

Even though this is a systematic strategy, it’s also worth considering the context. The unprofitable trade from $9600 to $6700 was 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 byproduct of the strategy.
In any case, this is how a simple backtesting process may look like. This strategy might have promise if we go back and test it with more data or include other technical indicators to potentially make the signals it produces stronger.

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.
These are just a few examples and not an exhaustive list by any means. What metrics you’d like to track is completely up to you. In any case, the more details you journal about the setups, the more opportunities you’ll have to learn from the results. Some traders are very rigorous in their backtesting, and it may also reflect 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. It can be helpful to test and optimize your ideas in a real-time trading environment, such as the Binance Futures testnet.

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. 

Do you still have questions about backtesting and crypto? Check out our Q&A platform, Ask Academy, where the Binance community will answer your questions.

[ad_2]

Source link