Disclaimer: I am not an investment advisor. When I describe my own trading activities, it is not intended as advice or solicitation of any kind.
Showing posts with label crossover. Show all posts
Showing posts with label crossover. Show all posts

20 April 2011

Revamping CS|MACO

NeighborTrader and I have been talking a lot about back-testing lately.  Back-testing is when you take a bunch of historical price data, and push it through a trading strategy to generate buy/sell/close signals as if you were running the strategy at that time.  Then you see how the strategy did, and try to extrapolate how it might do in the future based on those results. Ever hear the phrase: "Past performance is no guarantee of future results"?  Well, the same applies to back-testing, but a little information is better than no information at all.

NeighborTrader back-tested the CiG trade before he ever talked to me about it last fall, and he's been combing through data ever since to find more trades he can run.  I've been meaning to do the same with CS|MACO for quite some time, and I finally did this weekend.  I learned some interesting things, and I found a few changes I want to make.

I grabbed daily historical prices for SPY from January 1993 through March 2011.  I also grabbed the AAII sentiment data for that same period of time.  I wrote myself a little Python script to collate the data together, and then plugged all of that into a spreadsheet that created signals just like my present-day trading spreadsheet.  To this, I added some calculations to figure out the results of the trades, and compare them to simply buying SPY and holding it. 

As designed and outlined in this post, CS|MACO underperformed SPY over the 18-year period from 1993-2011.  Then I abstracted away all of the parameters so I could change them easily, and started playing around.  Next I evaluated various time periods based on the sort of market they covered: I looked for bullish and bearish periods, triangular moves up and down, and sideways choppiness.  I compared CS|MACO against SPY in bottom-to-bottom and top-to-top time periods, as well as a simple 5-year rolling time period throughout the 90s.  Once I had a feel for how CS|MACO behaved in various market scenarios, I started changing the parameters, and learned some things.

The first thing I learned is that the 25/200 moving average crossover component of MACO is far too responsive, and tends to trade into choppy sideways markets, losing money on every reversal.  To catch the really big trends, much bigger moving average periods, and more similarly sized periods, are far better: 200/300 seemed to be a good mix.

The next thing I learned is that the arbitrary 10% collar I have on the CS component is about right, but only for the buy signal.  This outcome was fascinating, and I think it gives insight into individual investor psychology.  If I'm right, it means that the CS buy signal (which is based on below-average levels of bullishness in the survey) is a leading indicator while the CS sell signal (which is based on above-average levels of bullishness in the survey) is a lagging indicator.

