Friday, 30 March 2012

Week of 2012 MR 30

SPY rose by 0.9% this week, while my account fell 1.1% to its lowest value ever.  My loss floor is now equal to my account because I am out of the market.

Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TZA  MR22 -4.4  14 -10.3 13 -8.3 13 -6.9 13 -5.9  0   -6.2 -6.2 -8.0%
TNA  MR26 +0.6  14 -1.5  13 -3.2  13 -4.1  13 -5.0  13 -10.5 -10.5 -3.3%
SPY +11.3 +12.8 +12.5 +11.9 +11.7 +12.2
me -2.6 -3.1 -3.4 -3.7 -3.7 -3.7
floor -2.9 -4.7 -4.7 -3.7 -3.7 -3.7

TZA: Gap-down at Monday’s open forced me to take a loss that was larger than my “max loss” number.  This happens less often with index funds than with individual equities, but there is still a chance for it — and more likely now that I am using tighter stops.

TNA: Whiplash!  It’s shit like this, Mr. Market, that drives less-stubborn traders out of the business.  I think the real problem here is that my system assumes a certain time constant for the market’s motions.  When things move faster than that, I get losses.

MACD-based swing trades

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA MR 22 11:00 $18.64 MR 26 09:30 $17.18 -1.0% -1.1%
TNA MR 26 12:00 MR 26 11:01 $65.73 $65.54 MR 28 11:00 $63.45 $63.49 -0.5% -0.4%

TZA: A “perfect trade” in both timing and pricing — yet still it was a huge loser.  Hopefully the usual rule of ”biggest gains come right after biggest losses” will apply.  Difference between model-profit and actual-profit may be related to the fact that IWM just paid a dividend but TZA didn’t.

