Saturday, 30 June 2012

Week of 2012 JN 29

SPY rose by 2.2% this week, while my account rose 1.7% and erased its last month of losses.  The loss-floor has risen to -9.7%.

Euro news: At this week’s summit, nothing of substance was definitely decided, but in the background there were several mega-purchases on stock markets.  For example, on Thursday at 3:30pm there was a single trade on the S&P 500 futures market whose notional value was $3 billion.  Somebody with a large credit line wanted to be *seen* propping up the stock market!  If the buyer used newly-printed money from a central bank, then this trade was inflationary—especially if they have to do it again next week to continue postponing the crash.  Goldman Sachs has suggested that $50 billion of inflationary stock purchases would be needed every month just to maintain the status quo.

Friday’s allocations:
Daily % gain
size
Max loss
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TZA  JN21 -0.5  15  +0.2  16  +0.0  15  -0.2  15  -0.2  15  -0.2  15 -1.3 -1.3
URTY  JN22 +0.2  15  -0.4  15  -0.3  15  +0.3  16  +0.3  16  +1.4  17 -1.3 -1.0
TNA  JN29 +0.2  15 -1.9 -1.9
SPY +6.3 +4.6 +5.2 +6.1 +5.8 +8.5
me -9.2 -9.2 -9.2 -8.8 -8.9 -7.5
floor -11.5 -11.5 -11.3 -10.2 -10.1 -9.7

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActual M AMA
TZA  (Do not buy)  JN 21 14:04 $20.73 JN 27 10:00 $20.49 0.0% -0.2%
URTY JN 22 11:00 $53.93 JN 29 13:00 $59.45 +1.2% +1.4%
TNA JN 29 11:00 $52.88 $52.86 (Not yet)

TZA: Never did get a “buy” signal for this.  In my records I recorded that at JN 26 13:10, I had a hunch that this thing should be sold.  Price would have been $20.90, for a +0.1% overall profit instead of the -0.2% loss that the robot got via its “alternate sell rule”.  I am pleased that my hunches were correct twice in a row (also for TNA last week), but for now I think I’ll just paper-trade my hunches and use the robot for real-money trades.

URTY: First URTY trade is a winner!  Because URTY has such low volume, I got exactly the expected prices—but my profit was greater than expected because URTY actually does better than 3× IWM over short periods.

TNA: Normal trade in progress.  The max-loss is uncomfortably large due to the recent run-up.  The market will have to stay “up” until Wednesday before there will be a big improvement in the max-loss.

Stop updates: Monday’s update failed due to Schwab changing their login-code; apparently this was a momentary self-correcting glitch?  Thankfully, this failure prevented the robot from making an erroneous SRTY purchase due to a bug (holding URTY did not prevent SRTY purchases at 10am, only at other times).  Bug has been fixed.  The rest of the week’s stop-updates were successful.

Gold trading

I have heard that, win or lose, President Obama will have to devalue the US$ by about 20% after the election, to ensure that the USA can continue as a going concern.  Of course I should buy gold *before* the devaluation, but when?  The obvious choice is “just before the election” but maybe somewhat earlier would be better.

Here is my new model:
Using weekly indicators for IAU.
Buy signal:
  • Time = Friday at 4pm (after-hours trade).
  • MACD(14,25,9) is greater than 0.
  • MACD(14,25,9) has been less than 0 since last sale.
Sell signal:
  • Time = whenever US markets are open.
  • Current price < 90% of highest price seen since purchase.

The 10% trailing stop seems a bit much.  Previously I had determined that 5½% is enough to hang on during a parabolic uptrend, but more is needed to stay on during sideways periods between uptrends.  This model could probably generate much more profit with some additional tweaking.

