Related Articles
Start Backtesting

Backtesting a Moving Average Strategy on the S&P 500

December 31, 2021
Robson Chow
Tradewell logo

What is a Moving Average Strategy?

A moving average trading or investing strategy is a popular trend following tool that uses past price data to generate buy or sell signals on the underlying asset.  This strategy has been and is used by top hedge fund managers and traders around the world.  

The moving average itself is calculated by taking a rolling average of a particular security's closing prices over a given period of time, and then plotting that average as a line on a chart. A moving average that is sloping up indicates that the underlying asset is in an uptrend and buyers are more aggressive than sellers.  Similarly, if the moving average line is sloping down, it indicates that the underlying asset is in a downtrend and sellers are more aggressive than buyers.  An asset that is “trendless” over a given period of time will have a flat moving average – that is there is no significant buying or selling pressure to create a trend.

While moving averages are useful indicators, they have limitations. First, they are lagging indicators, which means that they only provide information about what has already happened, not what is going to happen. As such, moving averages are notorious for generating false signals (whipsaws), especially in choppy markets. 

Moving averages in and of themselves are not necessarily predictive of future market behavior but that does not mean they are not useful. Steve Deppe, the Chief Investment Officer at Nerad Deppe Wealth Management sums up the best way to use technical analysis in this Tweet:

Technical analysis is best used as a tool to plan & predict your own behavior, what/when/how you enter & exit a position, from those on minute charts to those on monthly charts. It's not going to tell you where $SPX is going, there is no magic.

Moving averages are just one tool in the Technical Analysis toolbox - but when used correctly, they can be helpful in identifying trends, generating trading signals and predicting your own behavior.  

Below we are going to explore a popular, and simple moving average strategy on the S&P 500 etf SPY, the 12 month moving average.

Building a Moving Average Strategy for the S&P 500

In the above section we described how a moving average might be used to make trading or investment decisions.  In the following sections we will test the hypothesis: Does buying when the S&P 500 ETF SPY monthly price closes above the 12 month simple moving average outperform a buy and hold strategy.  The answer of course is - it depends, but let's dive in.  

First start by obtaining monthly price data for the S&P 500.  For the purpose of this post, we will use Adjusted Close data from Tiingo.  Then calculate the 12-month moving average for the S&P 500 SPY ETF by adding together the last 12 months of data points and dividing by 12.  For the month ending September 30, 2022, the 12 month moving average is $421.92, and the current price is below the moving average sitting at $370.53

Next, use the 12-month moving average as a reference point to generate buy and sell signals. The rules are as follows: 

  1. Buy the SPY ETF when the S&P 500 closes the month above its 12-month moving average.
  2. Sell the SPY ETF when the S&P 500 closes the month below its 12-month moving average.

The chart below shows monthly candlesticks of the SPY ETF since inception.  The redline line is the 12 month simple moving average and the red rectangles highlight periods when the strategy is uninvested - that is the monthly price closes below its 12 month simple moving average.  Immediately, we can see that this strategy avoids the majority of the declines during the most tumultuous periods of the past 30 years – the 2000-2002 technology stock bubble unwind and the 2008/2009 Great Financial Crisis.

Backtesting the Trading Strategy

The chart in the previous section showed us that this trading strategy avoided the deepest drawdowns in the S&P500 simply by not being invested when price was below it’s 12 month simple moving average.  Despite this there are a significant number of other times where price momentarily dipped below the 12-month moving average only to close above the following month.  As such, it is difficult to tell from looking at the image alone whether this strategy outperformed the S&P 500 buy and hold. Quantifying the results via a backtest will help us validate or invalidate our hypothesis.

To do this, we assign a starting cash balance of $10,000 to our simulated trading strategy.  In order to compare the performance of the strategy to simply buying and holding, we plot both equity curves on the same chart.  Where we stand now, and assuming trading started at the inception of the SPY ETF in 1990, the 12 month moving average strategy would be very slightly outperforming buy and hold - the black line is above the green line, and the strategy is currently uninvested.  The current equity value of the 12 month moving average strategy is $14.4k and the current equity value of the buy and hold strategy is $13.2k

Assessing the Backtest Performance

When assessing the moving average strategy, it is important to consider the following:

  1. What did drawdowns look like when compared to the benchmark and when did outperformance or underperformance occur?
  2. Is the performance observed in the past likely to continue into the future?

With regards to the drawdowns, the strategy is designed with the intent of reducing risk when it is highest.  As such, as we can see in both initial charts large drawdowns are prevented in 2000-2002 and 2008-2009. We can also see this on the drawdowns chart.  

