Moving averages are often used to gauge trends and momentum, and in some cases, to trigger order entry/exit. The simplest of moving average triggers is to buy or sell a stock when the price crosses above or below the average. If the price crosses above, this typically means the stock is trending upwards, for example, and so you should buy it.
What time period to use?
Simple moving averages are calculated over a period of time, so how do you know what period of time to use? Are there certain stocks that are better suited for using a simple moving average vs price crossover strategy than others? Does this strategy even work? We can do some back-testing and analysis using this trading framework to dig a bit deeper.
Sample output from the framework:
Using SPY, we can look at how different periods of moving averages perform over time. Starting with $10k, and unrealistically assuming no transaction fees, the following chart plots what our return looks like using 10, 20, 50, 100, and 200-day moving averages (using adjusted close prices from Yahoo), from 1/1/2005 to 3/13/2013. All cash moves into SPY when opening a position. (Note: periods when the strategy holds a position show up as a flat line – the position is not marked to market as the price moves, though all holdings on 3/13/2013 are marked to market.)
Observe a few things: generally, these MA-based strategies consistently under-perform a Buy+Hold strategy throughout the entire 2005-2013 window; the longer MA-strategies tend to out-perform the shorter MA-strategies; the 100-day strategy does just edge out BH.
When to start the analysis?
That drop in 2008 sucks – what if we had started the strategy in 2009? This next chart looks at how performance changes when varying the start date, along with varying the moving average period. If you started in 2008, and used a long enough moving average, the strategy would have perfectly timed when to start buying following the market crash, so there’s a huge performance increase there over BH. $10k of SPY picked up 1/1/2008, if held until 3/13/2013 would be worth $11,709; using the 100-day strategy (and no fees), that same $10k would have grown to $15,966. This is cool, but not terribly useful – a successful strategy shouldn’t require the technical analyst to find the starting time subjectively.
Checking Various Stocks
Maybe the problem is SPY is not a good security for this signal. Sure there are trends in the market, but maybe certain other stocks follow a friendlier pattern. Here’s the same analysis against each component stock of the DOW, starting the strategy from 2005.
The trend of longer period averages performing better than shorter still holds, but overall, this doesn’t look great. Here’s a different view of the data, grouping by period, just to help visually verify that there are more better longer periods than shorter.
What happened with GE? Looking more closely, it seems that the longer duration averages were able to keep the strategy from losing money pre-2009.
Well, we know what happened with GE following the credit crunch. So it seems like the moving average was able to pick up on this very steep price action.
AA was another out-performer on long-term MAs – and observe a similar scenario here: the strategy kicks us out from the big price declines:
This is useful information – we can use the MA as a comparison against price to capture very big price swings. A significant trend should obviously stand out against a long-duration moving average. Against the DOW sample set, this simple strategy doesn’t do much for profit generation, but it clearly helps for minimizing losses on some of the large drops over the past few years.
Trying a Contrarian Approach
What if we flipped the strategy around and tried buying when the price crossed to below the average, taking a contrarian approach rather than a trend-following one. With trend-following, buying when the price crosses above the average is like jumping on the bandwagon – the market’s already moved, and you may have already missed the boat. Buying when the price crosses below the average takes a ‘regression to the mean’ view, that the price will revert back to the average in time.
As you might expect, the shorter moving averages do better than the longer now – the 10-day average in fact shows a 200% return!
And for the DOW components:
The contrarian approach here looks more profitable across this sample set. How might this be justified? We could try to say that, on average, short term price volatility is just standard error and long term price action is due to legitimate fundamental news.
If we assume that in the short-term, prices move up half the time, and down half the time, then buying when the price moves down, most of the time, will allow us to find a short-term profit. This also means we’ll have a tremendous number of transactions using the contrarian approach, so transaction fees could have an impact on performance – this all seems to imply that, and perhaps obviously, a successful strategy should look at long and short term indicators to capture or at least monitor long-term trends and short-duration volatility.
If interested, you can also see the price-crossover trading algorithm in my trading github repo.