Friday, 27 April 2012

Week of 2012 AL 27

SPY rose by 2.0% this week, while my account fell by 1.5% to its lowest value ever.  My loss floor dropped by 3.5%.

US market news: Tuesday night, Apple released their earnings, which were very good indeed.  Wednesday morning: the market zoomed!  Thursday night, Amazon released their earnings, which were pretty good.  Friday morning the market dropped, then recovered.  I expect continued upward momentum next week, because Apple is basically driving the entire US market these days and typically the post-earnings euphoria lasts 8‒10 days.

Thursday’s cash allocation:
Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TNA#0  AL17 -3.7  14 -7.5  14 -5.5  0 -6.0%
TZA  AL23 -1.3  15 -3.4  14 -7.9  14 -10.7  13 -12.9  13 -9.8 -9.8 -9.9%
SRTY  AL23 -1.3  15 -3.4  14 -8.1  14 -10.5  14 -12.8  0 -9.9 -9.9 -3.1%
TNA#1  AL26 +1.0  15 +3.6  15 -11.4 -9.3
SPY +9.9 +9.0 +9.4 +10.9 +11.7 +11.9
me -4.8 -5.2 -5.9 -6.5 -6.7 -6.3
floor -4.8 -7.9 -6.8 -6.8 -8.6 -8.3

This week I had my fifth and sixth losses in a row!  I am really getting tired of all these losses.  When will the market make up its mind whether it’s going up or down?  Typically, April or May is supposed to be an intermediate top, followed by lower prices for the summer; but this has been true for only four out of the last ten years.

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA AL 23 10:00 AL 23 13:00 $20.34 $20.16 AL 25 10:00 AL 26 12:11 $18.60 $18.20 -1.3% -1.5%
SRTY AL 23 12:00 AL 23 13:00 $10.05 $10.04 AL 24 11:00 $9.76 $9.74 -0.4% -0.5%
TNA#1 AL 26 12:00 $58.55 $58.51 (Not yet)

SRTY: First trade using the new model was a loser.

The robot trader did not work well this week:
      Monday: Both TZA and SRTY models triggered Monday morning.  Due to a bug introduced last weekend, the robot didn’t actually buy anything, so I bought manually several hours later (and for better prices, as it happened).  I also set the stop-orders manually—but for the wrong prices!
      Tuesday: Automatic stop-update didn’t work, due to a different bug introduced last weekend.  Since it looked like the stop prices shouldn’t actually change today, I didn’t bother rerunning the code after fixing the bug, so once again I didn’t notice that Monday’s stop prices were wrong.
      Wednesday: TZA was supposed to stop out around 9:40am or so, but that didn't happen because I had used 29 hours instead of 15 for Monday’s stop-setting and then Tuesday's update didn't happen.
      Thursday: The TZA stop was at $18.20.  Price got down to to $18.24 at 10:07am; $18.23 at 10:18 and again at 10:49; $18.22 at 11:29 and again at 11:37; finally hit $18.20 at 12:11pm.  Meanwhile, the robot bought TNA at noon, so for 11 minutes I owned two opposing bets that cancelled each other out.
      Friday: Automatic stop-update was successful, but didn't reduce my risk much.  Monday morning’s update is predicted to be a big step up, to -3.1% max loss for TNA.  In the best case, the stop price could be above break-even by next Thursday.

Saturday, 21 April 2012

Week of 2012 AL 20

SPY rose by 0.6% this week, while my account (and loss floor) fell 0.9% to their lowest values ever.

Daily % gain
size
Max lossFinal Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TZA  AL04 +1.3  29 +0.9  29 -3.8  0 -0.8%
TNA  AL17 -1.0  15 -3.6  14 -5.3  14 -3.7  14 -8.2 -8.4 -6.0%
SPY +9.3 +9.2 +10.8 +10.4 +9.7 +9.9
me -3.9 -3.9 -4.1 -4.5 -4.8 -4.8
floor -3.9 -3.9 -5.2 -5.2 -4.8 -4.8

TNA: Thursday’s IWM-stop update was “no change”, but there was some wobble in the IWMTNA price conversion, so the max-loss value went down slightly.  Previously I had a TZA stop go up slightly under similar conditions.  This is just something to put with in the current design.

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TNA AL 17 11:00 $57.96 $58.15 AL 19 15:00 $54.75 $54.76 -0.8% -0.9%

TNA: Rats!  Fourth loss in a row.  Paid too much on Tuesday, then got very little extra on Thursday, so actual loss ends up 0.1 %-points larger than model.

New rule: When calculating the daily stop, if the lowest price for the last N hours was during the latest hour, then sell immediately rather than raising the stop.  This improves average profit slightly, but more importantly it avoids a potential glitch: suppose the stock is in free-fall, so the current price is the lowest price.  Seconds later the robot tries to set that price as the stop, but the stock has since fallen further and so Schwab rejects the stop-order because it’s already underwater.

