Skip to Content

Backtesting Trading Strategies: A Complete Guide

“The Oracle of Omaha”—that’s how many know Warren Buffett, the legendary chair and CEO of Berkshire Hathaway Inc., who, as of October 2023, was worth nearly $114 billion. However, Buffett’s investment prowess doesn’t stem from psychic powers; it comes from his ability to recognize a good deal.

Although the average retail trader may not be able to access the same resources as Buffett, anyone can learn how to evaluate trades and read market signals. Backtesting trading strategies is one popular method that elevates your trading skills and teaches you how to spot value like a pro.

By backtesting, you can test trading strategies using historical pricing data. In other words, a backtested portfolio can reveal incredible insights, allowing you to apply techniques that worked in the past to strengthen your approach for the future.

What is backtesting?

Portfolio backtesting involves evaluating an investment strategy by looking at how it would have performed in historical market conditions. Reconstructing past performance enables traders to simulate trading strategies in a controlled environment using historical data. With proper backtesting, you can:

  • Identify relationships between assets and economic factors

  • Analyze potential profitability

  • Compare strategies to find what works

Quantitative trading strategies conduct extensive backtests to optimize algorithmic models before executing trades in the real world. With backtesting, you can quickly assess the risk and return for a portfolio that combines several asset classes. You can also backtest to evaluate dynamic strategies weighted by volatility or strategies that switch between two assets like stocks and forex. 

Some traders use backtesting to practice reading technical indicators.

For example, you can backtest a simple moving average (SMA) crossover strategy using historical end-of-day (EOD) data, a short moving average, and a long moving average. SMAs smooth price history, allowing you to clearly see downward, upward, or horizontal trends. From there, you can alter the SMA lengths to see which averages performed best and apply this knowledge to future strategies. 

Backtesting isn’t a crystal ball; it cannot reveal the future. Instead, think of backtesting as game tape. By reviewing it, you can analyze how well your strategy performed, which allows you to tailor your game plan for future scenarios.

Backtesting software allows investors to evaluate hypothetical performance before they invest.

Composer's backtester in action

So what’s the catch? 

Backtesting functions like time travel, but this introduces numerous biases and issues that investors must combat. If you already know how the story ends, you can make decisions based on what you know. This is called look-ahead bias.

Suppose you want to test how your portfolio would perform if you overweighted growth stocks. In this situation, you could use Vanguard’s Growth ETF (VUG) and compare its performance to the S&P 500 (SPY) and Vanguard’s Value ETF (VTV).

From 2005 onward, weighting toward growth appears like an excellent strategy. Growth (VUG) returned almost 2% more per annum than SPY and over 3% more per annum than VTV during this period. 

A comparison of growth and value investing strategies relative to the S&P500.

Data from January 1, 2005 to February 22, 2022

But wait. You know growth outperformed over this period—the data is in the historical record. You want to know whether growth will continue to beat the competition. More specifically, you want to know whether the factors that led to growth’s outperformance over the period will continue.

This brings us to another problem with backtesting: data snooping. Data snooping involves testing multiple strategies and picking the best one. Investors get hooked on tweaking and optimizing backtests for their portfolios, which leads to overfitting. 

Overfitting occurs when you align your strategic model too closely with a limited data set. By picking the optimal strategy, you limit your analysis to only the data points that fit your model.

This can lead to flawed results, as the strategy only performs well using the sample data. Test your model against benchmarks and samples outside your backtest dataset to avoid overfitting your strategy.

How to do better backtesting

Unfortunately, you can’t invest in a backtest. Backtesting can only provide data and insight to inform the risks you take.

The challenge in backtesting lies in finding the truth buried within the data and applying that insight to take better risks. Better backtesting yields better data, which leads to better decision-making.

Here’s what that looks like in application:

1. Define your strategy

Before building a strategy, you must understand why you chose it and why you think it will work. Asking these questions forces you to start portfolio construction from first principles and build from the ground up. 

For example, to reduce portfolio volatility, you should determine how much volatility you’re willing to accept. You can then construct a strategy that shifts from relatively risky assets (e.g., U.S. stocks) to less risky ones (e.g., U.S. treasuries) like this Risk On Risk Off trade.

The trigger for the trade should match the “why.” In this example, bond market outperformance over the past quarter triggers a shift from Risk On to Risk Off.

A risk-on-risk-off investment strategy using Composer's automated trading software.

Paired Switching S&P 500 and Bonds represents a Risk On Risk Off trade

Next, assess why you think this strategy will work. Using the Risk On Risk Off scenario, you can expect the symphony to reduce volatility and drawdowns because it shifts to U.S. treasuries, an asset with lower historical and expected standard deviation.

