What Is Backtesting?
There are many different ways to invest in the stock market. Some people buy stocks when their prices fall, while others buy stocks when their prices begin to rise. But how can we determine which approach is better? One way is to go back through historical stock market data and test how an investment strategy would have performed. This process is called backtesting.
Backtesting is the process of using historical data to evaluate how well a particular investment strategy might have performed in the past. Instead of investing real money, investors simulate trades using historical stock prices and other market information. This allows them to examine whether a strategy would have made money, how much it might have lost, and how it behaved under different market conditions.
For example, imagine an investor who wants to develop a strategy based on a stock's average price over the previous 50 trading days. This average is calculated using the stock's prices over the last 50 days when the stock market was open. The investor wants to test a simple rule: buy the stock when its price rises above this average and sell it when its price falls below the average.
How could the investor determine whether this strategy actually works? One approach would be to examine historical stock prices. The investor could look at the past 10 years of prices in chronological order and simulate buying and selling shares whenever the predetermined conditions were met. For example, if a buying condition was satisfied at the end of a trading day, the simulation could assume that the shares were purchased on the following trading day.
By repeating this process, the investor could calculate how many trades would have occurred over those 10 years and how much money the strategy would have gained or lost. With computer software, thousands of simulated trades can be calculated quickly.
Suppose an investor started with $1,000 and ended up with $1,600 after 10 years. That would represent a 60% total return on the initial investment. However, what if simply buying the stock and holding it for the entire period would have increased the investment to $1,700? In that case, the backtested strategy would have made money, but it would have performed worse than simply holding the stock. Of course, these numbers are hypothetical and are used only to illustrate the concept.
This is why backtesting involves more than checking whether a strategy made a profit. It is also important to compare the results with other investment approaches. In particular, comparing a strategy with buying and holding a stock over the same period can help investors determine whether a more complicated approach was worthwhile.
Investors should also examine how much money the strategy could have lost along the way. Imagine two strategies that both earned a 50% total return over 10 years. However, suppose one strategy experienced a maximum decline of 10% in its value, while the other experienced a decline of 60%. Even though their final returns were identical, the risks investors would have faced were very different.
The largest percentage decline in an investment's value from a previous peak is called the maximum drawdown. When evaluating backtesting results, investors often examine not only total returns but also maximum drawdown, the number of trades, and when gains and losses occurred.
However, backtesting has several important limitations. One of the most important is that a simulation should reflect the costs and conditions investors would actually face when trading.
Buying and selling stocks may involve brokerage fees, and certain transactions may also be subject to taxes. Furthermore, investors cannot always buy or sell shares at exactly the prices they expect. This can be particularly important for stocks that do not trade frequently, since the actual execution price may differ from the expected price. If these costs and differences are ignored, a backtest may produce results that look better than what an investor could realistically achieve.
Using historical information correctly is equally important. Imagine an investor simulating a decision to buy a stock in 2020. The simulation should not assume that the investor already knew the company's financial results that would be announced in 2021. A real investor in 2020 would not have had access to that information. This type of mistake is known as look-ahead bias.
Another problem can occur when a backtest includes only companies that still exist today. Many companies that were publicly traded in the past have since been delisted because of financial difficulties, bankruptcy, or other reasons. If a backtest excludes these companies and analyzes only those that survived, historical investing may appear safer and more profitable than it actually was. This problem is called survivorship bias.
Another common problem is developing a strategy that fits historical results too closely. Imagine that an investor is dissatisfied with a strategy based on a 50-day average and decides to test 40-day, 30-day, and 20-day averages instead. By continually changing the rules and testing different conditions, the investor might eventually discover a combination that produced exceptionally high returns in the past.
However, there is no guarantee that the same combination will perform well in the future. It may simply have matched certain historical price movements by coincidence. This problem is called overfitting.
One way to reduce this risk is to divide historical data into two periods. The investor can use the first period to develop a strategy and the second period to evaluate whether the strategy still works. If the strategy performs well during a period that was not used to develop it, the results may provide somewhat stronger evidence of its effectiveness. Even so, they cannot guarantee future profits.
Most importantly, backtesting is a method for analyzing the past, not a way to predict the future with certainty. Stock markets change in response to economic conditions, interest rates, corporate earnings, investor behavior, and many other factors. An investment strategy that worked well in the past may become less effective or stop working altogether.
Does this mean backtesting is useless? Not at all. It can be a valuable tool because it allows investors to evaluate their ideas before risking real money. Rather than relying only on feelings or expectations, investors can use historical data to better understand the strengths and weaknesses of an investment strategy.
Ultimately, backtesting is not a process of proving that an investment strategy will succeed. It is a way to understand how that strategy would have performed under different conditions in the past. Although historical results cannot guarantee future performance, carefully studying the past can help investors make more informed investment decisions.
Sign in to save your learning progress.