Monday: Schwab changed their webpage formatting to be more iPad-friendly, causing my robot to lose its ability to fetch quotes.  Also, the robot’s database contained a rogue price for a real-time quote last Thursday, so it wouldn't have bought at 11am anyway.  Fixed the quote-fetch and manually purchased the TNA shares.  I guess I need to replace the robot’s database of Schwab quotes with stockcharts.com quotes every week to keep things in sync.
Tuesday: Another aspect of Schwab’s website-wide reformatting prevented the robot from updating its stop (whose price didn't change anyway).  Fixed.
Wednesday: Successful 10am stop-update (but no change in price), followed an hour later by a successful PPO-based sale.

TRIX-based trend trades

Current value for TRIX(176,16) is -0.00035.  Getting up to a “buy” level of +0.00011 could happen next week.  I plan to install this software into the trading robot over the weekend.

Quarterly summary

Pretty bad: I lost 3.7% of my money this quarter, while IWM gained 9.8%.

Actual Live model Final model
URTY ×0 (n/a)
RWM ×4 JA 06 - FE 01 -1.0%
TNA ×0 (n/a)
TZA ×2 JA 23 - FE 01 -1.3%
TNA ×1 FE 01 - FE 01 +0.0%
TZA ×2 FE 07 - FE 16 -0.4%
TZA ×2 FE 29 - MR 07 +0.5%
TNA ×4 MR 09 - MR 20 +0.0%
TZA ×1 MR 22 - MR 26 -1.1%
TNA ×1 MR 26 - MR 28 -0.4%
3:5 win:loss TOTAL -3.7%
URTY ×0 (n/a)
RWM ×0 (n/a)
TNA ×0 (n/a)
TZA ×2 JA 23 - FE 01 -1.2%
TNA ×0 (n/a)
TZA ×2 FE 07 - FE 16 -0.4%
TZA ×2 MR 02 - MR 07 +0.3%
TNA ×4 MR 09 - MR 20 +0.4%
TZA ×1 MR 22 - MR 26 -1.0%
TNA ×1 MR 26 - MR 28 -0.5%
2:4 win:loss TOTAL -2.6%
URTY ×3 DE 29 - FE 03 +13.0%
RWM ×0 (n/a)
TNA ×2 JA 10 - JA 13 -0.7%
TZA ×0 (n/a)
TNA ×2 FE 01 - FE 07 +1.0%
TZA ×2 FE 10 - FE 16 -1.1%
TZA ×2 MR 02 - MR 07 +0.4%
TNA ×3 MR 09 - MR 20 +0.8%
TZA ×1 MR 22 - MR 26 -1.1%
TNA ×1 MR 26 - MR 28 -0.5%
4:4 win:loss TOTAL +11.8%

The “actual” column shows what really happened.  The “live model” shows what should have happened, using the versions of the model that were current at those trade times.  The “final model” shows what could have happened, had I spent the entire quarter using the version of the model that I have now.

The “final model” is quite unrealistic.  It asserts that I bought URTY on December 29th, even though I had no URTY trend-trading system until March so I couldn’t possibly have bought it in December.  Without URTY, even the “final” model would have lost -1.2% this quarter (vs. +0.9% for Q4 of 2011).

Conclusion: my swing-trading system has “loser quarters” about ⅓ of the time—this was one of them.  Thankfully, the system very rarely has two loser quarters in a row, so there is reason to hope for gains in Q2.

(By the end of Q2, I hope to have a new graphing system to create these charts, which will produce something less ugly than those stupid rectangles.)

Friday, 23 March 2012

Week of 2012 MR 23

SPY fell by 0.5% this week, while my account fell 1.4% and returned to its lowest value ever.  My loss floor rose by 3.2% thanks to the new stop-setting algorithm.

As discussed last week, I have increased my tranche size to 14% of account.  This is supposed to magnify profits, but as of today it is just magnifying the loss.

Just for fun, the pie chart shown below is for Thursday.  Note the gigantic bet on TNA (which settled Friday morning).  I believe that this is the largest single-ticker bet I have ever placed that didn’t end up as a loss.

Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri Mon Tue Wed Thu Fri Beg   End
 
TNA  MR09 +2.4  32 +4.0  43 +1.2  42 +1.0  42 -1.8  42 +1.1  0 -12.0 -2.4 +0.1%
TZA  MR22         -1.5  14 -4.4  14 -6.2 -6.2
SPY +11.8 +12.2 +11.9 +11.8 +10.9 +11.3
me -1.2 -0.2 -1.9 -1.9 -2.2 -2.6
floor -6.1 -3.1 -1.9 -1.9 -2.9 -2.9

TNA: The new stop-setting algorithm did not interfere with the TNA trade, which closed normally due to PPO<-0.2. 

TZA: the new system is risking only 1 percent of my account, so I bought 40% more shares while taking 30% less risk than in the old system!  Problem: after today there is now very little stop-depth remaining and DanEric seems to be expecting that the market will go up a lot on Monday.

me: Briefly got up to -0.2% on Monday, but back down to lowest-ever.  Unless next week is very good for me (= very bad for the bulls), I seem to be heading for a loss this quarter.

floor: On Monday, Tuesday, and Friday at 10am, the new daily stop-update failed to work — for three different reasons! — so I updated the stop manually (except no change on Friday).  On Wednesday and Thursday at 10am, there was no stop to update.  Other robot operations (buy, buy-more, sell) have been observed to work correctly in the new system.
      The new stop system can be further optimized.  It invokes Opera three times: fetch IWM price, fetch TNA price, set new stop.  Each invocation involves a separate Schwab login, which takes several seconds, so the IWM and TNA prices are not for the same moment and their ratio isn’t quite accurate.  Instead, could call Opera only twice: fetch IWM price, then call it again with the new IWM-based stop and have GreaseMonkey re-fetch the latest IWM and TNA prices, calculate their ratio, and set the new TNA stop.

MACD-based swing trades

New rule: If today’s calculated stop price is lower than yesterday’s, and a trade is in progress, then do not lower the stop.  (This fixes a bug when the market gaps down at the open and the model responds by lowering its stop instead of detecting the stop-out.)

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TNA MR 09 11:00 $60.06 $60.11 MR 20 12:00 $61.79 $61.67 +0.4% +0.0%
MR 13 11:00 $60.24 $60.37
MR 15 14:00 $62.04
MR 19 11:00 $63.68 $63.67
TZA MR 22 11:00 $18.64 (Not yet)

TNA:  Argh!  All that risk and only +0.047% reward.  Okay, it wasn’t a loss, but I’m still not happy.  I place the blame on two main factors:
      Bad sale time.  It’s hard to see how the robot could have done any better.  There was no reason to sell at an earlier time.  If my cutoff were PPO<-0.3 instead of PPO<-0.2, the sale would have been postponed all day (because of the rule not to sell when prices are rising) and the next morning’s price would have been about the same.  It’s just unfortunate that so many better times to sell were available, but my model would never have picked any of them.
      Bought too many tranches.  Without the fourth tranche, account-profit would have been +0.4%, almost ten times as much as I got.  New rule: buy at most three tranches of TNA.  See section “Risk analysis” below for justification.

TRIX-based trend trades

Current value for TRIX(176,16) is -0.0005.  Last week it was -0.0009; the week before was -0.0013.  At this rate of increase, a “buy” signal (+0.00011) will probably not happen next week.

Here are the revised rules, with yellow highlighting for changes.  These reduce risk considerably over previous attempts!
Buy if:
  • TRIX(176,16) is now above 0.00011 and had gone below that value sometime after the last sale.
  • TRIX(17,20) is now below -0.028 and had gone above that value sometime after the last sale.
Sell if:
  • TRIX(176,16) is now below 0.0025.
  • TRIX(17,20) is now above 0.033.
Buy more if:
  • TRIX(176,16) is now above 0.00011
  • TRIX(17,20) is now below -0.01 and had gone above 0.003 sometime after the last purchase.
  • Have bought 2 or fewer tranches so far.
Regardless of above, at any time of day, sell immediately if:
  • Price falls below stop.
  • Each day at 10am, recalculate stop to be the lowest price seen in the last 78 hours, but skip this if a trade is in progress and stop is already higher than that value.
  • When buying the first tranche of a trade, raise stop to 0.97 × purchase price if it is less than that.

Risk analysis

In this table, we assume that 100% of my account is divided into the specified number of tranches.  More tranches mean smaller losses on bad trades that end quickly, but also smaller profits on good trades because the later tranches are bought for worse prices.  How many tranches produce the best results?  The “Risk” column indicates the percentage of my account that is at risk (below purchase price but above the stop), averaged over all days 2008-2011 when I owned some of the stock.  The “Ratio” column is gain÷risk, which should be maximized for best performance.

Long - TNA Short - TZA Trend - URTY
TranchesGainRiskRatioGainRiskRatioGainRiskRatio
1 160.9%7.4%21.6 116.7%6.4%18.2 242.3%10.2%23.8
2 109.9%4.9%22.7 126.7%3.5%36.2 208.2%5.3%39.3
3 90.5%3.3%27.8 107.9%2.2%49.0 174.0%4.1%42.4
4 68.2%2.5%27.5 92.4%1.6%57.8 147.4%3.5%42.1
5 54.5%2.0%27.4 75.5%1.3%58.1 125.4%3.1%40.5
6 45.4%1.7%27.3 62.9%1.1%57.2

Based on these results, I have lowered the max-tranche count for TNA to 3, increased it to 5 for TZA (at least for now), and kept it at 3 for URTY.  The risk numbers shown here are not realistic because I am not actually dividing my entire account into 3 or 5 tranches.  Instead, the tranche size is fixed at 14%, which is roughly ⅟7 of my account.  For a 14% tranche with a 15% trailing stop (due to 3× leverage), the maximum account risk is 2.1%.

The values shown above for URTY are based on old TRIX parameters, including a 30% leveraged trailing stop.  With the new parameters — if the model is to be believed — the average risk is actually NEGATIVE, meaning that the stop is above my purchase price on the AVERAGE day when I am holding URTY and so some profit is “guaranteed”.

For TZA, the higher tranche-counts occur very rarely.  The only time during 2008-2011 when five or six tranches would have been bought was during last August’s crash.  Can’t do statistics on a single-event outlier!

Monday, 19 March 2012

Week of 2012 MR 16

SPY rose by 2.2% this week, to its highest weekly close since Octo­ber 2007.  My account rose by 0.9%, back to its value from five weeks ago, but my loss floor fell by 2.5% to what might be its lowest value ever.  This is too much risk for the gain obtained; see “MACD-based Swing Trades” below for the new risk-reduction algorithm, which will raise the loss-floor from -6.1% up to -2.7%.

Daily % gain
size
Max lossFinal
Gain
Sym  Buy Fri   Mon   Tue   Wed   Thu   Fri Beg   End
 
TZA  FE29 -5.8  21 -5.1  0         +2.5%
TNA  MR09 -1.3  10 -1.9  10 +3.9  21 +1.3  21 +3.0  32 +2.4  32 -14.4 -12.0
SPY +9.6 +9.6 +11.6 +11.5 +12.1 +11.8
me -2.1 -2.2 -1.1 -1.7 -1.0 -1.2
floor -3.6 -3.6 -4.6 -4.5 -6.1 -6.1

TNA: I have just about ⅓ of my money invested in a 3× leveraged fund, so basically I am “100% long the market”.  This is my highest market exposure in quite some time.  I am eking out a profit, but the max-loss floor is just too damn low!  The new system will raise the loss-floor from -12.0% to -2.2%.

I am pleased with my new concern for risk management.  Over the last year, I have been telling people that I am obviously a newbie trader because all I care about is profit, with no thought to spare for risk.  Perhaps I am moving up to Trader Experience Level 2?

MACD-based swing trades

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TNA MR 09 11:00 $60.06 $60.11 (Not yet)
MR 13 11:00 $60.24 $60.37
MR 15 14:00 $62.04

TNA:  So far, so good!  All tranches bought at correct times.  Third tranche bought for exactly-correct price.  Hopefully my trading robot will close this position before the market turns.

New TNA rule: Each day at 10am, find the lowest low and 0.945 times the highest high for IWM over the preceding 22 hours.  Use whichever of these is higher as the new IWM sell-stop price.  If I currently own any TNA shares, take the percentage-change between sell-stop price and current IWM price, multiply by 3, then apply that to the current TNA price to get the new TNA stop price; update the standing “stop” order at Schwab with this new price.

New TZA rule: Each day at 10am, find the highest high and 1.046 times the lowest low for IWM over the preceding 15 hours.  Use whichever of these is lower as the new IWM buy-stop price.  If I currently own any TZA shares, take the percentage-change between buy-stop price and current IWM price, multiply by -3, then apply that to the current TZA price to get the new TZA stop price; update the standing “stop” order at Schwab with this new price.

These new rules replace the old continuous-update trailing stops (TNA: 0.95; TZA: 1.053).  The new system uses hard stops with once-daily updates, which the robot can handle all by itself (trailing stops required manual intervention to get them started).  The number of hours must be one more than a multiple of 7, because Schwab’s pricing data includes only daily highs & lows, not hourly ones.

YearTNA TZA
OldNewOldNew
GainRiskGainRiskGainRiskGainRisk
2008 7.5%1.1% 6.7%1.0% 14.9%0.7% 14.7%0.5%
2009 11.0%1.0% 10.9%1.1% 3.1%0.9% 2.0%1.0%
2010 1.7%1.3% 1.0%1.1% 9.2%0.9% 6.2%0.8%
2011 8.6%1.7% 8.1%0.8% 6.9%0.9% 14.6%0.5%

This table compares the old and new systems.  The “Risk” column shows the percentage of my account that is at risk, averaged over all days when some money was at risk.  Over the last four years, the new TNA system would have produced 7.5% less profit while taking 24% less risk (mostly in the last two years when volatility has been lower); the new TZA system would have produced 12% less profit while taking 33% less risk!

Because the new system takes so much less risk, I can justify increasing the tranche size.  If I increase the tranches from 10%-of-account up to 14%, the new system will produce about 26% more profit while taking the same amount of risk as the old system.  I think I’ll increase the tranche size after the current TNA trade is completed.

TRIX-based trend trades

Still not done yet—my day-job had lots of work this week.  I’ll probably use some variation of the same risk-reduction scheme shown above.  Meanwhile, TRIX(176,15) is still rather negative, so I still have lots of time before a “buy” signal might arise.

Saturday, 10 March 2012

Week of 2012 MR 09

SPY rose by 0.2% this week, to its highest weekly close since Nov­ember 2007. My account fell 0.1%, while my loss floor, after some gyrations, ended up rising by 0.1%.  (It looks like a rise of 0.5% on the chart because last week’s floor should have been -3.7% but was drawn as -4.1%; this will be fixed next week.)

Daily % gain
size
Max lossFinal
Gain
Symb  Buy Fri   Mon   Tue   Wed   Thu   Fri Beg   End
 
TZA  FE29 +4.5  11 +4.1  11 +5.5  22 +2.4  21 -1.8  21 -5.8  21 −9.9 −9.4 +2.5%
TNA  MR09           -1.3  10 −15.1 −14.4
SPY +9.4 +9.0 +7.4 +8.1 +9.2 +9.6
me -2.0 -2.1 -1.3 -2.0 -2.0 -2.1
floor -3.7 -3.5 -4.7 -2.0 -2.0 -3.6

Euro news: Greece says the bond-exchange is a go.  The ISDA has ruled that the bond-exchange counts as a “credit-default event”.  Presumably, all the banks that sold credit-default swaps on Greece can now pay off those bets using the billions of newly-printed LTRO money that was recently handed out by the European Central Bank.

US news: The Federal Reserve Bank has dropped hints that there will be no QE3 announcement at next week’s meeting.  Presumably this will cause the market to plunge (it usually does).  If the market drops 20% by June, maybe they can announce QE3 then.  I’ve been expecting a June QE3 for a year now, in order to assure Obama’s re-election.

MACD-based swing trades

Starting this week, the “Acct Profit” column below shows the effect of the trade on my account balance, so the +2.5% gain from TZA, being 21% of my account, yields +0.5% of overall profit.  This trade raised my account balance from slightly better than -2.6% YTD loss up to almost -2.0%

Ticker
Symbol
Buy dateBuy priceSell dateSell priceAcct Profit
ModelActualMAModelActualMAMA
TZA MR 02 12:00 FE 29 15:00 $19.63 $19.11 MR 07 15:00 $20.56 $20.53 +0.3% +0.5%
MR 06 11:00 $20.99
TNA MR 09 11:00 $60.06 $60.11 (Not yet)

TZA:  Ding ding ding!  The first completed swing-trade using the revised rules is a winner!!!  Okay, +0.5% isn’t much, but it’s positive.  My trading robot bought the second tranche within seconds of the expected time, and it happened to catch a price that was within a penny of the expected value; unfortunately, the second tranche turned out to be a loser that dragged down the overall gain—this happens quite a bit and we just have to put up with it in the pursuit of probabilistic profit.  The final sale of TZA occurred during the expected minute for nearly the expected price.  Overall profit was quite a bit larger than expected because of the beneficial “mistake” in the purchase time for the first tranche.
      The price of TZA continued to fall for several days after the sale, making me feel good about the sell-time that my model came up with.  (If only it had sold a day earlier for twice as much profit!)

TNA:  The robot's first bullish trade!  It bought at the right time for only 0.1% more than the right price; then an hour later it wrongly announced that TNA had been sold due to trailing stop!  Trailing stops are handled automatically by Schwab, so the robot didn’t actually do anything, but it thought the shares were gone so it stopped checking to see when to issue a “sell” order for them.  Problem was that the Schwab pricing data doesn’t include hourly highs or hourly lows, which were coming in as zeroes, and $0.00 is a very low price so surely (the robot thought) there would have been a trailing-stop trigger.  Fixed to use Schwab’s quoted highs and lows for the day-so-far, which should be close enough except on extremely weird days.
      TNA fell after the purchase, but not by much and it seems there is a good chance that it will go back up on Monday, unless some bank or other fails over the weekend.

TRIX-based trend trades

Still haven’t put this thing into production.  That “10% trailing stop” with 3× leverage turns into a potential 30% loss, which is more risk than I can bear.  So far, I’ve looked into using a 5% hard stop (sell if price ever falls to 95% of original purchase price for first tranche).  That works, but it means the max-loss floor never gets raised, so lots of unrealized gain would stay at risk for weeks until the final sale.  This needs more work.  Since TRIX(176,15) is rather negative right now, I should have several weeks to think about this before a potential “Buy” signal might show up.

Sunday, 4 March 2012

Week of 2012 MR 02

SPY rose by 0.3% this week, to its highest weekly close since Decem­ber 2007. My account rose 0.6%, but my loss floor fell by 1.1%.

Daily % gain
size
Max % lossResults
Symb  Buy Fri   Mon   Tue   Wed   Thu   Fri Beg   End
 
TZA  FE29       +1.8  11 +0.0  10 +4.5  11 −15.2 −9.9
SPY +9.1 +9.3 +9.6 +9.2 +9.7 +9.4
me -2.6 -2.6 -2.6 -2.3 -2.5 -2.0
floor -2.6 -2.6 -2.6 -4.1 -4.1 -3.7

MACD-based swing trades

Ticker
Symbol
Buy dateBuy priceSell dateSell priceProfit
ModelActualMAModelActualMAMA
TZA MR 02 12:00 FE 29 15:00 $19.63 $19.11 (not yet)        

TZA: First purchase using the revised swing-trading rules!  The purchase date doesn’t match because the stockcharts.com price-data (used for the model) has become rather divergent from the Schwab data (used for actual trading).  Oddly enough, the PPO_signal had become rather different but the PPO_histogram remained just about the same!  Anyway, I replaced the historical Schwab data with the historical stockcharts.com data to resynchronize the robot to the model.

Surfing the oscillations

This chart shows that the small-cap index has bounced off the “critical support” line.  What comes next?  The index could jump solidly higher and continue heading skyward.  It could go back up for a day or two, then either bounce off the line again or crash through it.  Or it could gap down below the line on Monday, in which case the critical-support line will become a resistance line.

TRIX-based trend trades

YearWin:LossResults
20083:0+7.7%
20094:3+9.1%
20102:2+20.2%
20117:1+13.4%

I might have something!  My new trend system fills in the periods when the swing system doesn’t do well.  It has a decent win:loss ratio and makes a profit every year.  For now at least, this is a long-only system because downtrends are usually over too quickly for this thing to recognize them.

The trend system will buy URTY instead of TNA, to keep the systems distinct — this is necessary because they have different trailing-stop values.  Both systems use hourly prices for IWM in their calculations, to make it easy to bolt the new system onto my existing trading-robot infrastructure.

Buy if:
  • TRIX(176,15) is now above 0.00015 and had gone below that value sometime after the last sale.
  • TRIX(17,20) is now below -0.025 and had gone above that value sometime after the last sale.
Sell if:
  • TRIX(176,15) is now below 0.004.
  • TRIX(17,20) is now above 0.033.
Buy more if:
  • TRIX(176,15) is now above 0.00015
  • TRIX(17,20) is now below -0.005 and had gone above 0.003 sometime after the last purchase.
  • Have bought 2 or fewer tranches so far.
Regardless of above, at any time of day, sell immediately if:
  • Price falls to 90% of highest seen so far.

Here is a chart showing all trading-system results simultaneously:

For URTY, the worst loss in the last four years occurred in February 2009 (which was also the only activation of the 10% trailing-stop).  Note that the tall brown rectangle partially overlaps a tall yellow rectangle, indicating that TZA was gaining at the same time that URTY was losing.  The next biggest loss was August 2010; once again there is a yellow rectangle overlapping the brown, partially reducing its sting.  The rightmost blue rectangle is for the trend from 2011 DE 29 through 2012 FE 03, which would have started off my 2012 results with a gain of nearly 10% if I had installed this system earlier!