Thursday, February 21, 2013

think this market can't go higher?

we all know that the fed activity has obfuscated the real machinations of the market. but it is easy to lift the veil of confusion by looking at the dow/gold ratio. here's the picture:
dow/gold ratio since 2009
economists refer to dow/gold ratio charts when they want to subtract inflation from their charts over long periods of time. the principle here is that gold is a stable store of value and by putting the price of gold in the denominator i am valuing the dow in terms of gold. so currently one can buy a dow future for about 8.7 troy ounces of gold. 

if you are still waiting for the market to double-dip the 666 level of march 2009 then please resume breathing - it already occurred. when the s&p downgraded the us debt in august of 2011 the dow/gold made the second dip. the reason why the media didn't report this was that it was obscurred by the activity of the fomc injecting liquidity into the market.

historically, values of dow/gold below 10 represent lower, recessionary readings and we are just breaking into a new range above 8.2 the next resistance is 9 and if that breaks then 10 comes into the picture, which represents the upper bound of the recession, with the teens representing early good-times.

Thursday, February 14, 2013

thinkscript included: aiSpy


after a long interlude i am back with an innovation in thinkscripting: sdi_aiSpy. to put it simply, sdi_aiSpy is a feed-forward neural-network strategy that simulates fixed-dollar, long-only trades on the etf, spy, using the daily aggregation period. here is a picture of the strategy at work:







the strategy mines the best practices for long-only trading on spy from 10 years of daily data. the circled fpl (floating profit and loss) does not include commissions.

the companion study, sdi_aiSpyMind, shows the output of the buy/sell "neurons" of the same nn as sdi_aiSpy. the threshold value of 0.8 is where the network considers the neuron to be "firing." in the rare cases where both buy and sell are both active then no action is taken. 

for comparison i have also displayed the sdi_passive study that shows the growth of a 10k investement via buy-and-hold and dollar-cost-averaging over the same period. this shows a profit of $1,440 vs $2,978 by aiSpy.

caveat: aiSpy is highly optimized for the specific environment that it was trained for: spy, daily aggregation period, long-only trades with prices in the range of $50-$200.

here is the thinkscripts for both aiSpy and aiSpyMind:
#############################
# sdi_aiSpy
#hint: feed-forward neural-network strategy that simulates fixed-dollar, long-only trades on the etf, spy, using the daily aggregation period. http://www.smallDogInvestor.com rev: 1.2.0
# author: allen everhart
# date: 2/14/2013
# revision:
#     1.0.1 7/27/2013 - round off long numbers for new 15 digit limit in TOS
#     1.2.0 11/17/2013 - account for commissions.
# Copyleft! This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.

