Saturday, October 11, 2014

thinkscript included: is trading the hull moving average a good strategy?

on tuesday, october 7th, on tastytrade's tech-tools segment, steve miller, aka slm, said he liked the hull moving average and encouraged his users to "play" with it. so i did. 

the hull moving average employs a smoothing technique that claims to reduce "lag" - a trading signal that comes a little too late. if you watched slm's presentation it clearly seems to do just that. the rollover of the hma certainly seems to occur way before some of the traditional moving average crossovers that investors watch - but can that make you money? 

it's really hard to eyeball a chart and make an assessment that is not subjective. first of all, the rising/falling color transition is not fully determined until the candle after the transition completes. this means that a trade entry would not occur until the open of the 2nd candle past the color transition.  the cumulative p&l of trades taken this way is something i wouldn't want to evaluate by eye. fortunately, there is the thinkscript strategy facility, with which i can simulate trading such signals and evaluate these things objectively. so here's a typical picture of the hull strategy at work:
simtrading $10k on spy via hull moving average signals compared to passive investment
the top graph shows when and at what price the hull strategy  bought, reversed and shorted $10,000 worth of spy, as indicated by the pink labeling and arrows. the pink number is the amount of shares transacted. when the dashed line connecting the reversals is colored cyan the trade made money and when the dashed line is colored red the trade lost money. the floating pl subgraph shows the day-by-day cumulative profit and loss for the strategy over the 1-year duration of the chart. the bottom subgraph shows the growth of $10,000 invested over the same period of time by the buy 'n hold method and by dollar-cost averaging (i.e. buying about $833 worth of spy every month.) so here we see that, as of Oct 8,14, that the hma strategy was down money while buy 'n hold showed a position improvement of +$1,650 and dollar-cost-averaging, +$372. this is very typical of the equities i looked at.

now the kinds of equities i tend to be interested in reflect that i tend to be a long trader. however, i did find that the hull strategy shined for equities in a long-term decline. take gld, for instance:

and even more impressively, slv:

so it seems that if you have a bearish opinion that was formed by some other method, that taking the bearish trades from the hma signal could be profitable.

here is the code (how to install):

# sdi_hullmastrat - plot results of trading the rollovers/unders of the hullMovingAvg 
#hint: shows the trade simulation of trading the hullMovingAvg rollovers / unders using a fixed amount of money. rev:1.0.0 
# author: allen everhart
# date: Oct 11, 2014
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale. 
# Help me get the word out about my blog by keeping this header
# in place.

input dollarsPerTrade=10000;
#hint dollarsPerTrade: controls the amount of money the simulation uses to trade. rev: 1.0.0 
input length=20;
#hint length: the number of charting periods passed to the hullMovingAvg calculation. 
def shareSize = Round(dollarsPerTrade / close, 0) ;
def ma=hullMovingAvg(length=length);
def buySig=ma crosses above ma[1];
def sellSig=ma crosses below ma[1];
addOrder(OrderType.BUY_AUTO, buySig,name="long", tradesize=sharesize);

addOrder(OrderType.SELL_AUTO, sellSig, name="short", tradesize=sharesize);

Saturday, October 4, 2014

thinkscript included: how to beat the s&p with a simple seasonal strategy.

it's that time of year again. no, not to binge on candy and tp your neighbor's tree. it's the time of year to initiate the world's most boring strategy that happens to beat the s&p over the last 15 years. that's right, you don't need cramer, a hedge fund, a certified market technician, nor even an astrologer to beat the market. you just need to trust that something that has been working will continue to work: the halloween strategy.

the halloween strategy is the flip-side of the market aphorism: sell in may and walk-away. it tells you when to buy. thus, there are just two rules:

  1. buy on the first close above the 50 day simple moving-average in the month of october.
  2. sell on the first day in the month of may.

how's this been working? well, let me draw you a picture:
trading $10k on spy via halloween strategy vs. growth of $10k via passive strategies
this chart shows that the profit and loss of trading $10,000 (without compounding!) of spy, the s&p 500 etf, by the halloween strategy over the last 15 years produced a net profit of $10,261 (double the $10k trading capital.)  this beats both the passive strategies of buy 'n hold and dollar-cost-averaging over the same period which only improved the 10k invested by 5k. (note: there is no accounting for dividends and commissions.)

while it might seem fantastical to double in 15 years let me remind you that this only amounts to an annualized return of 6.8%, uncompounded.

should you participate in this year's halloween? let me just interject the cliche disclaimer: past performance does not guarantee future performance. however, knowing the past can help temper expectations. if we extend the picture back 20 years we see something different:
halloween strategy vs passive investing over 20 years
now, halloween strategy (profit of $18.5k) falls in between buy 'n hold (profit of $33k) and dollar-cost averaging (profit of $6.5k.)  so, the boom-boom years of the late 90's were not years of out-performance for the halloween strategy relative to buy 'n hold (trick!)  however, if you didn't inherit wealth 20 years ago then you are stuck doing some sort of dollar-cost averaging. this halloween strategy could be a great 401k strategy - put your money in an s&p fund for half the year and then in a fixed-income fund for the other half. if you reinvest the profits then you will get a compounding effect, which can be estimated by the rule of 72. thus, given average past results, one might expect this strategy to double your money in about 11 years.

here's the thinkscript (how to install):

# Derived from TDA's halloween strategy.
# With minor modifications to create a constant dollars Per Trade by Allen Everhart 
# Source: 
input dollarsPerTrade = 10000;
input price = close;
input length = 50;

AddOrder(OrderType.BUY_AUTO, GetMonth() == 10 and price > Average(price, length), tickColor = GetColor(1), arrowColor = GetColor(1), name = "HalloweenBTO", tradeSize = Round(dollarsPerTrade / price, 0));
AddOrder(OrderType.SELL_TO_CLOSE, GetMonth() == 5, tickColor = GetColor(2), arrowColor = GetColor(2), name = "HalloweenSTC");