Because this is a weekly model, I will run it manually rather than installing it into the robot.  This allows me to buy after Friday’s close and to use real-time trailing stops, which the robot cannot do.  I can use my automatic downloader for Yahoo quotes rather than the manual system for fetching from stockcharts.com.  Two problems:
      Splits:  In general, for purest MACD calculations, I want data that has been adjusted for splits, but not for dividends; Yahoo offers either both these adjustments or neither.  So my downloader selects “neither”, but then I had to manually adjust the data for the 10:1 split in IAU that happened in 2010.  If I start using more non-hourly models then something should be done to improve the Yahoo-quotes downloader.
      Limited archives:  Stockcharts has data for IAU going back to 1990, while Yahoo has only back to 2005.  Because weekly MACD needs about two years to ramp up to speed, this means I can backtest only to about 2007 or so.

This model trades very rarely, about once per year.  Here are all trades for the last 5½ years:
BuySellProfit
2007 JA 192008 MR 20+6.5%
2008 DE 122009 MR 03+1.5%
2009 MA 222009 DE 17+2.1%
2010 AR 302011 AU 25+6.7%
2012 FE 242012 AR 04-1.4%

This is only about 2.8% profit per year because the tranche size is only ⅟₇ of my account and IAU is not leveraged.  Maybe, if an IAU trade is in progress in late October, I’ll dump my remaining cash into it to jack up the profits (if any) from the devaluation (if it happens).

Some people think that IAU is not a good investment because it is “paper gold”.  I think paper gold is safer than physical gold, in the case where the US government confiscates all physical gold again (like in 1933).  For IAU they would just replace my gold shares with dollars; for physical gold, if I were the last recorded receiver of a nugget, they would dig up my yard looking for it.  I don’t think the fact that my yard is actually in Canada would necessarily stop them, if they are desperate enough to try a gold confiscation.

Currently, the weekly MACD for gold is quite negative.  I don’t expect a “buy” signal for at least a month.

Monday, 25 June 2012

Week of 2012 JN 22

SPY fell by 0.6% this week, while my account fell 0.3%.  The loss-floor has dropped to -11.5%, so I have lowered the bottom of the chart.

US news: On Wednesday, the Federal Reserve behaved sensibly and did not announce a new money-printing program.

Euro news: All major ratings agencies have now downgraded Spanish government debt, so by law the ECB was supposed to require more collateral from Spanish banks – but they don’t have any more!  So the law was changed to ignore the ratings agencies; banks can now deposit any random piece of paper with “I.O.U.” written on it and withdraw fresh euros from the ECB.  This is inflationary.  I predict a rising US stock market and — in a few months — food riots in some country someplace (was Algeria for QE2).

Friday’s allocations:
Daily % gain
size
Max loss
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
SRTY ¹  JN13 -0.3  15 -0.3  15 -0.3  0
RWM  JN15 -0.1  15 -0.1  15 -0.4  15 -0.4  15 -0.0  15 -0.1  15 -0.7 -0.7
TNA  JN15 +0.0  15 +0.1  15 +0.8  16 +0.8  16 +0.0  15 +0.0  15 -1.3 -0.4
SRTY ²  JN21 +0.0  15 -0.1  15 -1.2 -1.2
TZA  JN21 +0.0  15 -0.5  15 -1.2 -1.3
URTY  JN22 +0.2  15 -1.3 -1.3
SPY +6.9 +7.1 +8.1 +8.0 +5.5 +6.3
me -8.9 -8.8 -8.3 -8.4 -8.7 -9.2
floor -10.8 -10.6 -10.6 -10.1 -11.8 -11.5

RWM: Non-robot trade.  I lost interest in it after URTY got its “buy” signal.  Didn’t sell on Wednesday because QE3 wasn’t announced, but the new European money-printing program amounts to the same thing.
      It was nice having this at the beginning of the week, as a hedge for TNA.  Whatever happened on the market, I owned *something* that was going up!  Going into this weekend, I own equal amounts of TZA and URTY which cancel each other out, so my account balance will not change until I decide to sell one of them.

cash: I am down to 1% cash.  If the robot were to buy another tranche of TZA on Monday, that would be using “unsettled funds” and I couldn’t sell those shares until Tuesday.  This would *probably* work out but I have decided instead to disable the “buy more” function in the robot until the TNA sale settles on Tuesday.

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TNA JN 15 15:00 $48.64 $48.65 JN 21 12:00 JN 21 12:21 $49.36 $48.82 +0.2% +0.0%
SRTY ² JN 21 14:00 $51.71 $51.75 JN 22 10:00 JN 22 10:47 $51.35 $51.49 -0.1%
TZA (Not yet) JN 21 14:04 $20.73 (Not yet)
URTY JN 22 11:00 $53.93 (Not yet)

