Friday, May 30, 2014

what i see

"trade what you see," is the admonishment i read from many a financial advice column. the tools at thinkorswim and my smalldoginvestor tools are geared for just that. here is the picture i have and outlook for june:
spy $10k seasonal buy and 20 trading day hold,  with projection channels
spy has been on an unseasonal bull run. the purple regression channel takes us up to the top of the blue, longer-term channel by mid-month...provided that the market continues a straight-line march. over the last 10 years, a june 20 trading-day buy & hold on spy has not once been profitable. will 2014 break the streak or conform to the decade-long norm? 

i can't build a case for buying based on proximity to a support level, yet, i can't build a strong case for selling either since we are not close enough to channel resistance levels. volatility levels are way down which takes the benefit out of trading neutral, premium-selling strategies. i feel stymied and have moved 90% to cash. i am trading some new ideas but in extremely small, test-the-water, 1-lots. i will post some of these soon.

Saturday, May 24, 2014

thinkscript included: sdi_seasonalstgy rev:1.2.0 & next 4 day hold on spy

i am hearing from this or that news outlet that the 4-day week following memorial day is bearish. so i am using this opportunity to show to you the best data i can muster regarding this and to improve the study i use to evaluate seasonality. so here is the picture:
p&l of $10k worth of spy buy 'n hold for next 4 days, over last 20 years. 
there are a number of improvements in this version of the study:

  1. the study allows for the input of specific target trading days instead of just the current.
  2. the study defaults to evaluating the next trading day of the year instead of the current. this reduces the influence of open positions on the p&l graph.
  3. the strategy reports on the chart the trading day it bought-to-open a position and the number of trading days it held it when it sold-to-close.
  4. the chart label reports the percentage wins and the number of trades.
  5. the chart label reports the average p&l per trade.
as always i maintain the revised studies on the original release blog here.

Friday, May 16, 2014

thinkscript included: sdi_psarstgy - simulate trading the parabolic-stop-and-reverse signal

i was listening to swimlessons on thinkorswim today and i heard jeff bierman promoting the psar (parabolic-stop-and-reverse) strategy. so i was wondering how this strategy really performs when you add up the wins and losses. this is the inspiration for my new sdi_psarstgy thinkscript strategy and here is what i find with the standard recommended settings of .02 for acceleration factor and .2 for acceleration limit:
p&l of $10k traded by the psar strategy (using standard .02 acceleration-factor and .2 acceleration-limit parameters) on spy compared with growth of  $10k buy 'n hold (bottom green) and dollar-cost-averaging (bottom blue)
the psar strategy lost $746 while buy 'n hold made $1,269 and dollar-cost-averaging made $678 - not exactly a happy picture but jeff did say you need to adjust the acceleration parameters. by tweaking the input parameters to my sdi_psarstgy one can instantly evaluate the effect a modification has to the p&l. here's a setting that turns the above frown upside down:
p&l of psar strategy with acceleration factor of 1.0 and acceleration limit of 0.3

this p&l is nearly the same as buy 'n hold and handily beats dollar-cost-averaging. the acceleration factor of 1.0 says to the psar formula to skip the pretty parabolic movement of the stop and go immediately to the straight-line movement set more aggressively at 0.3

here's the code (install instructions here):
# sdi_psarstgy:
#hint:Strategy to evaluate trading parabolic-stop-and-reverse signals rev:1.1.0
# author: allen everhart
# date: 16may2014
# revisions:
#    4jun2014-added %win label, corrected reverse price on gaps
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. rev: 1.1.0
input accelerationFactor = 0.02;
#hint accelerationFactor: controls how steep a parabola is traced by the stop.
input accelerationLimit = 0.2;
#hint accelerationLimit: after the limit is reached the stop moves up in a straight line.

def psar = ParabolicSAR( "acceleration limit" = accelerationLimit, "acceleration factor" = accelerationFactor);
def buySig = close crosses above psar;
def sellSig = close crosses below psar;
def shareSize = round(dollarsPerTrade/psar,0) ;
def buyPrice=#psar;
    if open[-1]>psar then open[-1]
    else psar;
def sellPrice= #psar;
    if open[-1]<psar then open[-1]
    else psar;
AddOrder(OrderType.BUY_AUTO, buySig[-1], price = buyPrice, tradeSize=shareSize, name = "buy");
AddOrder(OrderType.SELL_AUTO, sellSig[-1], price = sellPrice, tradeSize=shareSize, name="short");
plot parSAR = psar;

def longPrice=compoundValue(1,
    if !longPrice[1] && buySig[-1] then buyPrice
    else if longPrice[1] && sellSig[-1] then 0
    else longPrice[1]
#plot lp=longPrice;
def shortPrice=compoundValue(1,
    if !shortPrice[1] && sellSig[-1] then sellPrice
    else if shortPrice[1] && buySig[-1] then 0
    else shortPrice[1]
#plot sp=shortPrice;

def wincntr= compoundValue(1,
    if longPrice[1] && sellSig[-1] && sellPrice>longPrice[1] then wincntr[1]+1
    else if shortPrice[1] && buySig[-1] && shortPrice[1]>buyPrice then wincntr[1]+1
    else wincntr[1]
def winNum=if isnan(wincntr) then winNum[1] else wincntr ;
def losscntr= compoundValue(1,
    if longPrice[1] && sellSig[-1] && sellPrice<=longPrice[1] then losscntr[1]+1
    else if shortPrice[1] && buySig[-1] && shortPrice[1]<=buyPrice then losscntr[1]+1
    else losscntr[1]
def lossNum=if isnan(lossCntr) then lossNum[1] else lossCntr ;

    concat( "win: ", 
    concat( round( 100*winNum/(winNum+lossNum),1),
    concat( "% of ", winNum+lossNum))),

Saturday, May 10, 2014

thinkscript included: sdi_seasonalstgy rev: 1.1.0 - win% label added

in this enhancement i have added a chart label to show the win% of the trades. here's how this looks:
p&l on dia with win% label on a $10k investment purchased on yesterday's, 9th of may, trading day of the year and held for 20 trading days, going back 20 years.
as you can see, now (at least in the short run,) is not a great time to be buying the dow. however, with only a coin-flip's chance, it is not a good short either despite the negative p&l shown for would-be buyers.

additionally, a minor flaw was corrected: previously, the commission input was limited to integer dollars. now the commission can be entered to the cent.

as always, i maintain the updated source code on the original post page here