While the 12 month simple moving average strategy had drawdowns of under 5% in 2000-2002 and 2008-2009, the buy and hold strategy had drawdowns of up to 50%.  In this sense the 12 month simple moving average strategy.  During the period from 2010-2020, drawdowns were not all that different and some were greater than normal given whipsaws.  There were no major financial crises and as such the broader indices did not experience large drawdowns to which the 12 month simple moving average would have protected the investors capital.  So far in 2022 the strategy has capped drawdowns to approximately 12% while buy and hold has seen a drawdown of over 20%.

Visualized slightly differently we can look at strategy returns on a monthly basis by year.  This helps an investor determine whether or not outsized returns or conversely the reduction of risk is attributable to specific months.  The monthly returns chart shows that the strategy (via 0 returns) was uninvested for nearly 2 and a half years during the period from 2000-2003 and a year and a half during the great financial crisis from 2008-2009.

Caveats to Keep in Mind When Assessing The Backtest Results

When assessing the results of a moving average strategy, there are a few things to keep in mind. 

  1. The market is a dynamic system that is constantly evolving and as such, past performance is no guarantee of future results.  
  2. Second, the results may be sensitive to the starting date and ending date of the backtest period.  The backtest started with the inception of the SPY ETF in the early 1990s, however it tells us nothing about how the strategy would have performed on the S&P500 prior to the inception of the SPY etf.  This method of choosing multiple sample periods is a type of analysis called in-sample Vs. out of sample. 
  3. Various fees and costs are not included in the backtest results, for example tax implications of buying and selling the SPY etf multiple times compared to simply holding the investment.  Likewise, slippage (getting an adverse entry as compared to your expectations) and commissions are not accounted for in backtest results. All of these factors should be considered when assessing the potential profitability of a moving average strategy as well as the suitability for your personal risk tolerance and financial goals.


This post tested the hypothesis that the 12 month simple moving average strategy outperforms a simple buy and hold strategy on the S&P 500 SPY ETF.  Based on the results we conclude that the hypothesis is indeed true driven by outright outperformance on an ending equity value basis but more importantly by limiting the risk-exposure an investor faces during the most tumultuous of market conditions.  During strong market conditions and including trendless periods, we noted that strategy could be whipsawed leading to short-term underperformance versus buy-and hold. We noted that it is important to consider whether or not the strategy outperformance was simply due to the chosen sample period of analysis (luck) and that there was no consideration of fees or investment costs.  In a future post we will examine whether or not the 12 month simple moving average strategy outperformance is replicable across different asset classes versus a simple buy and hold strategy.

Read This Next
Vivek Chauhan, Oscar Levy, Deepak Singh
Backtesting Signals Derived from VIX Backwardation, Market Breadth and Market Spreads
Backtesting the performance of the S&P 500 after the appearance of signals derived from VIX backwardation, market breadth and market spreads.
Read Article
Robson Chow
Backtesting a Moving Average Strategy on the S&P 500
A moving average trading or investing strategy is a popular trend following tool that uses past price data to generate buy or sell signals on the underlying asset. This strategy has been and is used by top hedge fund managers and traders around the world.
Read Article
Robson Chow
Backtest Study: So You Want to Short the S&P 500?
This study uses the tools of backtesting and data visualization to examine the challenge posed by selling the SPDR S&P 500 ETF Trust.
Read Article
Humza Sarwar
What is a Backtest?
Backtesting is a method used in trading and investment research to assess the quality of strategy by simulating its performance against historical data. Learn more about the basics of backtesting by reading this article.
Read Article
Albert Huang
How to Backtest Your Trading Strategy: A Comprehensive Guide
Backtesting plays a key role in developing a successful trading system. Read this article to discover the steps a trader must take to backtest a strategy.
Read Article
Albert Huang
VIX Trading Strategies to Backtest
This article will explain what the VIX Index is, what instruments a retail trader can trade to profit from changes in equity market volatility, and also reveals three VIX-related signals worth monitoring. 
Read Article
Humza Sarwar
What is Trading Analytics and How Can Traders Benefit?
This article will help you understand the basics of trading analytics and how they can improve your trading performance.We'll also walk you through some of the most popular analytics options today so that you can find a solution that meets your needs.
Read Article
Get started with Tradewell for free

Start with the free version and upgrade when you need a larger metric library and longer lookback periods.

TradeBlock logo
FRED logo
CBOE logo
IEX logo
EIA logo
CME Group logo
Tradewell logo
© 2021 Tradewell, Inc. All rights reserved.
Start Backtesting