However, if you believe the symphony will outperform buy-and-hold portfolios simply because “it performed better in the past,” you may want to re-evaluate your thesis. 

Starting with “why” will help you fight look-ahead bias. If you start with a forward-looking view toward your goal, you’ll be less likely to game the backtest. And if you can explain why you expect the symphony to perform going forward, you’ll have a clear investment thesis to test. 

2. Choose your timeframe(s) 

Remember to choose a relevant period when designing your backtest. Some experts recommend using the longest period possible, as it exposes your strategy to more market environments (e.g., high rates, low rates, recession, expansion). Here’s the Paired Switching symphony from above over the longest period for which we have data:

Risk-on-risk-off investment strategy backtested from October 22, 2002 to February 22, 2022

Data from October 22, 2002 to February 22, 2022

You should test your strategy using different periods. Pick random periods or roll through backtests starting with the earliest period and move forward by set intervals. Evaluating performance across all these periods will give you insight into how the symphony may perform under various market conditions.

Here’s the same symphony from above, looking at only its first five years of data:

Risk-on-risk-off investment strategy backtested from October 22, 2002 to October 22, 2007

Data from October 22, 2002 to October 22, 2007

From October 22, 2002, through October 22, 2007, the symphony lagged the S&P 500 (represented by SPY), but importantly, it delivered reduced volatility and max drawdown. 

3. Use the right tools 

From Interactive Brokers and MT4 (MetaTrader 4) to TradingView and Tradestation, nearly all automated trading platforms offer backtesting capabilities in some form. When evaluating a trading platform, ensure it has the features you want to use in your backtests. 

Backtesting provides valuable statistics about quant trading strategies. Before you begin, familiarize yourself with popular technical analysis backtesting metrics, such as the Sharpe ratio, maximum drawdown, and Sortino ratio. Test your symphony using various inputs to separate genuine insights from statistical noise.

For example, you could test your Risk On Risk Off strategy using 7%, 10%, and 15% drawdowns to check if you get consistent results. 

Good backtesting strategies should balance responsiveness with trading costs. More frequent rebalancing responds more quickly to changing market conditions but also incurs more significant transaction costs and, possibly, capital gains taxes. Through backtesting, you can evaluate how often a strategy would have traded in the past to help inform your decision regarding rebalancing frequency. 

Benefits of backtesting

Backtesting provides numerous benefits, including:

Impartial strategy evaluation

Backtesting offers an unbiased lens through which to evaluate your trading strategies. Gathering data points and running tests reduces the need for speculation and removes emotions from the decision-making process.

Risk management

Backtesting helps  identify potential risks, enabling more effective risk management. Analyzing volatility, drawdowns, and market disruptions provides information you can use to determine losses. You can then use this information to establish appropriate position sizes, stop loss orders, and other risk-mitigation practices. 

Increased potential returns

Understanding how to research, analyze, and translate backtesting results into actionable strategies helps you make more well-informed investing decisions. Applying knowledge gained from backtesting can yield positive net results with patience and discipline.

Analyze your portfolio with Composer's backtesting tool

As an investor, you have more data and computing power at your disposal than ever before. Composer helps you backtest strategies to develop dynamic investment schemes.

Follow our straightforward rules, and you can harness backtesting to build symphonies designed to take on the future. Sign up with Composer and begin portfolio backtesting today.

Important Disclosures

Investing in securities involves risks, including the risk of loss, including principal. Composer Securities LLC., is registered with the SEC and member of FINRA / SIPC. This message has not been approved by FINRA or the SEC.

Certain information contained in here has been obtained from third-party sources. While taken from sources believed to be reliable, Composer Securities has not independently verified such information and makes no representations about the accuracy of the information or its appropriateness for a given situation. In addition, this content may include third-party advertisements; Composer Securities has not reviewed such advertisements and does not endorse any advertising content contained therein.

This content is provided for informational purposes only, as it was prepared without regard to any specific objectives, or financial circumstances, and should not be relied upon as legal, business, investment, or tax advice. You should consult your own advisers as to those matters. References to any securities or digital assets are for illustrative purposes only and do not constitute an investment recommendation or offer to provide investment advisory services. Furthermore, this content is not intended as a recommendation to purchase or sell any security and performance of certain hypothetical scenarios described herein is not necessarily indicative of actual results. There can be no assurance that the investments made using Composer Technologies’ online trading platform will be profitable.

Charts and graphs provided within are for informational purposes solely and should not be relied upon when making any investment decision. Past performance is not indicative of future results. The content speaks only as of the date indicated. Any projections, estimates, forecasts, targets, prospects, and/or opinions expressed in these materials are subject to change without notice and may differ or be contrary to opinions expressed by others. Please see Composer's Legal Page for additional important information.