How Do You Backtest a Trading Strategy?

Data has become the backbone of trading ever since the financial market truly transferred itself into the digital realm in the early noughties.


Backtesting is a useful method for traders to assess the viability of their trading strategy or hypothesis in a simulated environment, without putting capital at risk. 


Since backtesting involves the use of historical data of the financial market, the trader or programmer must have at least a basic understanding of data, programming, and falsifiability in order to correctly test a strategy with the aid of backtesting.


Backtesting helps the trader in choosing the right strategy which can maximize their profits over time. 


If you are interested in learning more about backtesting, various methodologies, as well as its benefits and pitfalls, then read on. We’ll go over the basics in this article. 





What is Backtesting?

Backtesting can be defined as the process by which a trader tests a trading strategy by utilizing historical data from the financial market. The strategy developed by the trader can be tested in previous market conditions to determine whether or not it would have been successful. 


Backtesting involves the development of a trading strategy, often starting with a hypothesis which is tested for efficiency against historical data of the financial market. Many platforms come with such backtesting functionality.


It is important for the trader to utilize clean, high-quality data, as well as backtest with different data from time to time to avoid the problem of overfitting.





Types of Backtesting

Traders can take two main approaches for backtesting their strategy ideas, these are: 


  • Hypothesis Method



With the hyptosis method, the trader starts by formulating a strategy based on basic assumptions about market facts and tests the effectiveness of the strategy by utilizing the historical data of the financial market. 


For instance, the trader could start with “when price prints a higher high, it often leads to higher prices over time.” If the strategy is found to be effective historically, it could then be implemented in the current market. 


  • Data Mining



Data mining is the process of filtering through raw data with an algorithm (sometimes blessed with the title of Artificial Intelligence) in search of recurring patterns.. These patterns are then used to formulate a trading strategy which would be based on the historical data set. If it is proven to be effective, it could then be tested on datasets from other periods or even different but similar instruments to check it definitely works. If it does, it could then be tested in a live market environment.




Benefits of Backtesting

Backtesting is not only about finding a profitable strategy, but also a strategy that will work for you. Backtesting allows you to learn about the intricacies of your strategy in a simulated environment.


Backtesting can be beneficial for the trader in the following ways:


  • Know Your Strategy’s Numbers



Testing your strategy over a large array of data will show you vital information, such as win rate, max drawdown, and average return per trade. 


Obviously, the hope is that the strategy is profitable. But you will also learn certain characteristics about your strategy. For instance, it’s not just about how much money you make, but when and how. Trend following or momentum strategies that buy when prices are rising or sell when they are falling tend to have lower win rates but higher average returns per trade. That means there can be wild fluctuations in your overall PnL, and it is important to be able to stomach this and avoid ditching your strategy when it is in a drawdown but still perfectly valid.


Learning about your trading system will help you to better implement it and stay consistent and disciplined. 


  • Improve Your Strategy



Naturally, backtesting will also help you to improve your strategy, as you will be able to learn the strengths and weaknesses of your system.


Perhaps you will discover that all your trades on Wednesdays are negative PnL trades. If you look into it further, perhaps it isn’t just a random fluctuation but due to some scheduled news that is released on that day, and then you go on to discover that your strategy simply performs better when it avoids news days altogether. This kind of information can turn a good strategy into a great one.




The Pitfalls of Backtesting

Backtesting is a very useful tool, but doesn’t come without its downsides. If overlooked, backtesting can be misleading or even dangerous for your trading account. 


Therefore, it is necessary to keep a few of the most common pitfalls in mind when conducting backtests:


  • Overfitting & Optimisation Bias



Overfitting and optimization bias occurs when there are too many parameters by which the strategy reaches its results. If a strategy fits the data too precisely, such a strategy may prove successful when tested with that specific historical data set but fail completely in the future. Therefore, it is crucial to keep the strategy as simple as possible, as well as test on various different datasets or in a live market environment.



  • Look-Ahead Bias



Look-ahead Bias means that the data which is used in backtesting would not have been available at the time when it was analyzed. This could be because the company released quarterly earnings reports that were only available a month after the trade was taken. This can lead to overconfidence in a strategy that would be impossible to implement in the future.



  • Survivorship Bias



When testing a strategy based on current market conditions, it may lead to survivorship bias. This is especially true for stocks, since backtesting only for the current market will miss all the losing trades that would have been taken on stocks that are no longer listed, because they went bankrupt (or otherwise). Therefore, the results you get from the backtest may be widely different from what would have been.



  • Ignoring Costs



There are certain costs which are sometimes ignored (such as commissions) or impossible to accurately calculate (such as slippage) when backtesting. This can lead to gross miscalculations, in some cases showing a strategy to be profitable when in reality it would be a net loser. 



  • Historical Results Don’t Guarantee Future Results



The markets are constantly evolving, and what worked yesterday might not work tomorrow. It is important to be aware that the future always remains unknown, and assumptions made in backtests may need to be revisited as time goes on.




Wrapping Up

Backtesting requires decent knowledge of financial market microstructure, clean historical data, and knack for statistics and for testing hypothesises. There is no guarantee of result when it comes to financial markets, but backtesting can provide extra insights which can help in formulating a profitable strategy. If the trader can avoid some of the common pitfalls present in backtesting, then they will greatly increase their chances of uncovering a trading edge.

Bookmap comes with API functionality that allows for backtesting. Try it out today for free. Click here to get started.




Receive updates about new articles

Follow us on social media

Unable to load Tweets

Learn More About Bookmap