compiled 2018-05-31
Brian Peterson:
Proprietary Trading:
Â
Â
Back-testing. I hate it - it's just optimizing over history. You never see a bad back-test. Ever. In any strategy. - Josh Diedesch (2014), CalSTRS
Â
Â
Every trading system is in some form an optimization. - Emilio Tomasini (2009)
Many system developers consider
"I hypothesize that this strategy idea will make money"
to be adequate.
Instead, strive to:
Constraints
Benchmarks
Objectives
Â
To create a testable idea (a hypothesis):
Â
good/complete Hypothesis Statements include:
Filters
Indicators
Signals
Rules
install.packages('devtools') # if you don't have it installed install.packages('PerformanceAnalytics') install.packages('FinancialInstrument') devtools::install_github('braverock/blotter') devtools::install_github('braverock/quantstrat')
stock.str <- 'EEM' currency('USD') stock(stock.str,currency='USD',multiplier=1) startDate='2003-12-31' initEq=100000 portfolio.st='macd' account.st='macd' initPortf(portfolio.st,symbols=stock.str) initAcct(account.st,portfolios=portfolio.st,initEq = initEq) initOrders(portfolio=portfolio.st) strategy.st<-portfolio.st # define the strategy strategy(strategy.st, store=TRUE)
## get data getSymbols(stock.str, from=startDate, adjust=TRUE, src='tiingo')
Â
Far better an approximate answer to the right question, which is often vague, than an exact answer to the wrong question, which can always be made precise. - John Tukey (1962) p. 13
Â
Fail quickly, think deeply, or both?
Â
No matter how beautiful your theory, no matter how clever you are or what your name is, if it disagrees with experiment, it’s wrong. - Richard P. Feynman (1965)
#MA parameters for MACD fastMA = 12 slowMA = 26 signalMA = 9 maType="EMA" #one indicator add.indicator(strategy.st, name = "MACD", arguments = list(x=quote(Cl(mktdata)), nFast=fastMA, nSlow=slowMA), label='_' )
Â
Â
Â
MACD is a two moving average cross system that seeks to measure:
Classical technical analysis, for example only, not widely deployed in production
What do you think you're measuring? A good indicator measures something in the market:
Make sure the indicator is testable:
If your indicator doesn't have testable information content, throw it out and start over.
facts to support or refute
#two signals add.signal(strategy.st, name="sigThreshold", arguments = list(column="signal._", relationship="gt", threshold=0, cross=TRUE), label="signal.gt.zero" ) add.signal(strategy.st, name="sigThreshold", arguments = list(column="signal._", relationship="lt", threshold=0, cross=TRUE), label="signal.lt.zero" )
Signals are often combined:
"\(A\) & \(B\)" should both be true.
This is a composite signal, and serves to reduce the dimensionality of the decision space.
A lower dimensioned space is easier to measure, but is at higher risk of overfitting.
Avoid overfitting while combining signals by making sure that your process has a strong economic or theoretical basis before writing code or running tests
Signals make predictions so all the literature on forecasting is applicable:
add.distribution(strategy.st, paramset.label = 'signal_analysis', component.type = 'indicator', component.label = '_', variable = list(n = fastMA), label = 'nFAST' ) #> [1] "macd" add.distribution(strategy.st, paramset.label = 'signal_analysis', component.type = 'indicator', component.label = '_', variable = list(n = slowMA), label = 'nSLOW' ) #> [1] "macd"
sa_buy <- apply.paramset.signal.analysis( strategy.st, paramset.label='signal_analysis', portfolio.st=portfolio.st, sigcol = 'signal.gt.zero', sigval = 1, on=NULL, forward.days=50, cum.sum=TRUE, include.day.of.signal=FALSE, obj.fun=signal.obj.slope, decreasing=TRUE, verbose=TRUE) #> Applying Parameter Set: 12, 26
sa_sell <- apply.paramset.signal.analysis( strategy.st, paramset.label='signal_analysis', portfolio.st=portfolio.st, sigcol = 'signal.lt.zero', sigval = 1, on=NULL, forward.days=10, cum.sum=TRUE, include.day.of.signal=FALSE, obj.fun=signal.obj.slope, decreasing=TRUE, verbose=TRUE) #> Applying Parameter Set: 12, 26