TNA: Misread the chart and thought it was supposed to be sold at 11am (and I would have exited with +0.5% profit if I had listened to my Spidey Sense and just dumped it at 11am).  I noticed that the robot’s price-quote for 10am was way off and assumed that this was another case like May 14th where a wrong real-time quote prevented a trade.  Because I was screwing around with limit-orders, the correct sale at 12pm didn’t happen, either.  Clearly, I have lost faith in the current system and it needs repair.

SRTY ²: At 10am on Friday, the robot was supposed to update the stop for TZA and then sell SRTY, but the sale didn’t happen.  I’ve had this experience before — this time I figured out what the problem is: in shell-script, variables have global scope by default.  The code for “adjust stop price” was using the same variable-name as the main loop, so after a stop-adjustment all remaining queued operations would be skipped.  Fixed.

TZA: I guess I got override-happy.  The model did not call for a purchase because IWM’s price at 2pm was lower than the closing prices for only the preceding 29 hours, while my model calls for 32 hours of preceding lower prices for a “buy” signal.  It doesn’t make much difference: during 2008..2011 the overall TZA profit would have been only 2 %-points lower using 29 hours instead of 32 hours.  The model might yet issue a “buy” signal on Monday.  In the meantime, I have added a special rule to the robot: “If the simulated time is 2012-06-21 14:00 then buy TZA”.  This way the robot realizes that I am currently holding TZA, so it updates the stop, looks for a “sell” signal, etc.
      My manually-chosen stop was slightly too high, so the robot lowered it at the 10am adjustment on Friday.

URTY: Normal trade in progress.  First activation of the URTY model!

TRIX-based trend trades

Finally got a “buy” signal!  And it only took 436 hours of trying!  According to the back-tests, if an URTY trade isn’t going to work out, it will usually close at a loss within a week, while sucessful trades often run for over a month.

Germany has ordered the ECB not to reduce its collateral requirements, but if the ECB doesn’t print then a Spanish banking collapse may be imminent, so the ECB might well disobey orders, which could possibly cause Germany to leave the Euro, which could lead to hyperinflation in the remaining Eurozone countries.  Of course, the connection between European politics and the URTY model is tenuous at best.

MACD-based news trades

This model is currently disabled because I am holding URTY, which prevents any “buy” signals for SRTY.

PPO-based swing trades

I have changed all four rules of the form “This hour’s price > previous hour’s price” to instead use “99.9% of previous hour’s price”.  This makes the glitch less likely, but still the model and robot can disagree because the model uses top-of-hour prices while the robot uses prices from several seconds later.  A better fix would be to fetch top-of-hour prices, such as from Schwab’s “charts” module, but parsing these looks difficult — it seems they have deliberately obfuscated this data.

Sunday, 17 June 2012

Week of 2012 JN 15

SPY rose by 0.8% this week, while my account fell 0.5% to its lowest value ever.  The loss-floor has fallen to -10.8%.

World news: Crown Prince Nayef of Saudi Arabia has died.  My pet theory is that this will have a much larger effect on world affairs than the elections in Greece.  None of Nayef’s obituaries discuss his position as a kingpin among the world’s crony capitalists.  His expected replacement, Prince Salman, is a very different man.

Euro news: The lying is nearing a crescendo.  The BBC reports that Spain “was given” a bailout.  Oh yeah?  They got *promises* of a bailout.  You can’t eat promises.

US news: Next Wednesday, the Federal Reserve will announce its policy for the next two months.  Far too many people have written that it is “almost certain” that they will announce a new money-printing program (QE3).  I think this is absurd.  Printing money now will cause a spike in the price of food, which could start another Arab Spring, which Saudi Arabia cannot afford during their line-of-succession difficulties.  Hopefully the Fed will put this off until August, which will cause large numbers of traders to be sorely disappointed next week.

