Understanding Backtesting: A step-by-step guide

Backtesting is a boon for traders, allowing them to test the viability of their trading strategy without risking money. Do you want to learn more about it? Then read on!

In real life, it isn’t possible to backtest your decisions, or we could avoid making all the stupid mistakes we made. But when you are a trader, backtesting trading strategy is an option.

It allows you to quantify the risks and returns of your decisions, analyse the history and predict the future behaviour of your plan. Traders use backtesting software for this purpose. This article is a step-by-step guide on how to backtest a trading strategy, the best backtesting strategy, and its importance.

What is a Backtesting trading strategy?

In simple words, backtesting involves testing your trading strategy on past data.The purpose behind is to check if the strategy works on past data, it might as well work in the future. 

If backtesting produces positive results, it boosts the confidence of the trader. Similarly if the test yields are negative, the trader either rejects or improve the strategy.

Backtesting analysis uses historical data to predict the future. It promotes using tested and valid strategies over randomly selected ones. Backtesting boosts your efficiency as a trader and quantifies the risks and returns of your method. Since it doesn’t involve money, anybody can use backtesting, especially if you are a new trader. 

It allows you to check the success probabilities of your trading strategy in the actual market. But before you try backtesting, you should meet the prerequisites, which include having a trading strategy, understanding of risks and returns of the asset, and historical data.    

There are two ways to do backtesting – manually and using backtesting software. In the manual method traders manually analyse results of the test. A backtesting software automates the process, making it quick and accurate. 

Steps for backtesting trading strategy

Manual backtesting involves the following steps.

  • Backtesting can be performed of any quantifiable trading strategy. Traders build a trading strategy around market conditions, trading period, risk level, profit target, and general entry and exit points. Once you have an in-depth trading strategy with defined parameters, you can apply it to backtest. 

Testing an unclear trading strategy will give clouded results.

  • Traders preparing for backtesting must identify the asset and the respective market where they want to conduct the test, like the stock market for testing stock trading strategy or the forex market for testing currency pairs.
  • Since trading strategies are sensitive to the timeframe, one must select a timeframe that reflects the current market environment for the best test results. 
  • While backtesting, traders compare and analyse the results for success and failure. It is considered a success when the outcomes match expectations.
  • Similarly, if the test results in a failure, one can work on improving their strategies. 

Backtesting trading strategy using a software tool

Nowadays, using backtesting software has simplified and optimised the process. Most of these tools perform on user inputs and lets you tweak the system to adjust to your testing requirements. It involves the steps below. 

  • Select the market that represents the asset and the period. 
  • Set relevant parameters for the test, like initial capital, portfolio size, benchmark, profit level, stop-loss level, etc.
  • Run the backtest. 
  • You will get either success or failure. In case of failure, optimise your strategy. 

Key factors to consider 

There are a few factors to consider while backtesting to improve the accuracy of your test.

  • The first is to find a data set from a relevant time period and duration that accurately reflects various market conditions. This way one can assure that the test results are based on solid research.
  • The backtesting data should represent all stocks, including bankrupt or liquidated stocks for the most accurate results. Excluding such stocks will result in significantly high results and may impact the accuracy of the outcome.
  • The testing should include all trading costs. All these costs can add up during the testing period and affect actual profitability. 
  • Lastly, testing your strategy outside of the data set and forward testing further confirm the suitability of the strategy in a real-world scenario. Your backtesting, out-of-sample, and forward-testing results should conform for the best trading strategy.   

Difference between backtesting and paper trading 

Traders use backtesting and forward performance testing to check the relevancy of the trading strategy. Forward performance testing, or the paper trading method, uses a simulated trading environment that reflects a live market and data. Traders use paper to write down the steps of the trade, including entry and exit, as well as profit and loss. 

If the backtesting and forward performance testing produce the same results, it means you have a solid trading plan. 

Backtesting vs scenario testing 

Scenario testing will simulate various hypothetical data that reflect changes in the values of portfolio security and other key factors like changes in interest rates. 

Traders use scenario testing to evaluate changes in the portfolio’s value against unfavourable market conditions. Unlike backtesting which uses real data, scenario testing uses hypothetical data to examine worst-case scenarios.

Why is backtesting important?

Backtesting provides several critical statistical feedback about the strategy.

  • Net profit and loss or the net percentage of gain or loss
  • Percentage measure of maximum upside or downside of average gains or losses 
  • Exposure to the market as ratio of the capital invested 
  • Win-to-losses ratio 
  • Percentage of risk-adjusted returns 
  • Percentage of annualised returns 

Pitfalls of backtesting 

Backtesting can provide meaningful results when tested against an unbiased data, meaning the trader must build a strategy independent of test data. However, it is easier said than done because traders usually develop strategies based on historical data. Hence while backtesting, it is vital to test the strategy against different data sets to produce more accurate results.  

Traders must also avoid the mistake of data dredging.

Data dredging refers to testing multiple hypothetical strategies against the same data set. It can lead to false hypotheses when an invalid test strategy may also produce success by chance which will fail in real time. It can be a costly mistake if you are unaware.

One way to avoid data dredging is to test a plan against relevant in-sample data and then check it out with a different data set or out-of-sample data set. If both in-sample and out-of-sample tests produce the same results then the strategy is proven to be valid.

Final words 

Backtesting means testing the suitability and accuracy of a trading plan using historical data. It helps traders to quantify the risks and returns of the strategy before using it in the real market. Although it is an efficient method, traders should remember that past data doesn’t always reflect future performance. Using backtesting with the other testing methods is the best way to identify the right trading strategy.