Bugfix: The models were not calculating their gains properly.  Basically, they were adding the transaction cost instead of subtracting it.  This is presumably why the last few trades had mismatches between model-profit and actual-profit.  This bugfix reduced apparent profit for 2008…2011 by several percent—but now it’s more realistic.

New trading model

I can haz nu model!  The design target for this model was to catch short downswings like the one that happened last week.  Also, this model avoids real-valued parameters, using moving averages and channels instead.  Because the absolute values of the indicators do not matter, I can use good ol’ MACD instead of PPO.

This is a short-selling model, meaning that I want IWM’s price to go down during the trade.  The “buy” and “sell” actions refer to SRTY, which (like TZA) is a 3× leveraged inverse ETF that tracks the Russell 2000 basket of stocks.

This model has no “buy more” signal.  Only a single tranche is ever purchased.

Buy signal:
  • Time = 10am–3pm, on the hour.
  • This hour’s price is below stop.
  • This hour’s price < SMA( 27 ).
  • Previous hour’s price < SMA( 27 ).
  • MACD( 15, 66, 9 ) < 0.0
  • MACD( 4, 16, 4 ) < its high over the previous 12 hours.
  • MACD( 4, 16, 4 ) > its low  over the previous 12 hours.
  • STDDEV( 7 ) > its EMA( 8 ).
  • I don’t currently own URTY, whose “buy” signal is a strong contrary indicator for SRTY.
  • When buying, lower stop to be no more than 2.7% higher than this hour’s price.
Sell signal:
  • Time = 10am–3pm, on the hour.
  • Either:
    • This hour’s price > SMA( 27 ).
    • MACD( 4, 16, 4 ) > its high over the previous 12 hours.
Stop update:
  • Time = 10am.
  • Calculate new stop = highest price seen in preceding 15 hours.
  • Replace stop with the newly-calculated value, unless I currently own SRTY and the new value is higher than the current one.
  • If the highest price of the last 15 hours was during the last hour, this is a “sell” signal.  Otherwise, if I currently own SRTY, convert this IWM stop to the equivalent SRTY price and update the standing sell-stop order at Schwab.

Below is a chart showing how this model would have behaved over the last four weeeks.  There were three losses and one gain, adding up to -0.1%.  Without the STDDEV requirement, the model would have bought on AL 05 instead of AL 09, for a much bigger gain and overall a profitable month.  But STDDEV is very useful: when volatility is low, most swing trades are losers.  Without it, this model would have a win:loss ratio of 114:189; with STDDEV, it’s 100:116 and the 30% profit over four years is increased to 40%.  But not so hot this month.

Summary of models

Hypothetical Historical Returns
Quarter   TNA TZA URTY SRTY  
qtr
—Total—
yr
2008 Q1 3.2% 0.5% 0.0% 1.7% 5.4% 53.3%
Q2 -2.0% -0.9% 1.1% 0.0% -1.8%  
Q3 2.8% -0.2% 5.4% 2.4% 10.4%
Q4 4.9% 15.5% 3.8% 15.1% 39.3%
2009 Q1 8.6% 4.0% 1.2% 10.3% 24.1% 59.8%
Q2 -1.5% -1.6% 21.6% -1.3% 17.2%  
Q3 7.9% 1.7% -2.0% -0.4% 7.2%
Q4 -0.2% 4.3% 4.5% 2.7% 11.3%
2010 Q1 4.0% -0.8% 0.0% -1.1% 2.1% 45.7%
Q2 -1.9% 8.0% 13.2% 4.0% 23.3%  
Q3 -1.3% 5.4% -0.6% 1.9% 5.4%
Q4 0.2% -1.2% 16.7% -0.8% 14.9%
2011 Q1 0.6% 0.9% -0.5% -1.0% 0.0% 55.4%
Q2 4.8% -1.2% -1.0% 0.2% 2.8%  
Q3 3.9% 24.2% 0.8% 6.5% 35.4%
Q4 2.3% -0.7% 3.1% 1.8% 6.5%
2012 Q1 0.4% -1.7% 12.9% -0.9% 10.7%
Total 36.7% 56.2% 80.2% 41.1% 212.8%

The robot is now using four trading models, identified here by the ticker-symbols they are supposed to trade.  These hypothetical historical returns look great on paper!  I would very much like to be making 45%‒60% per year.

In reality, I did not get the 10.7% profit shown here for 2012 Q1.  Instead, I lost 3.7% because the URTY and SRTY models hadn't been invented yet, the TNA model was improved after the fact, and I made a loser RWM trade that wasn’t justified by any model.