Friday’s allocations:
Daily % gain
size
Max loss
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
SRTY ¹  JN12 -0.1 15  -0.1  15 -0.1  15 -0.1  0 -1.0 -1.0
SRTY ²  JN13 +0.1  15 -0.3 15  -0.3  15 -1.1 -1.1
RWM  JN15 -0.1  15 -0.7 -0.7
TNA  JN15 +0.0  15 -1.3 -1.3
SPY +6.1 +4.7 +5.9 +5.2 +6.4 +6.9
me -8.4 -8.4 -8.5 -8.4 -8.8 -8.9
floor -8.4 -8.4 -8.5 -9.7 -8.8 -10.8

New this week: the daily-gains table no longer has a “Final Gain” column.  Instead, when a security is sold, its daily gain is red for one day and then freezes for three days until the trade settles and the size goes to 0%.

RWM: Non-robot trade.  Obviously the market is going down, so I might as well bet against it.  Sell if QE3 is announced, or hold until the crash (with 5% trailing stop to catch the bottom).  RWM is a 1× bear, while TNA is 3× bull, so for now I am net 30% long.  My guess is that the market will be down on Monday, up on Tuesday, stable on Wednesday if “Operation Twist 2” is announced, then begin its decline.

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
SRTY ¹ JN 12 11:00 JN 12 11:06 $55.49 $54.77 JN 13 14:00 JN 13 14:12 $54.27 $54.34 -0.3% -0.1%
SRTY ² JN 13 15:00 $54.51 $54.41 JN 14 14:00 $53.38 $53.42 -0.3%
TNA JN 15 15:00 $48.64 $48.65 (Not yet)

SRTY ¹: Tuesday's buy-order did not go through because Schwab reformatted their website again.  Entered manually.  Sell-order didn't work either, so entered manually as well.  Adjusted the robot code.

SRTY ²: Wednesday's buy-order went through, but not the sell-stop order.  Entered manually.  More robot code adjustments.

TNA: Robot is now working properly again.

Surfing the Oscillations

The robot has lost money for every month of its existence.  MarketSniper explains why: in their desperation to avoid the next crash, the central banksters are now intervening in the markets almost continuously, breaking up even the hourly patterns that my robot is looking for.  We’ve seen this script before.  Remember “Baghdad Bob” announcing that the Yankees have been defeated, while US tanks roll down the street behind him?  Increasingly I see the words “end game” being used to describe the Euro situation (and by extension the US situation).  The game actually ended about two years ago.  Wile E. Coyote is off the cliff, hovering in thin air, refusing to admit that he is actually falling.  Eventually he will hit the ground and the illusion will shatter.  Hopefully my robot will catch the crash and make lots of money, but as of yet there is no evidence that it will actually work.

Last year, the TNA and TZA models would have lost money in the first half, then made it all back and more in the second half.  We shall see how 2012 turns out.

Friday, 8 June 2012

Week of 2012 JN 08

SPY rose by 4.0% this week, while my account fell 0.3%.  My loss-floor rose because I am out of the market again.

Friday’s allocations:
Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TNA  MA29 -3.5 29  -3.6 29  -2.7 -1.6%
SRTY  MA30 +1.4 15  +1.4 15  +0.9 +0.2%
TZA  MA30 +0.7 16  +0.8 16  +0.2 16  -0.8 16  -0.6 16  -1.1 -1.4 -0.8 +0.5%
SPY +2.1 +2.1 +2.8 +5.2 +5.2 +6.1
me -8.1 -8.1 -8.4 -8.4 -8.4 -8.4
floor -10.3 -10.0 -8.4 -8.4 -8.4 -8.4

TZA: Sold for 0.2% less than last Friday’s estimate, but account value went down by 0.3% for the week.  Some sort of round-off error.

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA MA 31 11:00 $22.56 $22.60 JN 05 13:00 $23.39 $23.42 +0.6% +0.5%

TZA: Sold Tuesday using the "Alternate sell rule”.  Spent the rest of Tuesday cursing that damned rule.  Wednesday morning the market jumped, so would have sold TZA for a loss at the 10am stop-update.  Hooray for the alternate sell rule!

