Tuesday, October 22, 2013

thinkscript included: sdi_tde rev 1.1 release, add 0.5 to after-market releases to group before and after market releasors.

previously, sdi_tde assigned the same count of trading days to earnings to before and after market releasors. this complicated the task of finding the after-market today and the before-market tomorrow releasors. now sdi_tde adds 0.5 to the count of trading days to earnings of after-market releasors so that they group separately from the before-market releasors. here's a picture of the new custom watchlist column that i now call tde:
watchlist of equities with weekly options sorted in the order of upcoming earnings
in the above list a tde of 0.5 indicates an equity with an earnings release after market-close today and 1.0 indicates an equity with an earnings release before market-open tomorrow. tde numbers update when the cash-market opens at 9:30am eastern.

as always i maintain the source code on the blog of the original release, here.

Sunday, October 6, 2013

thinkscript included: customize your watchlist to sort in the order of upcoming earnings

with the pace of enhancements to the tos platform i guess i shouldn't be too surprised that i stumble on things i didn't know were there. however, i've long been frustrated by the fact that there wasn't a natural mechanism to sort a watch-list in the order of upcoming earnings. so, today i set about building a custom column to show something like days to earnings when i stumbled on the function, geteventoffset(). geteventoffset() returns the number of bars into the future of a corporate event. this was an easy button for creating the custom column i call bte (bars-til-earnings.) 

Equities with weekly options sorted in order of upcoming earnings
here's the thinkscript for this column:

# sdi_tde: trading days til earnings
#hint: displays the trading days til earnings. after-market earnings add 0.5 to the count. this code is meant to be pasted into a custom watchlist column. rev: 1.2
# author: allen everhart
# date: 08oct2013
# rev 1.2: 8mar2014 color code the after-market earnings.
# rev 1.1: 22oct2013 add 0.5 if earnings are after-market.
# copylefts reserved. 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.

input length=60;
def xx = -getEventOffset(Events.EARNINGS);
def yy = sum(HasEarnings(type = EarningTime.AFTER_MARKET),length)[-length +1] > 0;
plot x=xx+yy*.5;
x.assignValueColor( if yy!=0 then color.LIGHT_RED else color.DARK_GRAY);

the only little gotcha is the minus sign. geteventoffset() returns negative numbers because in thinkscript a negative offset is a reference in the future time direction. 

here's how to get this custom column on your watch-list:

  1. right click on any column heading in your watch-list and select customize at the top of the pop-up list.
  2. scroll the available items list of the watchlist dialogue and click on the left-hand icon of one of the custom columns that you haven't already used.
  3. replace the default column name with bte in the column name text entry box of the custom quote formula dialogue.
  4. click on the thinkscript editor tab and replace the default formula with the thinkscript: -GetEventOffset( eventType = Events.EARNINGS)
  5. click ok
  6. click add item(s)>> button
  7. click move up or move down buttons to position the bte column to your preference.
  8. click ok

happy trading to you

Saturday, October 5, 2013

lessons of ai: trading underperforms a trending market

its been about 6 months since i published aiSpy (queue cheesy background music,) an artificial intelligence strategy for trading the etf spy. i was a little disappointed that the real-world testing of aiSpy was underperforming the passive investing techniques buy 'n hold and dollar-cost-averaging. i was expecting that when i ran the numbers i would see a reversion to randomness in the real-world numbers. that is to say i thought the numbers would revert to something like a coin-toss with a win/loss ratio very close to 1 and a risk/reward ratio a smidgeon less. instead the numbers worked out to 8 wins and 4 losses for win/loss of 2. the average dollars lost on a losing trade was 66.42 and the average dollars won on a winning trade was 60.33 (both corrected for commissions.) this gives a risk/reward ratio of 1.10 (=66.42/60.33) 

this fits my criteria for a winning strategy whereby:

win/loss > risk/reward

in fact these numbers are rather impressive for automated strategies. for the ones i've evaluated it is rare that an actual edge of this sort holds up and rarer still for the edge to be this large. usually i see something like 1.8 for win/loss and 1.7 for risk/reward.

so why the underperformance? 

i think this has to do with the real-world era under comparison. the last 6 months has been an upward trending period for the market. thus, trading underperforms a trending market. perhaps, this is a bit obvious but the market has just come through a decade long era of sideways action. if you are using aiSpy for trading you should think about how long the market might continue trending. if you believe this trend is not done then buy 'n hold is a better strategy otherwise aiSpy should outperform in the next 6 months. i leave it up to you.