Monday 28 May 2012

Week of 2012 MA 25

SPY rose by 1.9% this week, while my account fell 1.5% to its lowest value ever.  I am once again out of the market, so my loss-floor is same as account-value.

Euro news: The “GrExit” is no longer unspeakable among Europe’s leaders.  Greece has announced that they will be unable to meet payroll after the end of June without another bailout, which they can’t get without an “austerity” government, which (polls say) the Greeks will not vote for.  The end seems nigh.

US news: Many pundits predict that next week will have the traditional ”Memorial Day bounce".  The US market seems decoupled from Europe, going up while Euro markets are falling.  This may continue for a few weeks—or the US market may crash later next week.  Hopefully my robot will catch the crash if it happens.

Thursday’s allocations:
Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
SRTY 1  MA16 +2.1 16  +0.9 16  +1.2 16  +0.9 +1.4%
SRTY 2  MA18 +1.2 15  -0.9 15  -0.6 15  -0.9 -0.3%
TZA  MA21 -0.8 13  -0.6 13  -0.9 13  -0.9 -0.7 -0.7 -0.7%
SRTY 3  MA21 -0.0 14  +0.2 14  -0.1 14  -0.2 14  -0.1 -0.4 -0.4 -0.1%
SRTY 4  MA23 -0.9 14  -1.0 14  +0.2 14  -1.2 -1.2 -0.8%
SPY +3.4 +5.2 +5.3 +5.4 +5.6 +5.3
me -6.0 -6.7 -6.8 -7.7 -7.5 -7.5
floor -6.0 -7.0 -6.8 -7.9 -7.5 -7.5

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA MA 14 11:00 MA 21 10:01 $20.58 $23.18 MA 21 15:00 MA 21 12:26 $21.94 $21.97 +1.0% -0.7%
SRTY 3 MA 21 12:00 MA 21 15:56 $55.97 $54.11 MA 22 10:00 $53.88 $53.94 -0.5% -0.1%
SRTY 4 MA 23 12:00 $57.40 $57.45 MA 24 10:00 $54.48 -0.7% -0.8%

TZA: What a horror story!  Last Sunday night, I put in a buy-stop order for TZA that would trigger if the market dropped to 0.5% below its 200-day moving average.  Also I resolved to get up early Monday morning and buy TNA if the market zoomed instead.  Well, Monday morning the market just sat there, hugging the 200-MA.  Eventually I got tired of waiting, convinced myself that the market looked like it was going down, and changed the buy-stop to a market order for TZA.  Immediately the market went up!  I bought at the worst price of the day!  Yet another reason why I use a trading robot, so I don’t have to make those real-time trading decisions.  Rule: don’t get up early.  It’s never worth it.
      To recap recent events: when the robot failed to buy SRTY a few weeks back, I put in a limit-order to buy if the model’s price showed up again—which it did, but the trade ended up being a small loss.  Then the robot failed to buy TZA, but I didn’t put in a limit-order even though the price did come back—and the trade would have been a medium-sized winner.  So this 2-item subset of trades shows the same “small losses, big gains” feature that we expect of all trades.  New rule: when the model says “buy” but the robot fails to buy, put in a limit-order to at least try to get the model’s price.

SRTY 3 : Because I was screwing around with the robot’s price-data, trying to make it match up with my manual TZA trade, I caused it to not buy SRTY at noon as it should have.  I ended up buying near the close for a better price — but still the trade ended as a small loser.

SRTY 4 : Normal trade, which happened to be a loser during a week that already had losses.

Custom indicator PEAKFREQ

I can haz nu indicator!

Let PEAKFREQ(n,size) be the number of peaks and troughs detected during the last n hours.  Detection uses Donchian channels: a “peak” is a rise in the upper CHAN(size) followed by a drop, while a “trough” is a fall in the lower CHAN(size) followed by a rise.

This indicator shows how “jittery” the market is.  If there are a lot of peaks and troughs per unit time, then the market is changing direction a lot these days.

The chart at right shows the last 140 hours of price action, with 8-hour channels.  The light blue arrows show when peaks and troughs are detected (which happens nine hours after they occur).  There are eight arrows shown and therefore PEAKFREQ(140,8) = 8 as of Friday’s close.

Here is a histogram showing the PEAKFREQ(140,8) values during the period 2008 through 2011 (excluding January 2008, to give the algorithm a running start).  There were 7,329 trading hours during this period.  About 14% of all hours had PEAKFREQ=13.  Only two(!) of all these hours had PEAKFREQ=6.  Only 0.6% of all hours had values below 8, so Friday’s close was a rather “calm” hour.

Adding a PEAKFREQ test helps my TNA and TZA models a lot!

MACD-based news trades

The SRTY model is a “news” trade in the sense that its typical hold time is hours-to-days, even though this is a quant model and doesn’t attempt to parse a news feed.

New rule: don’t buy SRTY if PEAKFREQ(140,8) < 8.  Although only 0.6% of hours have such low values, those trades are mostly losers, so skipping them raises the 2008..2011 return from 42.4% to 42.8% and improves the win:loss ratio from 93:104 to 81:88.  Yeah, it’s not much.  Then I retuned the model: only the SMA parameter changed (from 27 to 26), but that further increased returns to 43.2%.

PPO-based swing trades

%return, win:loss
TNATZA
Old model41.0%, 26:2253.9%, 25:20
add PEAKFREQ44.9%, 24:1556.0%, 22:11
retune52.4%, 29:1563.2%, 24:17