Custom indicator PEAKFREQ

As of Friday’s close, PEAKFREQ(140,8) = 7, so the SRTY model is disabled but the other models remain on duty, waiting for “buy” signals.

On Thursday, PEAKFREQ got down to 6, so I tried to recreate the previous histogram which showed only two hours of the last 7,000 that had such a low value.  But the numbers are all different on my re-creation!  Something went wrong last time.  Here is the revised chart, showing 6,895 hours from February 2008 through December 2011.  There were only 10 hours during 2008..2011 where PEAKFREQ=4 and only 4 hours with PEAKFREQ=16.  About 13% of all hours have PEAKFREQ<8 (which blocks purchases of SRTY), while 24% of all hours have PEAKFREQ>11 (which blocks TNA and TZA).


Sunday, 3 June 2012

Week of 2012 JN 01

SPY fell by 3.2% this week, while my account fell 0.6% to its lowest value ever.  My loss-floor has fallen to -10.3%, but is expected to rise to perhaps -9.8% on Monday morning.

Euro news: The government of Spain has announced that they can continue as a going concern until October, but it has become increasingly apparent that Spain is lying its collective head off, so presumably their actual financial condition is dire.

US news: Friday’s non-farm payroll report was awful, so President Obama went on TV to reassure the public.  As usual, the market fell after the Obama speech.  The S&P 500 pierced its 200-day moving average, so I expect at least a one-day bounce next Monday, which hopefully will cause my robot to double-down on its bearish bet.

The last five months have been a nightmare for my trading system.  The market goes up, I lose money; the market goes down, I lose more money.  Some stock trader I am!  For reassurance, I look to the back-tests for last August.  If I had been using my latest TZA model last year, there would have been four losses in a row from April through July, totalling -2%, before the +19% win in August.  For TNA the results were more mixed: if somehow I had failed to get the +5.7% win in July, then results for April through July would have been -0.6%.  So there would have, could have, should have been several months in a row of “I just can’t win!”, followed by a big win.

On Monday, US markets were closed for Memorial Day.  The “post Memorial Day bounce” lasted all of one day.

Friday’s allocations:
Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
SRTY 1  MA23 -1.0 14  -1.5 14  -0.8 -0.8%
TNA  MA29 -0.0 15  -0.9 30  -1.1 29  -3.5 29  -1.6 -1.6 -1.6%
SRTY 2  MA30 +0.0 15  +0.1 16  +1.4 15  -0.9 -1.0 +0.2%
TZA  MA30 -0.5 15  +0.7 16  -1.5 -1.4
SPY +5.3 +6.5 +5.0 +4.8 +2.1
me -7.5 -7.5 -8.4 -9.3 -8.1
floor -7.5 -9.2 -10.0 -10.4 -10.3

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TNA MA 29 11:00 $50.48 $50.45 MA 31 10:00 MA 31 09:49 $46.42 $46.40 -1.6%
MA 30 11:00 $47.79 $47.81
SRTY 2 MA 30 13:00 $53.98 MA 31 15:00 $54.84 $54.87 +0.2%
TZA MA 31 11:00 $22.56 $22.60 (Not yet)

TNA: Bought on Tuesday near (what turned out to be) the high of the week.  Price went down and back up again, triggering a “buy-more” at 4pm, but the tranche-purchase was postponed until Wednesday 11am (for a much better price).  At Wednesday’s close, PPO was just above giving a “sell” signal.  From Thursday’s open the market just sank until it hit my stop.

SRTY 2 : Sold near Thursday’s close, just before its price went through the roof on Friday.  What can ya do?  The SRTY model has a hair-trigger “sell” signal and it triggered.

TZA: Bought Thursday.  Its price went down at Thursday’s close, then up at Friday’s open, but a “buy more” signal was not triggered because STDDEV was too high.  This will turn out to have been a good move if there is a reaction rally on Monday and so I end getting a better price on the second tranche.  Even if I had bought the tranche at 11am on Friday, my account would still have lost 0.3% this week.

