Sunday, July 24, 2011

Review of a SPY System I Created

Back in December I created a very basic end-of-day mechanical trading system based on the $SPY. The creation of this system served as an experiment in system development for me. At the time, I wondered whether I could trade this system in real time.  The only way to know is to actually trade it; and six months later, I have some thoughts.

How was the performance?

Below is a simple summary. Every trade can be found here.


Historical
Walk Forward Real
Walk Forward Sim
Annualized Return
26.07%
21.22%
18.46%
Win %
63.74%
71.43%
57.14%
Ave Trade
0.45%
0.62%
0.61%
Max Drawdown
-20.89%
-3.67%
-3.78%
Profit Factor
 2.12
3.00
2.52

The walk forward results compare pretty well to the backtested results. This isn't a 'double your money' system.  It is designed to get consistent results that beat the market, all while limiting drawdowns.  I would say the trades were in line with historical expectations.

Why were the real time walk forward results different from the simulated?

I think I got lucky here. I traded the system a little better than the simulation.  The sim results follow the system to a tee, with every trade entered and exited precisely according to the system rules.  Replicating these trades proved difficult at times for a variety of reasons.

-Price Slippage: This is an end-of-day system (EOD), so the majority of the trades were entered market or limit-on-close (MOC/LOC) through Interactive Brokers. Slippage here was usually 1 - 2 cents.  IB couldn't always get the exact closing price. There was some positive slippage, but mostly negative.  It was only a couple cents though, not a very big deal.

-Bad Signal: I'd check 20 minutes before closing; if it was a BUY or SELL, I'd enter the order accordingly.  Sometimes SPY would move in those last 20 minutes, negating the signal.

-Bad Data: I used Yahoo Finance for the signals because I could get delayed intra-day quotes from them.  Norgate only provides (very reliable) EOD data. Yahoo and Norgate didn't always have the same SPY data (dividend adjustments, bad ticks, whatever).  Sometimes the signals were early or late by a day.  The system design was based on data from Norgate, so the signals from them are the accurate ones.

-Random Distractions:
     -Internet down
     -Completely forgot to check the signal
     -Vacation
     -Other parts of life that get in the way
Even with perfect data and an accurate signal, I couldn't always be at the computer to enter the trade.

-Luck: If I missed a signal right at the market close, I would still enter the trade in the after hours, next day pre-market or next day open.  Prices were often favorable to me.  If a buy signal came, I could enter at better prices during the after hours because SPY was selling off.  And vise versa for sell signals.  I think it was just good fortune; prices could easily have gone against me.

Long vs Short

Longs performed better. This makes sense because we're in a bull market. The short trades actually were net losers.  I think some kind of market filter would be appropriate.  Adding a filter is a whole other project, but this is where system design leads you. You refine and adjust until you're comfortable and confident with your product.

Outliers?

None really. I had one trade that lasted longer than any backtested trade.  It just kept dragging out, although the drawdown was minimal. I wasn't sure if my data or scanning software had gone bad.  You begin to question things when the system does something for the first time.  Aside from that, everything went smoothly.

Only Six Months of Testing?

I know, it's not a long time.  I would need real time trading for multiple years through bull/bear and high/low volatility markets to gain supreme confidence in the system.  For my purposes, six months was long enough to 'get a feel'.  

Final Thoughts    

You can backtest and simulate all you want, but to truly get a feel for a system, you need trade it live.  There were times that I questioned the signals. For example: Why am I buying the SPY when Japan is on nuclear meltdown watch? The discretionary part of me would not take some of these trades.  But this a mechanical system; if a signal comes, take it.  Trust your rules.

I will still need refine this strategy but it was a valuable experiment for me.  It made some money and I was happy with how it performed.  For an off-the-cuff creation, no complaints.

Monday, July 11, 2011

Very High NYSE TRIN Readings: Bullish for SPY?



