That's a Big Idea
Categories
  • Personal (53)
    • Finance & Trading (6)
    • Music (5)
    • Parenting (12)
    • Projects (11)
    • Topical (18)
    • Travel (1)
  • Technology (11)
    • Application Development (8)
    • Product Management (1)
    • Recruiting (2)
Archives
  • July 2024 (1)
  • June 2024 (1)
  • August 2022 (1)
  • October 2017 (1)
  • September 2017 (10)
  • August 2017 (1)
  • June 2017 (1)
  • February 2017 (1)
  • November 2016 (1)
  • October 2016 (6)
  • April 2014 (1)
  • March 2014 (5)
  • March 2013 (2)
  • March 2012 (1)
  • February 2012 (1)
  • January 2012 (1)
  • December 2011 (2)
  • November 2011 (7)
  • October 2011 (10)
  • September 2011 (8)
That's a Big Idea
  • Notes on Technology
    • Application Development
    • Recruiting
    • Product Management
  • Stuff I Think About
    • Finance & Trading
    • Music
    • Parenting
    • Projects
    • Topical
    • Travel
  • About Me
    • Who am I?
    • Random Side Projects
  • Finance & Trading

Analysis of Moving Average Triggers

  • craig
  • March 17, 2013
graphs display on an ipad
Photo by Burak The Weekender on Pexels.com

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:

SPY - Trading Sample

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.)

SPY - MA Performance -2005-2013

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.

SPY - MA Performance - Comparison

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.

DOW - MA Performance

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.

DOW - MA Performance By Period

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.

GE - MA Performance
GE - Trading

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:

AA - Trading

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!

SPY - MA Performance - Contrarian

And for the DOW components:

DOW - MA Performance - Contrarian

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.

You May Also Like
stacks of coins
View Post

Tracking Personal Finances

close up photo of data in a monitor
View Post

Analysis of Technical Analysis

blur board game business challenge
View Post

Trading Games… Working the Limits

Read Next
  • Illustration of code being packed into a truck and shipped off to a server factory, featuring a neon color palette with purples and pinks and a matrix-like tech-themed background.
    Deploying a Dockerized Django Application to Production
    • July 2, 2024
  • How to Set up Django with Docker, PostgreSQL and React
    • June 5, 2024
  • resume checklist next to a computer
    How to Craft and Optimize an Awesome Tech Resume
    • August 20, 2022
  • Most Common First Baby Words
    • October 5, 2017
  • baby blocks
    12 Proven Ways to Improve Baby Name Recognition
    • September 28, 2017
I’m Everywhere!
I'm Everywhere! FacebookI'm Everywhere! TwitterI'm Everywhere! LinkedInI'm Everywhere! YouTubeI'm Everywhere! GithubI'm Everywhere! VimeoI'm Everywhere! Goodreads
Craig Perler's Blog
That's a Big Idea!

Input your search keywords and press Enter.