def n00 = (1.0 / (1.0 + Exp(-(0.394412243353913*close[0] + -0.757893552541896*close[1] + 0.298268163430432*close[2] + 0.073011718813853*close[3] + 0.268481160972121*(-1.0))/1.0)));
def n01 = (1.0 / (1.0 + Exp(-(0.043156438870034*close[0] + 0.314385182984086*close[1] + 0.643174368836916*close[2] + 0.449210701821324*close[3] + -0.039991647581192*(-1.0))/1.0)));
def n02 = (1.0 / (1.0 + Exp(-(0.114407816382417*close[0] + -0.189924985908828*close[1] + 0.308215925671476*close[2] + 0.336453429416838*close[3] + 0.230327528474661*(-1.0))/1.0)));
def n03 = (1.0 / (1.0 + Exp(-(-0.475647872256089*close[0] + -0.112591560827932*close[1] + -0.613013913739063*close[2] + -0.164836967728427*close[3] + 0.080334976530424*(-1.0))/1.0)));
def n04 = (1.0 / (1.0 + Exp(-(0.338319944050806*close[0] + -0.187943246111633*close[1] + -0.045920637300546*close[2] + 0.065643428215118*close[3] + -0.136887709123339*(-1.0))/1.0)));
def n05 = (1.0 / (1.0 + Exp(-(-0.248025954494193*close[0] + -1.245654016701924*close[1] + 0.959282554357995*close[2] + 0.531781356224809*close[3] + 0.097232935684274*(-1.0))/1.0)));
def n06 = (1.0 / (1.0 + Exp(-(0.978509085019555*close[0] + 0.522508628185785*close[1] + -0.007746140763169*close[2] + 0.182100420784146*close[3] + 0.147782358875439*(-1.0))/1.0)));
def n10 = (1.0 / (1.0 + Exp(-(0.001353108521367*n00 + -0.207117354877679*n01 + 0.395157679885085*n02 + 0.318818663432868*n03 + 0.212632869510944*n04 + 0.735186053799497*n05 + 0.553872437254164*n06 + -0.02237150713544*(-1.0))/1.0)));
def n11 = (1.0 / (1.0 + Exp(-(0.662663591575132*n00 + -0.341341340003081*n01 + -0.16609680207996*n02 + 0.163148493179810*n03 + 0.136936511969303*n04 + -0.709184442200140*n05 + 0.698809451898064*n06 + -0.892538600208493*(-1.0))/1.0)));
def buysig = n10 >=0.8&& n11 < 0.8 ;
def sellsig = n10 < 0.8&& n11 >= 0.8 ;
input dollarsPerTrade = 10000;
#hint dollarsPerTrade: trades vary in share size in order to keep the invested dollars constant to create a fair comparison to passive strategies. http://www.smallDogInvestor.com rev: 1.2.0
input commission = 5;
#hint commission: dollar value of commission per trade i.e. this number is multiplied by 2 (to account for a round trip) and divided by the number of shares traded and added to the purchase price in order to slip the entry price to account for the effect of commissions on the p&l.
def shareSize = round(dollarsPerTrade/close,0) ;
def commissionPerShare = 2*commission/shareSize;
addOrder( OrderType.BUY_AUTO, buysig, tradeSize = shareSize, name="aiSpy", price = open[-1]+commissionPerShare );
addOrder( OrderType.SELL_TO_CLOSE, sellsig,  name="aiSpy");

plot buy =  buysig && !buysig[1] ;
buy.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot sell = sellsig && !sellsig[1] ;
sell.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

 


#############################
# sdi_aiSpyMind
#hint: Plots the buy/sell neuron output of the aiSpy feed-forward neural network simulating long-only, fixed-dollar trades on SPY using the daily aggregation period. http://www.smallDogInvestor.com rev:1.0.1
# author: allen everhart
# date: 2/14/2013
# revision:
#     1.0.1 7/27/2013 - round off long numbers for new 15 digit limit in TOS
# Copyleft! This is free software. That means you are free
# to use or modify it for your own usage but not for resale.
# Help me get the word out about my blog by keeping this header
# in place.

declare lower ;
def n00 = (1.0 / (1.0 + Exp(-(0.394412243353913*close[0] + -0.757893552541896*close[1] + 0.298268163430432*close[2] + 0.073011718813853*close[3] + 0.268481160972121*(-1.0))/1.0)));
def n01 = (1.0 / (1.0 + Exp(-(0.043156438870034*close[0] + 0.314385182984086*close[1] + 0.643174368836916*close[2] + 0.449210701821324*close[3] + -0.039991647581192*(-1.0))/1.0)));
def n02 = (1.0 / (1.0 + Exp(-(0.114407816382417*close[0] + -0.189924985908828*close[1] + 0.308215925671476*close[2] + 0.336453429416838*close[3] + 0.230327528474661*(-1.0))/1.0)));
def n03 = (1.0 / (1.0 + Exp(-(-0.475647872256089*close[0] + -0.112591560827932*close[1] + -0.613013913739063*close[2] + -0.164836967728427*close[3] + 0.080334976530424*(-1.0))/1.0)));
def n04 = (1.0 / (1.0 + Exp(-(0.338319944050806*close[0] + -0.187943246111633*close[1] + -0.045920637300546*close[2] + 0.065643428215118*close[3] + -0.136887709123339*(-1.0))/1.0)));
def n05 = (1.0 / (1.0 + Exp(-(-0.248025954494193*close[0] + -1.245654016701924*close[1] + 0.959282554357995*close[2] + 0.531781356224809*close[3] + 0.097232935684274*(-1.0))/1.0)));
def n06 = (1.0 / (1.0 + Exp(-(0.978509085019555*close[0] + 0.522508628185785*close[1] + -0.007746140763169*close[2] + 0.182100420784146*close[3] + 0.147782358875439*(-1.0))/1.0)));
def n10 = (1.0 / (1.0 + Exp(-(0.001353108521367*n00 + -0.207117354877679*n01 + 0.395157679885085*n02 + 0.318818663432868*n03 + 0.212632869510944*n04 + 0.735186053799497*n05 + 0.553872437254164*n06 + -0.02237150713544*(-1.0))/1.0)));
def n11 = (1.0 / (1.0 + Exp(-(0.662663591575132*n00 + -0.341341340003081*n01 + -0.16609680207996*n02 + 0.163148493179810*n03 + 0.136936511969303*n04 + -0.709184442200140*n05 + 0.698809451898064*n06 + -0.892538600208493*(-1.0))/1.0)));

