200 Day Moving Average
One of the indicators of the health of a stock or index is the relationship between its most recent price and the 200 day moving average of that price.
There are many ways to interpret an indicator, and many ways to use it to signal entries and exits from trades. This posting analyzes the results of entering long and short positions as the close crosses above and below its 200 day simple moving average – a trend following system.
Compare a mean reversion system using the same data.
Daily data for SPY for a period of about twelve years are used. The beginning and ending dates are chosen intentionally so that the period has very little net price change. SPY closed at 126.31 on 1/28/1999, and closed at 126.66 on 10/31/2011.
While there was little net price change over that period, there were five large moves within it.
Rise from 126 to 155 in March, 2000.
Drop from 155 to 77 in October 2002.
Rise from 77 to 156 in October 2007.
Drop from 156 to 67 in March 2009.
Rise from 67 to 126 in October 2011.
The AmiBroker code that was used follows.
// 200DayMovingAverage.afl // // Buy, Sell, Short, Cover when the close // crosses its own 200 day simple moving average // // Howard Bandy // November 2011 SetOption( "InitialEquity", 100000 ); //SetPositionSize(10000,spsValue); SetPositionSize( 100, spsPercentOfEquity ); Delay = 0; SetTradeDelays( Delay, Delay, Delay, Delay ); BuyPrice = Close; SellPrice = Close; ShortPrice = Close; CoverPrice = Close; LongTermAverage = MA( C, 200 ); Buy = Cross( C, LongTermAverage ); Sell = Cross( LongTermAverage, C ); Short = Sell; Cover = Buy; Plot( C, "C", colorBlack, styleCandle ); Plot( LongTermAverage, "200DayMA", colorBlue, styleLine ); shapes = IIf( Buy, shapeUpArrow, IIf( Sell, shapeDownArrow, shapeNone ) ); shapecolors = IIf( Buy, colorGreen, IIf( Sell, colorRed, colorWhite ) ); PlotShapes( shapes, shapecolors ); e = Equity(); Plot( e, "equity", colorGreen, styleLine | styleOwnScale ); ////////////////////// end //////////////////
Trading all available funds
For all runs, the initial equity is set to $100,000.
The first run was made assuming that all available funds were used to take each position.
A chart follows that shows the price series of SPY as black candlesticks, a blue line showing the 200 day moving average, arrows showing when trades were made, and a green line showing the account balance.
The report giving the statistics follows.
The charts produced by the report utility follow.
Note that only 17 percent of trades were profitable, and the drawdown in each of the five periods exceeded 17%, with a 38% drawdown in 2000 and a 27% drawdown in 2010.
Trading a $10,000 basic unit
In order to evaluate the profit potential, risk, and position size, the system was re-run. Each trade is $10,000 — a “basic unit.”
The report giving the statistics follows.
The charts follow.
When all funds were used for each trade, the order of the trades distorted the equity results. Results from trading a single unit show that the 200 day moving average is a poor indicator and produces results indistinguishable from random.
Mean, standard deviation, and t-score of long trades are 0.0028, 0.0520, 0.3871 respectively.
Mean, standard deviation, and t-score of short trades are -0.0006, 0.0641, -0.0643.
Mean, standard deviation, and t-score of all trades are 0.0011, 0.0582, 0.1928.
A t-score above about 1.68 shows the results are better than random at the 95% level of confidence.
If the results had been promising, then an analysis of profit potential, risk, and position sizing would be performed using the trades generated by the basic unit runs. Since these are not, no further analysis of applying the 200 day moving average to SPY is performed.
Individual stocks
SPY is designed to follow SPX, the S&P 500 index, closely. SPX consists of about 500 individual stocks chosen by a committee at the Standard and Poor’s Company. Due to the effects of the central limit theorem and the law of large numbers, the distribution of prices for SPX is expected to be close to and smoother than the distributions for the constituent stocks. Consequently, indexes and funds that track well defined sectors are generally easier to model successfully (lower drawdowns, in particular) than individual stocks. This was tested by running the same trading system on about 30 individual issues, all components of SPX, all of which were roughly net flat for the same period. Some produced profits, some losses, but a portfolio of them lost money. The initial account balance was set to $1 million to insure there would be adequate funds to take all possible positions. The report giving the statistics follows.
The charts follow.
No doubt there are other ways the idea can be used, but these tests show that using the crossover of the close with the 200 day simple moving average of the close is not profitable for either individual stocks or for a broad market index.
What does this mean for a trader?
When the guru states: “XXX has just crossed above its 200 day moving average and that is a signal to buy.” Don’t do it. At very least, don’t do it until you have run tests using your own version of the indicator on the issues you will be trading.
Does any other moving average length work?
Using SPY for the same period, the length of the moving average was tested using lengths from 2 days to 400 days. Based strictly on profit, the best results came from a length of about 370 days, including lengths nearby, indicating the parameter is robust. There are 45 trades, 8 of which are winners. The mean, standard deviation, and t-score are 0.0464, 0.1849, and 1.68, respectively. If these results were from using out-of-sample data, they would probably be significant. But the analysis is not exactly comparable. In tests reported previously, a fixed lookback length of 200 days was used in all runs. Due to the historical importance of the 200 day period, we can make the case that there is no parameter fitting going on, and all runs are out-of-sample. In this run, I examined all possible lengths from 2 through 400, and found that 370 was best. This is clearly an in-sample result. In order to verify that 370 is a good length, out-of-sample testing is required. Unfortunately, 370 trading days is one and a half calendar years, which makes it difficult to perform walk forward validation. (In order to get reliable results, the length of the out-of-sample period must be long enough so that very few trades extend over either the beginning or end of the period.) As above, we can test other data rather than other time. Running the system with a 370 day length and the 30 stocks, the results are poor. Most individual stocks lose money. The portfolio shows a steady loss right from the initial date with no period of positive equity.







You need to be loged to make a comment