Below is a chart showing weekly results for all models simultaneously.  Of the 221 weeks, there are 84 losses, 41 zeroes, and 96 gains.  Any week with a gain of less than 2.7% is just paying back for the weeks with losses.  About 12% of all weeks have larger gains than that and thus are making actual progress.

Note that 2012 Q1 was a bad quarter with no large gains, except for URTY which I couldn’t actually trade because the model didn't exist yet.


Friday, 13 April 2012

Week of 2012 AL 13

SPY fell by 2.1% this week, while my account fell 0.2% to its lowest value ever.  Just can’t catch a break!  The loss floor rose by 1.1% since I am out of the market again.

Daily % gain
size
Max lossFinal
Gain
Sym  Buy Thu Mon Tue Wed Thu Fri Beg   End
 
TZA  AL04 -0.2  14 +4.7  15 +6.5  30 +2.2  29 -2.6  29 +1.3  29 -8.9 -0.7 -0.8%
SPY +11.4 +10.1 +8.3 +9.3 +10.6 +9.3
me -3.7 -2.9 -1.6 -3.0 -3.9 -3.9
floor -5.0 -4.3 -6.1 -4.4 -3.9 -3.9

MACD-based swing trades

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA AL 04 11:00 $18.54 $18.46 AL 12 11:00 AL 12 10:33 $19.31 $19.30 -0.1% -0.2%
AL 10 12:00 $20.49 $20.50

TZA: This was a stop-out, which actually happened at 10:33am but the model didn’t take notice until 11am.  Buy-price for 1st tranche was better than expected, while the 2nd buy-price and the sell-price were almost on the nose, so why the 0.1% difference in expected profit?  This needs investigation.

New rule: Allow TZA trades at 10am; con­tinue prohi­biting TNA trades at 10am because they would hurt performance.  Under this new rule, TZA would have been sold at 10am on AL 12 (because PPO was so high) rather than setting a stop which then triggered 30 minutes later for a 0.1% bigger loss.

This chart makes it look like I have gone too far in the “minimize risk” direction.  For the No 10am case, everything within the range -2.0% to +2.0% is “churn” and adds up to nothing; only the larger gains contribute to profit. Thus, only 6 of 65 trades are worthwhile!  For the With 10am case, 5 of 71 trades are worthwhile.  This is not good enough.  I do not want a 93% chance of “waste of time” each time the robot opens a trade!

Thursday, 5 April 2012

Week of 2012 AL 05

SPY fell by 0.8% this week, while my account was un­changed.  The loss floor dropped by 1.3% to make room for my new trade.

US markets are closed tomorrow for Good Friday.

Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TNA  MR26 -5.0  13 -1.6  0 -3.3%
TZA  AL04       -1.4  14 -0.2  14   -9.2 -8.9
SPY +12.2 +13.0 +12.6 +11.4 +11.4
me -3.7 -3.7 -3.7 -3.9 -3.7
floor -3.7 -3.7 -3.7 -5.1 -5.0

TZA: I didn’t have a lot of faith in this trade, but that’s why I use a trading robot.  All I need is faith in the general system; the individual trades are automated.

The daily stop-setting system works!  On Friday it raised my stop on TZA, even though the IWM stop-price didn’t change, due to random fluctuation in the IWM/TZA ratio (which could perhaps have gone 0.3% in the other direction).  Unless something bad happens Monday morning, I expect that the 10am recalc will raise the TZA stop to somewhere in the neighbourhood of -3.6%.

MACD-based swing trades

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA AL 04 11:00 $18.54 $18.46 (not yet)

TZA: PPO(10,60,12) was rising very slowly Thursday afternoon, until the close when it rose by +0.032.  I require two hours of +0.03 or more in order to trigger a buy-more, so the market needs to rise for at least the first ½ hour Monday morning before plunging or I’ll have to make do with this single tranche.  If the market zooms instead of plunging, the single tranche loss won’t hurt me too much.

TRIX-based trend trades

The trap is set, but has not yet sprung.  TRIX(176,16) peaked at -0.0003 on Tuesday, now it’s back down to -0.0005.  I need +0.00011 to trigger a ”buy”.

This seems to happen over and over: as soon as I put in a recognizer for a price-pattern, that pattern stops happening for weeks or months.  I suspect that this is not a coincidence.  Patterns vary in their obviousness, probably in a way similar to stock prices.  When a pattern becomes so obvious that I notice it and write a recognizer for it, that might indicate that the pattern-obviousness level is approaching a “blow-off top”.  After the blow-off, the pattern recedes for a while and so my recognizer has nothing to recognize.

Surfing the oscillations

In early March, IWM broke its October-November trendline.  It quickly recovered and spent the rest of the month hovering around that line.  Now, in early April, it has broken the new trendline for October-March.  There’s no way to know yet how soon it will recover.  This could be the start of THE BIG ONE, but probably not.