plot buy = n10 ;
buy.setDefaultColor(Color.Dark_GREEN);
plot sell = n11 ;
sell.setDefaultColor(Color.RED);
plot threshold = 0.8 ;
threshold.setDefaultColor( Color.DARK_ORANGE);
threshold.setLineWeight(2);
threshold.setPaintingStrategy(PaintingStrategy.DASHES);

#########################


Saturday, February 2, 2013

butterfly morph's

it's been a tremendous bull run this january. however, with the experience of trading in the past few years, i now fear a backlash. i am just not used to a trending market. to address these fears, i have been experimenting with a different way of finishing-off winning short option trades: the butterfly-morph.

a butterfly is simply two verticals, a credit-spread and a debit-spread, that share a common short-option strike. because the credit offsets part of the debit, they can be very inexpensive and sport a large reward IF the underlying expires in the vicinity of the short option strikes. that's a big 'IF' because the target vicinity is usually a narrow price range. low risk/high reward = low win/high loss, there's no free lunch ... or is there?

here's the risk profile of a typical butterfly trade:

february spy 'fly
16.48% of the time there will be some gain in this trade but 83.52% of time there will be a full loss (ignoring the miniscule transition ranges.) this is a win/loss ratio of .197 so a $20($8 + $12 in round-trip commissions) investment means i would have to make $101 (=20/.197), at least as a possibility, to break-even on a steady diet of butterflys. since our maximum return on this trade is $92 it would seem this is not a business-quality strategy. this is not even your typical casino-quality trade, since the maximum return only occurs for the exceedingly rare event of the underlying pinning the short option strike at expiration. these butterflys are lottery tickets. why would any investor want that!?

i would want that because i can get the lottery tickets essentially for free. suppose i am in a cash-covered, short-put trade. say, short the spy feb 149 put, that i sold for $2 a while back. today i can buy back this option for 59 cents and i could roll this position to march but there is a decent amount of time left in february. for a few cents more than the cost of buying back the feb option i can purchase a 'morph' - i buy the feb 150 and 148 puts and sell one more feb 149 put, all for 65 cents. this metamorphizes my trade into a butterfly,  but, this is a butterfly that was legged-in for a net credit of $1.29 ($2-.65-.06commissions). by doing so, i lock-in $1.29 of profit and retain a free lottery ticket that could help ease the pain of a retracement.

but it gets better. once i have purchased the morph, the buying power allocated to the original cash-covered put, enough to buy 100 shares of spy at the price of $149 each, is returned to my account because there is no further risk of loss in the trade. with the released buying-power i can initiate a new cash-covered put position in march and continue onward prepared for most of whatever.

now, the lunch isn't really free. i gave up 6 cents and commissions of unrealized profit. however, this is lunch money that could easily be lost in the slop while waiting for a more opportune time to roll and it buys a disproportinate amount of peace-of-mind.