The NYSE TRIN closed at 5.37, which is ridiculously high.  In fact, it has closed above 5 only 12 other times since 1993.

Primer: The TRIN, or Arms index, incorporates up-volume and up-issues to down-volume and down-issues for the NYSE market. It is the ratio of advances to declines divided by the ratio of up-volume to down-volume and is calculated using the following formula:

TRIN = (# of advancing stocks / # of declining stocks) / (up-volume/down-volume)

When this indicator hits an extreme level, it can sometimes be a contrarian indicator on a short term time frame.  A TRIN above 5 has only happened a dozen times, so I wanted to broaden it out to a close above 3 in order to get a larger sample size.  My main curiosity is this: how does the SPY usually behave when the NYSE TRIN is above 3?

Data from Norgate. Tested in Amibroker. No commissions or slippage.

Buy SPY when NYSE TRIN > 3; sell 'n'days later. $10,000 per trade; 1993 to present.
Net Profit
# Trades
# of winners
% of Winners
Max. Trade % DD
Avg % P/L
W. Avg. Profit
L. Avg. Loss
Profit Factor
Payoff Ratio
1
         2,959
56
36
64.29
-7.42
0.53
          145
        (113)
2.30
1.28
2
         3,233
55
33
60.00
-9.33
0.59
          201
        (154)
1.95
1.30
3
         3,014
52
34
65.38
-11.53
0.58
          228
        (262)
1.64
0.87
4
         4,445
50
33
66.00
-11.53
0.89
          257
        (238)
2.10
1.08
5
         5,644
48
30
62.50
-11.53
1.18
          346
        (262)
2.19
1.32
6
         7,273
48
31
64.58
-11.53
1.52
          395
        (292)
2.46
1.35
7
         4,992
45
31
68.89
-11.53
1.11
          325
        (363)
1.98
0.90
8
         6,272
45
32
71.11
-11.53
1.39
          374
        (439)
2.10
0.85
9
         9,915
45
33
73.33
-11.53
2.20
          429
        (355)
3.33
1.21
10
         8,833
44
30
68.18
-19.61
2.01
          474
        (384)
2.64
1.23

This study is biased to bullish side. Looking 1 to 10 trading days out, this would be a high probability trade. Sure there is a nasty drawdown (2008 inflicted), but overall the numbers look positive. It's definitely not the only thing to consider, but it could add confirmation to other short term indicators a trader may have. For example, today was another 95% NYSE Down Day.  This is another way to view advancing/declining issues and up/down volume. It has also historically been a short-term bullish setup.

Good trading out there.

----------------------------------------------Random Tidbits----------------------------------------------------------

1.  Since 1993, 10 of the 12 times the TRIN closed above 5 occurred between 2007 and 2010. I'm not sure what this means, but I thought it was worth noting that this barely happened before 2007.

2.  Quick system based on TRIN above 3. Average hold is 3 days.

Buy SPY when NYSE TRIN > 3; sell on first higher close. $10,000 per trade; 1993 to present.
Exit n
 days
Net Profit
# Trades
# of winners
% of Winners
Max. Trade % DD
Avg % P/L
W. Avg. Profit
L. Avg. Loss
Profit Factor
Payoff Ratio
1
   4,373.10
53
41
77.36
-11.53
0.83
    145.13
   (131.42)
3.77
1.10

Tuesday, July 5, 2011

Amibroker Code: NYSE McClellan Oscillator

Below is the code I use to caclculate $NYMO in Amibroker. It is the ratio adjusted version described by Stockcharts.com.  This code will only work if your data provider has advancing and declining issues.  My data provider is Norgate, so if you are not using them, replace the #NYSEADV and #NYSEDEC with the appropriate symbols.


-------------------------------------------------------------------------------------------------------------------------
/*

McClellan Oscillator

*/

SetForeign("#NYSEADV");

adv = C;

RestorePriceArrays();



SetForeign("#NYSEDEC");

dec = C;

RestorePriceArrays();



Rana = (adv - dec)/(adv+dec);

NAMa = EMA( rana, 19 ) - EMA( rana, 39);

r =NAMa*1000;

Plot( NAMa*1000, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );

PlotOHLC( r,r,50,r, "", IIf( r > 50, colorRed, colorGreen ), styleCloud | styleClipMinMax, -70, 70 );

Plot(0, "0", colorWhite);



Saturday, July 2, 2011

What Happens to SPY When NYSE McClellan Oscillator is above 80?



The market has had a great run the last five days. Some would consider us short term overbought. One way to measure this is through the McClellan Oscillator.  It hit 89 on Friday, an extreme level. I wanted to test the short term returns of the SPY when this indicator hits 80.


Buy SPY when NYSE McClellan Oscillator is > 80; sell 'n'days later. $10,000 per trade; 1993 to present.
Net Profit
# Trades
# of winners
% of Winners
Max. Trade % DD
Avg % P/L
W. Avg. Profit
L. Avg. Loss
Profit Factor
Payoff Ratio
1
      (647.45)
16
5
31.25
-4.20
-0.40
    137.81
   (121.50)
0.52
1.13
2
   (1,488.59)
15
7
46.67
-9.51
-1.03
       89.58
   (264.45)
0.30
0.34
3
      (945.92)
12
4
33.33
-9.51
-0.80
    170.27
   (203.38)
0.42
0.84
4
      (667.25)
12
5
41.67
-9.51
-0.55
    172.05
   (218.21)
0.56
0.79
5
      (402.90)
12
8
66.67
-10.60
-0.31
    123.43
   (347.58)
0.71
0.36
6
      (805.53)
11
7
63.64
-14.53
-0.67
    110.96
   (395.57)
0.49
0.28
7
        (58.23)
11
7
63.64
-14.53
-0.02
    172.67
   (316.73)
0.95
0.55
8
      (491.37)
11
7
63.64
-14.53
-0.42
    196.21
   (466.21)
0.74
0.42
9
   (1,204.91)
10
5
50
-14.88
-1.22
    232.80
   (473.79)
0.49
0.49
10
   (1,109.48)
10
6
60
-14.88
-1.10
    198.38
   (574.94)
0.52
0.35
11
   (1,642.58)
10
5
50
-18.83
-1.70
    240.97
   (569.49)
0.42
0.42
12
   (2,532.35)
10
5
50
-24.86
-2.67
    272.31
   (778.78)
0.35
0.35
13
   (1,710.27)
9
4
44.44
-24.86
-1.93
    387.29
   (651.89)
0.48
0.59
14
   (1,439.37)
9
4
44.44
-24.86
-1.62
    379.69
   (591.63)
0.51
0.64
15
   (1,349.83)
9
4
44.44
-24.86
-1.54
    331.62
   (535.26)
0.50
0.62
16
      (910.64)
9
4
44.44
-24.86
-0.99
    336.85
   (451.60)
0.60
0.75
17
      (231.45)
9
5
55.56
-24.86
-0.15
    368.32
   (518.26)
0.89
0.71
18
   (1,249.87)
9
5
55.56
-24.86
-1.30
    391.61
   (801.98)
0.61
0.49
19
        251.40
8
5
62.5
-24.86
0.34
    424.09
   (623.02)
1.13
0.68
20
        160.85
8
4
50
-24.86
0.24
    474.43
   (434.22)
1.09
1.09

It hasn't happened all that much and it's not the most bullish thing in the world (on a short term basis).  A pullback or consolidation should be in order over the next week or two.  How the market responds to it will be very important.  It is interesting: when there is a strong market breadth thrust (as indicated by NYMO), it usually leads to overbought conditions.  Strong breadth may signal a new bull move, but the market often takes a breather right after it.  The last time it happened was 7/26/10; look at the SPY chart for that period and you'll know what I mean. That's all I have on the subject right now.

Good trading out there.