danielkrizian / strategery

Quant Strategy Specification, Backtesting, Optimization And Statistical Analysis Workflow
10 stars 21 forks source link

Holiday strategy #15

Closed danielkrizian closed 10 years ago

danielkrizian commented 10 years ago
# Tsiakas(2010) tested since 1962 that: preholidays, postholidays, and prelong weekends 
# have significantly higher mean and lower volatility than regular trading days
# whereas postlong weekends have lower mean and higher volatility.

newStrategy("holiday")
Universe("SPX")
require(timeDate)

# on the OHLCV frame, mark preholidays as TRUE, others as FALSE
HOL <- CJ(Instrument=unique(OHLCV$Instrument), 
          Date=as.IDate(holidayNYSE(1800:2015))) [,PreHoliday:=TRUE]
PREHOL <- HOL[OHLCV[,list(Instrument,Date)],roll=-1][is.na(PreHoliday),PreHoliday:=FALSE]

advanceBarsForSig <- 2 # anticipate signal n days in advance
preholiday <- indicator( anticipate(PreHoliday, advanceBarsForSig, pad=F), input=PREHOL)

Long <- (preholiday==TRUE) %position% shares(1)
Neutral <- (preholiday!=TRUE) %position% shares(0)

Backtest()

image

image