Backtesting stocks is a method of simulating an investment strategy without risking any money. You’re only performing paper trades without risking any capital. Historical data is the only way to backtest stocks and trading strategies.
Investment professionals that use backtesting and simulations that rely on adjusting strategies and variables based on historical data could increase their confidence when it comes to live trading.
In this article, we explain backtesting stocks, why investors, brokers, and analysts use this approach, the pros and cons, and the best practices for backtesting.
What Is Stock Backtesting?
Any investment strategy carries an element of risk. Traders, investors, and analysts working for brokers want to know an investment strategy has the potential to work in theory before putting it into practice. Otherwise, you increase the risk of losing your money, client funds, or both. Hence the value of backtesting stocks, instead of diving into a live investment strategy without validating your approach.
Everyone knows that what goes up must, at some point, come down, and the usual investment disclaimer is that past performance doesn’t guarantee future profits.
However, smart investors look for ways to minimize risk and maximize gains. Backtesting stocks and trading strategies is one approach to reducing downside risks. In theory, if a strategy can be quantified and tested on historical data and — crucially — works, then it should give you more confidence to put it into practice.
The idea is that a backtesting strategy that performed well in the past should perform well in the future. In most cases, the ultimate measure of success is, “Did my trading strategy yield a profit from financial markets?” If yes, then it could be viable for live trading. If not, then it’s time to rethink and tweak your trading system.
Although, it helps to backtest using a timescale when market conditions were comparable to the present to make it realistic. This means finding a time period with similar levels of volatility, whether bull or bear, depending on the different markets you want to invest in.
If your tests prove successful, then you can test your theories further with different time periods, timeframes, datasets, and out-of-sample data.
Backtesting doesn’t only apply to stocks and shares. Investors and analysts can use this for anything from derivatives, commodities, currencies, forex trading, crypto (although historical data is more limited as Bitcoin only launched in 2008), exchange-traded funds (ETFs), futures markets, and numerous other asset classes.
Why Do Investors Use Backtesting Stock Strategies?
Investors deal in numbers and data — hence the value of understanding technical indicators. Almost everything can be quantified except for useful elements of qualitative data when investors are applying fundamental analysis methodologies.
Trading strategies can be quantified too, provided you’ve got one that can be coded into a trading platform (e.g., using a programming language such as Python), an online simulator, or defined using backtesting tools and software settings and parameters.
That’s what backtesting stocks is all about: testing a quantifiable investment strategy or theory using historical market and price movement data over a fixed time period. As no investment strategy is risk-free, this acts as a smart approach to risk management. Once you’ve evaluated trading ideas with historical data, you can implement forward testing before putting your theory into practice.
Backtesting is used to safeguard investor funds before implementing actual trades that risk real capital. Investors that spend time drawing up trading strategies for a backtesting scenario can then implement the same strategy during live trading, perhaps manually on a small scale at first before investing more and perhaps using algorithmic trades to execute the strategy faster, provided it yields a profit.
Investors or analysts backtesting any strategy need to be clear on the stocks, commodities, or other investment vehicles they include in any test.
A backtesting strategy could be as simple as using candlestick charts, Bollinger bands, or a simple moving averages crossover over a fixed timescale to compare a basket of stocks in a particular sector. Or it could be more complicated, such as using algorithmic trading to plot a seven-figure investment strategy spread across hundreds of funds, stock markets, and ETFs.
Pros and Cons of Backtesting Trading Strategies
Here are the pros and cons of backtesting stocks that every trader and investor needs to think about before going ahead with a simulated approach.
Advantages of Backtesting Stocks
- Saves time and money: Backtesting is a time- and money-saving strategy that lets you quickly test dozens, even hundreds of theories and trading strategies, until you find one or more that works successfully.
- Protects your investments: Backtesting means that you can better understand underperforming market conditions by implementing automated filters and triggers to avoid sailing into stormy waters in the future.
- Has realistic simulations: Backtesting software is an effective way to apply technical analysis in as close to real-world conditions as possible without the risk of losing money if something goes wrong, e.g., market conditions move against your positions.
- Helps with risk management: With this approach you can manage risk more easily while avoiding drawdowns and eliminating buy, sell, and hold indicators and asset classes that don’t contribute to the ROI you’re aiming for. Backtesting isn’t a magic formula for beating the market, but it may help to reduce risk and generate higher returns when applied the right way and when you factor in the disadvantages too.
Disadvantages of Backtesting Stocks
- It’s just theoretical: Remember that backtesting is a way to test theories using historical market data. Even if your strategy performs fantastically, real-time market conditions in the present are almost always going to be different in some way (even if only slightly) from the theory when tested over a timescale that’s unchanging.
- Experience bias can get in the way: Experience bias can influence investors when backtesting, even if an investor is trying a new approach. If something has worked in the past, why won’t it work again? It’s human nature. It’s worth trying something new to get a more accurate and honest evaluation of your trading strategies before diving into the live market.
- Actual investing costs more: Make sure to factor in trading costs, slippage, and micro-price movements when trying to calculate profits. Algorithm trading could help keep these factors to a minimum, but that will involve more detailed and accurate testing.
- There is a risk of overconfidence and overfitting: Overfitting is almost as bad, and similar to, overconfidence. Algorithmic models are the outputs from equations. They can’t panic and buy or sell too early. But investors can, if they optimize a model too well — a process known as overfitting. Once you start live trading, you risk being overconfident in a strategy that generated impressive results in backtesting simulations because it was over-optimized and doesn’t reflect the real-world investment environment.
How to Implement Stock Backtesting: Software Tools and Best Practices
Backtesting only works well when an investment strategy (or multiple strategies that you’re testing) is well-considered, quantitative, and data-driven, rather than based on gut instinct. If you can’t quantify it, then it’s harder to test and evaluate.
It’s equally important that the data you’re using to test theories is truly representative of accurate market conditions. Businesses collapse or are liquidated, stocks are split, and other companies that were public go private. Make sure the sample dataset includes and takes into account these stocks. Otherwise, you’ll see results that are artificially higher than they should be, producing a false positive.
Integral to sample periods being representative is to avoid being too bullish or bearish. Backtesting stocks during the 2010 to 2020 period isn’t going to represent current market conditions accurately. Aim to take the present into consideration when picking sample time periods, as once you start forward testing and live trading, these are the conditions you’re operating in.
And, of course, you then need to choose backtesting stock and trading simulation software (and the right data sources) to run the variables and validate your theories.
When picking a backtesting software tool, you need one that gives you enough control and covers the right range of timescales and markets:
- Markets: It’s essential to choose a tool that covers all of the markets and stocks you want to analyze or allows you to customize the data sources using a range of stock price data APIs —e.g., an end-of-day stock price data API, a real-time IEX API, a forex API — and other options that fit your investment strategy.
- Timescales: How far back do you want to go: five, 10, 20 years? It depends on how much data you want to analyze and when there were market conditions that were reflective of today’s conditions.
- Control: You need a trading, backtesting, or simulation tool that lets you create sophisticated strategies with full control over filters, such as when to enter or exit trades. Some software platforms are more limited, and that will restrict your ability to build and test a realistic strategy accurately and then robustly validate that.
With the above in mind, there are dozens of backtesting and simulation software products on the market. Some are free and require coding skills, such as QuantConnect, and others are more expensive, easier to customize, and don’t need coding, such as Trade Ideas.
It’s worth reading reviews and asking around to get a clearer idea of the tools and platforms other traders and investors use. You might already be using a trading or analytics product that includes backtesting features. But if those features aren’t enough, then you’re going to want a dedicated backtesting and simulation software suite.
Build Future Investment Strategies With Good Data and Stock Backtesting
The bottom line with stock backtesting is it’s a smart way to test whether trading strategies, theories, and ideas hold any weight. But results shouldn’t be trusted 100%, even when the outcome is either really positive or negative.
Real-world variables are going to be different from the results of testing models on historical data, even when market conditions are as close as possible to how they currently are or any predictions for the future.
However, even with downsides and limitations factored in, backtesting ⏤ when implemented well with a sensible quantifiable strategy (not relying on gut instinct) ⏤ can be a useful way to validate and assess new approaches to investing or day trading.
Searching for the best source of high-quality, clean, and cost-effective stock market trading and historical data for backtesting trading strategies? Look no further than Tiingo’s Stock APIs.