Greetings all --

The thread that prompted me to make this posting began with the question of 
whether a system based on a simple-moving-average crossover was profitable and 
would remain profitable.

I used this code to test that:
//      Test MA Crossover.afl
//

BuyPrice = SellPrice = C;
ShortPrice = CoverPrice = C;
SetTradeDelays(0,0,0,0);

OptimizerSetEngine("cmae");


FastMALength = Optimize("FMAL",1,1,200,1);
SlowMALength = Optimize("SMAL",10,1,200,1);

FastMA = MA(C,FastMALength);
SlowMA = MA(C,SlowMALength);

Buy = Cross(FastMA,SlowMA);
Sell = Cross(SlowMA,FastMA);
Short = Sell;
Cover = Buy;

e = Equity();

ArrowShape = Buy*shapeUpArrow + Sell*shapeDownArrow;

Plot(C,"C",colorBlack,styleCandle);
PlotShapes(ArrowShape,IIf(Buy,colorGreen,colorRed));
Plot(e,"equity",colorGreen,styleLine|styleOwnScale);

//////////////////////

Samantha suggests Buy when the monthly price is above the 10 month SMA, Go to 
cash when it is below.

When tested on the 500 stocks currently in the S&P 500, using end-of-day data 
from Quotes Plus that goes back to about 1993 (for companies with history that 
long), the median exposure is about 50% and the median RAR is about +9%.

As asked, the question assumes that being long or cash is the correct 
allocation.  For many reasons, a trader may want to consider only long 
positions.  But recent history (1984 to the present) has been a period of very 
strong rising markets.  The future might be different.  Using SPY as a 
surrogate for the broad market, the result of that same test are an exposure of 
61% and an RAR of 12.6%.

We can ask several questions:
1.  Using full knowledge of the history, what are the best parameters for a 
trader who wants to use only long positions?

First, we need to decide how to measure best.  We'll make a few runs with 
different objective functions and note the results.

Net % Profit.
The best values for the parameters are 2 and 12.  Net profit is 304% (every 
initial $1.00 becomes $4.04).  Maximum drawdown is 15.3%.

CAR/MDD.
Best values are 116 and 15.  Backwards.  This implies the trade should be flat 
when the faster moving average is above the slower, be long when it is below.  
Net profit is 51%.  Exposure is 6%, RAR is 39%.

Maximum System Drawdown.  
The best result is to never trade.

Sharpe Ratio -- used by many money management firms.
Best values are 97 and 13.  Backwards again.  64% return with 13% exposure, for 
an RAR of 22.7%.

RRR (Same as K-Ratio).
Best values are 1 and 12.  292% return, exposed 63%, RAR of 13.8%.

The best results depend very much on the definition of best.

2.  If the trader was able and willing to take short positions, what is best 
for them?

Net % profit.
Best values are 7 and 18.  64% return, exposed 26%, RAR of 11.7%.  

CAR/MDD.
Best values are 1 and 24.  63% return, exposed 25%, RAR of 12.1%.

Maximum System Drawdown.
The best result is to never trade.

Sharpe Ratio.
Best values are 5 and 22.  63% return, exposed 24%, RAR of 12.5%.

RRR.
Best values are 7 and 18.  64% return, exposed 26%, RAR of 11.7%.

3.  If the trader wants a system that is always exposed, long or short, and a 
single set of values that signal reversals. 

Net % Profit.
Best values are 1 and 22.  Net profit is 534%, exposure 88% (flat at the 
beginning until the averages have enough data), RAR of 13.6%.  Maximum drawdown 
is 16.3%.

CAR/MDD.
Best values are 1 and 23.  Net profit is 534%, exposure 88%, RAR 13.6%.

Maximum System Drawdown.  
The best result is to never trade.

Sharpe Ratio -- used by many money management firms.
Best values are 78 asnd 47.  Backwards again.  76% return with 34% exposure, 
for an RAR of 10.3%.

RRR (Same as K-Ratio).
Best values are 7 and 18.  522% return, exposed 89%, RAR of 13.2%.

However --- those are all in-sample, backward looking results.  And none of the 
results have more than a handful of trades.  Beware of making estimates of 
future performance based on in-sample results (even when there are a lot of 
data points, but that is another topic).  

4.  What are the results when a period of several years is analyzed, the best 
parameter values select based on those years, and the future results computed?  
Since the moving average lengths are so long --  typically around 24 months -- 
the in-sample period must be longer.  

Five years is a long enough in-sample period to get some results.  But, in part 
due to the edge effects of the walk forward process, one year is not a long 
enough out-of-sample period.

An in-sample length of six years, out-of-sample three years, starts to give 
results, but the out-of-sample results are not profitable.   

Six years and four years gives only two steps -- one profitable, the other not.

My conclusion is that we cannot determine whether a moving average crossover 
system based on monthly bars is likely to be profitable in the future or not.  
Sixteen years of monthly data -- 192 data points is insufficient to allow 
meaningful validation.  

What next?

1.  Add more data.  We might think that adding data from earlier periods will 
help.  Testing to find out what moving average lengths worked best in the 1930s 
through the 1980s might be interesting, but it is still in-sample and has no 
value in estimating future performance.  But we could run walk forward tests 
beginning at an earlier date and observe more steps.  Whether those results 
look promising or not, we are still stuck with using the data we have from 1993 
through the current.  So we might find out what the best lengths of the 
in-sample and out-of-sample periods are.  But we already know that the system 
is not sufficiently profitable or stable over the past eight years or more to 
actually trade it or to use it as a filter.

2.  Use short bars.  Moving to weekly bars increases the amount of data to 
about 830 data points.  Moving to daily bars increases the amopunt of data to 
about 4000 data points.  

Using weekly data, walking forward, two years in-sample, one year 
out-of-sample, long only, RRR as the objective function.  The results are 
pretty promising.  The system is profitable in nine OOS periods, unprofitable 
in three, and does not trade in two.  But the values of the parameters are the 
interesting part.  In 11 of the 15 OOS periods, the values are backwards.  That 
is, be long when the faster moving average is below the slower moving average, 
and go flat when it crosses from below to above.  The values of the parameters 
vary quite a lot, with four of the steps having both lengths greater than 60 
weeks.  In the steps where the moving average periods are both below 30, 10 of 
11 have the values backwards -- often the faster period is one bar.

The conclusion I draw is that the traditional thoughts on using moving average 
crossovers as filters for trading systems have it backwards.  When run as a 
walk forward test, which is the only way to estimate what future performance is 
likely to be, the S&P 500 is mean reverting, not trend following.

Thanks for listening,
Howard
 

Reply via email to