Bear in mind, this all just my viewpoint: I think we as humans tend to invest our emotions as well as our money, and we are very slow to accept that we are in a losing position and get out of it.  On the other hand, we are much quicker to jump into a new position if we think there is opportunity there.  The vast majority of us do not short-sell anything (my father thinks it's un-American and somehow Satanic), and so statistically, investors tend to become bullish faster, and become bearish much slower.

To handle this lopsided behavior, I changed things so that I could control the bullish/bearish thresholds independently.  Then I tried turning one and then the other off by setting them so wide that the indicator could never reach them (+/- 100% certainly works).  I discovered that turning CS off entirely made things worse: MACO, by itself, is not a winning strategy.  Actually, let me be clear: it does have positive returns, but it does not beat SPY itself.  Turning on only the buy (bearish investors) signal had the most positive effect. 

So, how about the results?  In rolling 5-year periods, CS|MACO was profitable in just about all of them - can't say that for SPY, not by a long shot.  When it beat SPY, it beat it badly; when SPY beat it, it wasn't nearly as big a difference.  The best part is that CS|MACO tended to diverge up from SPY in down markets, and pace it fairly well in up markets.  It really only lost ground in prolonged sideways chop markets.  And by prolonged I mean like longer than a year of nothing but sideways chop - that's pretty rare.

A big danger of back-testing is sample bias, also known as curve-fitting or false optimization. This is where you optimize your strategy against all the data you have, and assume that tomorrow will just like your data sample.  In a perfect world, we would like to use a sample of, say, 1995-2000 to train our strategy, and then make sure it still works from 2000-2011 before committing real money to it.  This is called split-sample testing.  However, I feel that the behavior of the markets and the attitudes and psychology of the individual investors have changed somewhat over the last 18 years.  For me to find a strategy that works well in the 90s, and expect it to continue working in 2012 and beyond, is naive.  So I have to flirt with that sample bias problem, but I try to watch for it and be aware that it is always there without falling into it.

Below is a graph that compares SPY to CS|MACO for the whole 1993-2011 period.  SPY is the red line, and CS|MACO is the blue line.  Notice how when SPY suffers, CS|MACO profits.  This makes it a very viable strategy for running alongside a standard retirement account holding index funds.  And for me, that's just perfect.

(click for the original size)

31 March 2011

Not The Spreadsheet's Fault

Two weeks ago, CS|MACO gave me a Buy signal when AAII.com released a bearish investor sentiment report -- bearish investors correspond well to short-term market bottoms, that's why we call it Contrary Sentiment.  The moving-average crossover component had no strong feelings either way, so the CS-based Buy signal was allowed to generate a system-wide Buy.  I dutifully bought SPY near the open price in my paperMoney account.

A week later, as the market rose, investors relaxed their concerns somewhat and found their bullish mojo again.  37.7% of them gave the thumbs-up to the world, which was outside of the Buy range, but not above the 41.5% required to close the trade.

Finally last night, a new report came out at 41.8%...just high enough to get a close signal.  But now SPY was above its 25-day moving average, which in turn was above the 200-day moving average.  So while CS went from Buy to Flat, MACO went from Flat to Buy.  Flat+Buy=Stay-Long.

If I had managed to put the numbers into the newly-fixed spreadsheet correctly, that's what I would have done.  Instead, I fat-fingered the 200-day moving average, entering 4119.49 instead of 119.49.  The spreadsheet was a little taken aback by this sudden 4000% spike in the long-term moving average, but kept a stiff upper lip about it.  "Guess you better sell, boss," it said.  I sold.

Hey, I got a great price, getting out about 35c above the close for the day.  But first thing tomorrow I'll have to get back in.  And I'm betting that the Employment Situation Report tomorrow an hour before market-open is going to send the S&P up sharply, causing a gap-up in SPY that will cost me for my stupidity.

Can't blame the spreadsheet this time... garbage in, garbage out.

16 November 2010

Big News for Boring Trades

It's been a busy few days.  The CiG trade finally fired a signal on Friday, but I was in Colorado all weekend so I didn't have time to write it up.  Then I came home with a head-cold just in time to support a major roll-out at the office that went pretty wrong.  By the time I got home last night all I wanted to do was sleep.  So now here we are.  Excuses excuses.
 
Saving Money While Asleep
First the CiG trade on Friday.  You may recall I decided to run it on S&P futures as well as treasury note futures, because I feared that treasury notes would bore me to death.  On Friday, it signaled a buy-on-close on the S&P, so I did.  Things were looking good Monday morning, but not good enough to reach the target exit signal.  By this morning, the whole world was fleeing from risk again and the stock market opened significantly lower.  Since there are no clearly-defined stop rules, I decided to sell the position for a loss shortly after the stock market opened.  I felt that what we were seeing was not a momentary blip but in fact a setup for a selling day.  I was right: I sold the position at 1188 at 9:00.  At the 3:00 close, ES was down to 1176.

Because CiG tries to buy on dips, though, it had another buy signal come out on ES today.  Pleased at my ability to dodge at least some of the sell-off today, I decided to get back in with a new long position at the close.  So I'm still long from Friday, but I took a 12-point ($550/contract) hiatus.  That's almost a winning trade all by itself.  Not a bad money-saving siesta.

No joy in treasury note futures yet.  Yawn.

Insert Spy Pun Here
CS|MACO, another boring trade, is finally starting to see some life.  It has been locked flat while SPY has rallied over the last 3 months, due to the bearish signal coming out of the contrarian investor sentiment component and the bullish signal coming out of the moving-average-crossover component.  One of those two opposing forces was removed today when SPY closed below its 25-day moving average, breaking the SPY>25MA>200MA relationship that has been in place since October 4.  That's not a sell signal yet, though, because the terms of the trade state that I won't enter a position on the removal of a signal.  I need the CS component to affirm its bearishness tomorrow after the close before I can short this puppy.

A Boring Iron Condor is a Good Iron Condor
Unfortunately, this one is starting to get a little exciting.  When I opened the position I groused about my poor judgment a little bit regarding the low price I was paid to initiate.  Sure enough, the VIX almost immediately rallied while RUT flagged, causing my delta to increase as I rode the curve down toward my put spread.  Delta of +16 this morning, so time to adjust already.

It seems ridiculously early to be thinking about exit orders, but I could buy back my call spreads for only 60c already; so I put in some limit orders to buy back at 20c.  That doesn't help my delta, but it does lock in a profit on half the trade - and with some careful adjustment the other half might not cost too much.

As for the put spreads, I looked at the mouse-ear like I used last month and decided it was overkill: RUT was 710 or so when I was adjusting, and my put spreads are 660/650s.  A mouse-ear would throw my delta so horribly negative that I would have to buy back most if not all of my call spreads to contain it.  Plus it was crazy-expensive, at $21.

The next thing I looked at was simply reducing the call spread position.  That would certainly help the delta and the feel of the position, but I felt the cost was a little high.  A variant of this is to roll the call spread down a few strikes, also increasing the position a bit to finance the roll.  This increases risk, and I wasn't happy with the outcome or my perception of the risk-reward trade-off.

I also looked at Wolfinger's Kite Spread, which involves a naked long OTM put and a credit put spread even farther OTM with 3-4x the size on it for financing.  That had some real potential, but it really hurt the theta.  Ultimately I decided I could achieve my delta goals and flatten the value graph best by putting on some 630/640 debit put spreads.  I bought just enough (at 1.90) to get the delta under +5.  By the close, the delta was back up to +5 again, but that's within my parameters.

Boring News for Big Trades
I'm still not holding GLD calls, and I'm glad.  I'm looking for bargains in some of the mining companies right now, but I haven't had time to look very hard yet.  Earnings season is upon us, and if I can capture a couple of positive earnings surprises before the event-driven IV goes through the roof, I'll be a happy camper.

05 October 2010

I Spy a Crossover

I'm running a mechanical trade in paperMoney on SPY that is based on Simple-Moving-Average Crossovers.  I just started running this trade, but I did a little back-of-the-envelope backtesting before I started and I really liked the way it performed over the last couple of years.  Since the 25-day SMA crossed the 200-day SMA to the upside today, it bears mentioning.

There are two competing indicators in this trade: moving average crossovers (MACO) and individual investment sentiment, which I use as a contrary indicator (CS).

Moving Average Crossovers
MACO is bullish when the SPY daily closing price is higher than the SPY 25-day SMA, which in turn is higher than the SPY 200-day SMA.  MACO is bearish in the opposite situation: when SPY closes below the 25-day SMA, which in turn is below the 200-day SMA.  In any other closing price configuration, MACO is neutral/flat.

If this was where it ended, this would be a classic long-term trend-following trade.  It would have killed in 2009, and been killed in 2010.

Contrary Sentiment
The American Association of Individual Investors publishes a set of weekly indicators based on surveys of their members.  They give the percentage of their responding members that are bullish, bearish, and neutral.  I have arbitrarily chosen the bullish indicator, and I use the prior calendar year's average value as a midpoint - this year, that midpoint is 36.8%.  I then set the entry lines 10% above and below that value.  I get a new value from AAII every Wednesday, when they publish the survey.

CS is bullish when the surveyed value is below (yes, below) the low entry line, bearish when the surveyed value is above (yes, above) the high entry line, and signals "exit" when the surveyed value crosses the midpoint.  I basically use it to fade individual investor sentiment, because I think most people are morons - especially those who spend money on a membership to a website so they can donate their time filling out surveys.

So when that bullish indicator is above 46.8%, CS will initiate a "short" signal, remaining in "short" state until the indicator drops below 36.8%.  When the bullish indicator is below 26.8%, CS will initiate a "long" signal, remaining in "long" state until the indicator rises above 36.8%.  I'm trying to only place bets against other investors when it is more or less universally agreed upon how great/shitty the world is.

As a momentum-fading indicator, CS kills in sideways markets like most of 2010 has been.  It gets killed in trending markets like 2009, where everyone got really excited and stayed really excited while the stock market rallied a gazillion points for no reason.

Putting it all together
Now I aggregate the signals thus:
  • If both CS and MACO say "flat/neutral", my position is flat
  • If CS and MACO disagree (long/short or short/long), my position is flat
  • If CS and MACO agree on a position (rare), I take that position
  • If one says "long" and the other "neutral", I'm long (but see below)
  • If one says "short" and the other "neutral", I'm short (but see below)
  • If there was a disagreement (long/short, short/long), and MACO goes to neutral/flat, I do not initiate a position until the next CS survey release is in the "initiate" zones.  I do not "back into" positions.
  • I only use closing prices for the MACO portion, and I trade the next day on the open.  If SPY gaps back through into neutral territory before the open, I treat it as no signal.  This basically just makes the backtesting easier.
In my backtesting, I compared various combinations of CS and MACO to a simple "buy and forget" strategy, resetting the entry price on 1 January each year.  I found that CS tended to keep MACO out of trouble by catching the tops and bottoms of the market trends really nicely.  On the other hand, MACO would keep CS from gritting its teeth and fading a long-term trend for a huge loss.  In fact, as a long-term trend asserted itself, CS would gradually drift into neutral territory, allowing MACO to get a position on and chase the trend.

The combination I describe above didn't consistently beat the "buy and forget" strategy, but: (a) it was a lot more fun; (b) buy-and-forget is what we all already do in our 401(k)s anyway - this whole trade is a diversification, in my opinion.  And, honestly, it has beat the snot out of "buy and forget" so far this year.

Where are we now?
The last entry signal in CS was "short" on 16 September, when the survey came out 50.89% bullish.  It has since drifted lower.  The most recent survey on 30 September was 42.5%, which would not cause a new position, but it remains "short" because we haven't gone through 36.8% yet.  We get a new survey tomorrow, and I'll go out on a limb and predict that it will remain above 36.8%.  In fact, for double-or-nothing I'll predict an up-tick from last week.

MACO, on the other hand, has been flat/neutral since 2 September, when SPY closed at 109.47: above the 25-SMA of 109.09 but below the 200-SMA of 111.79.  SPY has been trading above both of its moving averages since gapping higher over the weekend before 13 September, and today it finally dragged the 25-SMA higher than the 200-SMA at the close, generating a "long" signal:
  • SPY Close: 116.04
  • 25-day moving average: 112.46
  • 200-day moving average: 112.05
With MACO transitioning from "neutral/flat" to "long", there is a disagreement so the trade is flat.