[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Testing a moving average crossover system



PureBytes Links

Trading Reference Links

> When we 'plot' an MA(C,10) line everything else is measured relative to this construct.

Repeated mental constructs tend to become habitual ... moreso if we actualize them in the 'real world' == PhysicalWorld;

Note also that no one in the forum complains when I use AFL as part of the English language, because we are habitualized to thinking in AFL and using in our prose is a natural extension.

A labourer once said to me,"Habits are easy to manage, just start a new one".

--- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@xxx> wrote:
>
> For the trading philosophers (on modelling):
> 
> When we look at a chart of an index, say the monthly ^DJI, if we really 'look' at it, without prejudice, we see apparently random datapoints, or at least meaningless datapoints, until after we determine our perspective and overlay it on the charts.
> 
> When we 'plot' an MA(C,10) line everything else is measured relative to this construct.
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
> >
> > Thanks for that Howard.
> > 
> > Samantha's topic was an excellent study piece, both from a technical and behavioural perspective, and now it continues here.
> > 
> > There were a lot of behavioural issues highlighted by the discussion.... it would take me quite a while to canvass them all and I am not sure about the level of interest so I will confine myself to a short summary:
> > 
> > Self-managed investors, of which 'traders' are a subgroup, are an extreme minority on a world scale, even when restricted to those who are financially literate .... possibly they aren't even a majority in this forum.  Speaking for myself only, I think it is safe to assume that my opinion isn't as important as I think it is and that my investment style isn't as topical as I think it is (I say this so that we can put the discussions on 'all trading systems are discovered and traded to failure', and it's derived arguments, into a rational perspective).
> > 
> > I am sure the financial world is a different place, for those with clients (Financial Planners/Fund Managers etc), than it is for a self-managed retiree or a self-managed trader, for example.
> > 
> > Perhaps the smile on the clients faces is the number one metric used by FinancialPlanners.
> > 
> > To that end:
> > 
> > - the study we are referencing is not Samantha's... it is from Faber's paper, which I find extremely well writtten and interesting ... he/she quotes from several interesting referenced sources
> > 
> > - specifically, studies referenced by Faber meant that up to 2006 had to be considered IS and the OOS sample can only be from 2006 to the present ... this data is included.
> > 
> > - for the referenced studies the IS varies ... one goes back to the turn of the previous century
> > 
> > - Fabers study is conducted on a TotalReturnBasis
> > 
> > - the chosen metric is RiskAdjustedReturn although overall the results are summarized by the statement that
> > 
> > "in the five asset classes
> > tested, the timing approach improves the results over buy-and-hold in each of the four
> > metrics (return, volatility, Sharpe and drawdown) for each of the five asset classes."
> > 
> > In lay terms ... trend following, timing systems outperform in bull years and reduce/minimize losing years/amounts.
> > 
> > I agree with Samantha's comments that these are desirable qualities for retirement account investments.
> > 
> > I am not sure if Samantha advocated this model before 2008 but certainly the paper itself highlights the fact that historical returns, in all asset classes, are marred by occassional heavy drawdowns and that in 2008 (for the first time?) the assumptions about diversification where tested to breaking point (I did say in this forum, around 2-3 years ago, that diversification by asset class and market was an old world financial model ... now we see the reality of globalisation and the (NewAge) one world market?)
> > 
> > From the paper:
> > 
> > - recently correlated returns were negative for all asset classes
> > - G7 countries experienced 75% losses that need a  300% gain to get back, which is equivalent to 10% for 15 years compounding
> > - individuals do not have sufficiently long time frame to recover
> > - the correlation between negative years for the S&P
> > 500 and the timing model is approximately -.37, while the correlation for all years is approximately .82.
> > 
> > - timing improves risk-adjusted returns in about two-thirds of all decades and improves drawdown in all but one decade.
> > 
> > Note the objectives of Faber's approach:
> > 
> > "The attempt is not to build
> > an optimization model, but rather to build a simple trading model that works in the vast
> > majority of markets. The results suggest that a market timing solution is a risk-reduction
> > technique that signals when an investor should exit a risky asset class in favor of risk-free
> > Treasury bills."
> > 
> > At the end of the paper the implications for portfolios and leveraged portfolios are briefly considered.
> > 
> > IMO opinion self-managed investors/traders do not operate in a seperate financial universe, from others, and the principles dicussed in this paper apply equally to mechanical system design and diversification by system etc.
> > 
> > 
> > 
> > On the technical aspect (not in order of significance and certainly not complete):
> > 
> > (I haven't done any testing and I am relying on conceptual analysis and experience for this opinion).
> > 
> > - for long strategies, in any timeframe, selling when the market is falling and buying our 'holdings' back, at a cheaper price, is always theoretically justified ... only transactional costs, exascerbated by whipsawing prices, negatively impact the strategy ... the strategy is always justified IF the cost of the round trip is less than the avoided 'losses' (nominal losses for system designers)... the challenge is first to achieve this in a cost effective way, if it can be achieved at all, and then to optimize the strategy from there. IMO a large part of trading effort goes into that pursuit (catching the falling knife).
> >  
> > - re the small sample size available for monthly testing ... volatility (risk, evidenced as drawdown) can only increase with a longer sample period? ... so, in the long run, the 'benefit of  doubt' is in favour of timed systems, over the B&H strategy
> > 
> > - QP data is not dividend adjusted , nor does it take into account delistings?
> > 
> > - if we test on an index we don't need to worry about delistings because, irrespective of the constituents, we could have actually traded the index at the historically recorded prices, if we were around at the time?... same if we test endemic patterns in RT data?
> > 
> > - prices always 'revert to the mean' and this has two components ... reverting to the mean when the price is above the mean or below the mean ... Howard's study shows that 'fading the trend' (going short when above the mean) underperforms compared to going long when below the mean ... in the long term it always will because the stockmarket is upwardly biased (by earnings and or inflation?)
> > 
> > - one way to get around small datasets, when using long timeframes, might be to identify and treat non-correlated assets as different datasets ... perhaps non-correlation might only occur in 'screaming bear years' that come around every 7-10 years (maybe less ... who knows ... the future might be different to the past?).
> > 
> > - MA(10), chosen for the study, is one of the simplest trend following systems .. it is not necessarily the optimum system for meeting Faber's objectives
> > 
> > - Fabers paper showed that a small range of variable MA's for the monthly period all improved the 5 chosen metrics in historical data
> > 
> > - high volatility diminishes compound returns.... evaluation should be considered on a compounding basis ... careful selection of the metrics needs to be made with that end in mind.
> > 
> > - when will MA(10) systems fail? ... who knows how many are trading this system and if they will trade it to failure but it will definitely fail if the underlying instrument (the market you are trading) stops trending i.e. it goes sideways or whipsaws back and forth across the MA
> > 
> > - markets always revert to mean because moving average 'indicators' are momentum indicators and they always lag (when price momentum slows the MA will still be going up and they cross each other when the price slows markedly, relative to the MA).
> > 
> > - I didn't test this but I plotted PivotLo(Close),  from the Zboard example, on the ^DJI, using Yahoo EOD data - going back a few decades ... to the naked eye PivotLo (sell when the close crosses below the prev PivotLo(C) seems to outperform MA(C,10) when it comes to avoiding whipsaw on the sell (not all whipsaw, just some) ... MA10 does quite a remarkable job though, for a simple indicator .. no wonder it has enduring appeal ... Buy when C crosses above previous PivotHi(Close) ... to the naked eye MA10 seems to outperform PivotHi when entering.... the entry is the hardest part to optimize (note when I use the term optimize I don't primarily mean parameter optimization althought I don't rule it out).
> > 
> > - PivotHiLo is an adaptive indicator (it is self-adjusting regarding dimension and timing == periods, phase, freqency, probability?)
> > 
> > - chart traders (pattern traders) don't have reversion to mean to consider, or optimize parametrically
> > 
> > - chart patterns are fractal/holographic (not sure what term to use there ... maybe I will coin one or be more decisive about it in the future) .... so trend (momentum) patterns are endemic in price charts ...therefore similar probabilities, for the same trade, or class of trades, can be found in lower timeframes ... therefore Howard is correct in moving the anlaysis to lowertimeframes to obtain acceptable N values ... generally (subject to data limitations) I find that higher timeframes (monthly bars) are biased towards trending (non-random behaviour) slightly more than shorter timeframes (randomness is slightly more prevalent in intraday data ... perhaps tick data is even chaotic ... I haven't worked with tick data so far so that is only a hunch at this stage)....anyway, as long as caution is applied the CoreMetrics will be similar across all timeframes (say 5min - monthly bars .... which is what I have checked ... core price behaviour might persist into 1 min or below ... I can't say without checking)
> > 
> > - while the structure, and hence viable systems, is similar between timeframes, increased transactional friction will tend to impact more on shorter timeframes.... commission and slippage are the killers in short timeframes and not the unreliabilty of TA.
> > 
> > I am sure I have missed a few interesting observations from the MA10 study but I am going from memory.
> > 
> > 
> > 
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Howard Bandy" <howardbandy@> wrote:
> > >
> > > 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
> > >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/