New rule: do not buy TNA or TZA if PEAKFREQ(140,8) > 11.  This removes 77% of all hours from consideration for purchase, while improving results noticeably.  Because PEAKFREQ eliminates so many bad hours, I was able to retune for best results on just the hours that remained.  After retuning, 66% of the TNA model’s trades are now winners (was 54%) while TZA now has 59% winning trades (was 56%).

In the new model, there are now no TNA trades at all for the first five months of 2012.

The PPO model is overcomplicated, but I can’t decide what to prune.  The most obvious candidates are the “alternate buy” and “alternate sell” rules, but the alt-buy rule is responsible for 13 %-points of profit during 2008..2011, while the alt-sell rule provides almost 5 %-points of the total 116% profit.  Anyway, here is the model-description, with highlighting for changes:

Bull swing (TNA) Bear swing (TZA)
Buy signal:
  • Time = 10am–3pm, on the hour
  • PEAKFREQ(140,8) ≤ 11
  • This hour’s price > previous hour’s price
  • This hour’s price > stop
  • This hour’s price > SMA(30)
  • This hour’s price > max of preceding 26 hours
  • PPO(8,71,1) < +1.8
  • PPO(8,71,12) > +0.4
  • PPO(8,71,12) has gone below -0.25 since last purchase
  • STDDEV(80) < its EMA(43)
  • Time = 11am–3pm, on the hour
  • PEAKFREQ(140,8) ≤ 11
  • This hour’s price < previous hour’s price
  • This hour’s price < stop
  • This hour’s price < SMA(75)
  • This hour’s price < min of preceding 34 hours
  • PPO(10,60,1) > -2.4
  • PPO(10,60,12) < -0.1
  • PPO(10,60,12) has gone above +0.28 since last purchase
  • STDDEV(29) < its EMA(25)
Alternate buy signal:
  • Time = 10am–3pm, on the hour
  • This hour’s price > SMA(30)
  • This hour’s PPO(8,71,12) minus its value from 35 hours ago > +2.6
  • It has been at least 6 hours since last sale.
  • Time = 11am–3pm, on the hour
  • This hour’s price < SMA(75)
  • This hour’s PPO(10,60,12) minus its value from 22 hours ago < -2.35
  • It has been at least 10 hours since last sale.
Buy-more signal:
  • Time = 10am–4pm, on the hour
  • Either
    • PPO(8,71,12) has risen by at least 0.02 during each of the last two hours
    • PPO(8,71,12) has changed by less than ±0.02 during the last hour and rose by at least 0.02 during each of the preceding two hours
  • PPO(8,71,12) fell by at least 0.02 during the two hours before that.
  • STDDEV(80) < its EMA(43)
  • Have bought 2 or fewer tranches so far
  • If signal received at 10am or 4pm, postpone purchase to 11am
  • Time = 10am–4pm, on the hour
  • Either
    • PPO(10,60,12) has fallen by at least 0.02 during each of the last two hours
    • PPO(10,60,12) has changed by less than ±0.02 during the last hour and fell  by at least 0.02 during each of the preceding two hours
  • PPO(10,60,12) rose by at least 0.02 during the two hours before that.
  • STDDEV(29) < its EMA(25)
  • Have bought 4 or fewer tranches so far
  • If signal received at 4pm, postpone purchase to 10am 10am or
Sell signal:
  • Time = 10am–3pm, on the hour
  • This hour’s price < previous hour’s price
  • This hour’s PPO(8,71,12) < -0.25
  • PPO(8,71,12) has gone above +0.4 since original purchase
  • Time = 11am–3pm, on the hour
  • This hour’s price > previous hour’s price
  • This hour’s PPO(10,60,12) > +0.28
  • PPO(10,60,12) has gone below -0.1 since original purchase
Alternate sell signal:
  • Time = 10am–3pm, on the hour
  • This hour’s PPO(8,71,12) minus its value from 35 hours ago < -2.7
  • It has been at least 6 hours since last purchase.
  • Time = 11am–3pm, on the hour
  • This hour’s PPO(10,60,12) minus its value from 22 hours ago > +0.6
  • It has been at least 10 hours since last purchase.
Stop update:
  • Time = 10am
  • Calculate new stop = lowest price seen in preceding 22 hours.
  • Raise new stop to  94.5% of the highest price seen in preceding 22 hours, if less than that
  • If I don’t currently own TNA, replace stop with the newly-calculated value.  Otherwise:
    • Discard new stop (and keep the old one) if the new value is lower
    • Sell now if lowest price of last 22 hours occurred during the last hour
    • Otherwise, convert the IWM-based stop to the corresponding TNA price and update the standing stop-order at Schwab
  • Time = 10am
  • Calculate new stop = highest price seen in preceding 22 hours.
  • Lower new stop to 104.6% of the lowest price seen in preceding 22 hours, if greater than that
  • If I don’t currently own TZA, replace stop with the newly-calculated value.  Otherwise:
    • Discard new stop (and keep the old one) if the new value is higher
    • Sell now if highest price of last 22 hours occurred during the last hour
    • Otherwise, convert the IWM-based stop to the corresponding TZA price and update the standing stop-order at Schwab

TRIX-based trend trades

No change.  It turns out that the URTY model only ever triggers when PEAKFREQ has a middling value, so there is nothing to gain from adding an explicit test.

For almost three months now, the robot has woken up every hour and calculated whether to buy URTY.  Every single hour, the answer has been “No.”  This model typically triggers about six times per year, so clearly we are going through a dry spell.

Summary of changes to trading performance

In this version of the chart, the left column for each quarter shows the results using the models as of March 31st (but excluding URTY) and the right column shows results using the latest model as above.  For the 2012 quarters there is a third column showing actual results.

So far, Q1 and Q2 of 2012 look only a little worse than Q4 2010 and Q1 2011.


No comments:

Post a Comment