Overall, the robot performed well this week.  I got the expected amounts of profit and loss, the buy-times and sell-times were correct (the model cannot predict stop-out times any more accurately), and the actual prices received were as close to the model prices as could reasonably be expected.  The main thing that went wrong was that Thursday’s max-loss recalculation for SRTY caused the stop price to go *down*, but stop prices should only ever go up.  I have adjusted the robot to pull latest quotes for both IWM and TZA during the same invocation of Opera, so they will differ by milliseconds instead of seconds.  Hopefully that will tighten up the stops a little.

Surfing the oscillations

Here are the last two weeks, showing how mean the stock market has been to me.  Three times the market went in one direction just far enough to convince me to hop on, then immediately reversed to make me lose money.  This sort of thing happens periodically and is a side-effect of using “average” model parameters that have typically worked well over the last four years (but those parameters have worked very badly for certain multi-month periods).

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.


Friday, 18 May 2012

Week of 2012 MA 18

SPY fell by 4.7% this week, while my account rose 0.9%.  I am out of the market again; many pundits believe that next Monday will bring either a large bounce or a crash.

Friday’s allocations:
Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TZA#0 MA03 +0.7 30  +1.8 30  +1.9 -0.0%
SRTY#0  MA08 -0.1 14  +0.4 -0.3%
SRTY#1  MA14 +0.0 15  +0.1 15  +0.4 15  +1.4 -0.9 -0.9 -0.2%
SRTY#2  MA16 +0.6 16  +1.6 16  +2.1 16  -0.4 -0.3 +1.4%
SRTY#3  MA18 +0.2 16  -1.2 -1.2 -0.3%
SPY +8.1 +6.9 +6.2 +5.8 +4.3 +3.4
me -6.9 -7.1 -7.1 -6.5 -5.5 -6.0
floor -6.9 -7.1 -7.1 -7.5 -7.2 -6.0

This week, I have changed the “Daily % Gain” table so all figures are percentages of my total account, not of the individual trade.  Basically, all numbers are now ⅟₇ of what they used to be.  This removes the disparity between the daily table above and the robot’s weekly table below, which was already using total-account figures.

Stock-trading robot

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA#1 MA 14 11:00 (Skipped) $20.58 (Not yet)
SRTY#1 MA 14 12:00 MA 14 11:00 $51.05 $51.25 MA 09 14:00 $50.57 $50.50 -0.2%
SRTY#2 MA 16 10:00 $50.75 $50.58 MA 18 11:00 $55.75 $55.70 +1.3% +1.4%
SRTY#3 MA 18 12:00 $57.52 $57.50 MA 18 13:00 $56.47 $56.46 -0.3%

TZA#1: Argh!  The robot didn’t buy because it got an IWM real-time quote from Schwab at 11am that was higher than the one for 10am, while stockcharts.com shows a lower price.  Because of the new STDDEV rule, the robot then refused to buy TZA all week, waiting for a bounce that never came.  As I suspected last week, it was a bad idea to sell TZA last Thursday and it might well turn out to have been a bad idea not to overrule the robot and buy TZA this week.

SRTY: This ticker underwent a 1-for-5 reverse split last Friday, so all price-quotes are now five times larger ($50 instead of $10).

SRTY#2: Good timing on the purchase!  The robot shorted the market on Wednesday at what turned out to be nearly the highest price of the day.  Friday’s sale-time wasn’t so hot, though.

SRTY#3: This was stupid.  I have added a new rule: Do not buy SRTY unless at least two hours have passed since the last sale.  This rule increases average profit slightly (from 10.4%/year to 10.5%/year) and improves the win:loss ratio slightly (from 101:118 to 101:116 since 2008) but the main point is that it would have blocked the third trade this week.

Daily stop-update: Friday’s stop price for SRTY#2 should have been $50.40 (for a -0.1% max loss) but the robot chose $49.48 (for -0.3%).  As a result, the max-loss actually went *down* from Thursday’s -0.2%.  I really ought to fix this, by fetching quotes for IWM and SRTY during the same invocation of Opera so their prices will differ by milliseconds instead of seconds.