r - Quantstrat logical error while running applySignals - missing value where TRUE/FALSE needed -


i having error while running strategy back-testing in r, using quantstrat package. whenever, try use applysignals function test signals, shows logical error. tried remove nas na.omit(fb) command, when calculate simple moving average, have nas in beginning. can suggest me solution?

thanks,

require(performanceanalytics) require(quantstrat) require(quantmod) require(blotter)  initdate="2015-01-01" from="2015-01-02" to="2015-06-30"  options(width=100)  currency('usd') sys.setenv(tz="utc")  symbols = c("spy", "fb", "twtr")  getsymbols(symbols, from=from, to=to, src="yahoo", adjust=true)  stock(symbols, currency="usd", multiplier=1)    suppresswarnings(rm("account.mac","portfolio.mac",pos=.blotter)) suppresswarnings(rm("order_book.mac",pos=.strategy))   tradesize <- 1000 initeq <- tradesize  strategy.st <- portfolio.st <- account.st <- "mac" rm.strat(strategy.st) initportf(portfolio.st, symbols=symbols, initdate=initdate, currency='usd') initacct(account.st, portfolios=portfolio.st, initdate=initdate, currency='usd', initeq=initeq) initorders(portfolio.st, initdate=initdate) strategy(strategy.st, store=true)  #parameters   nfast = 10 nslow = 30   #indicators  add.indicator(strategy.st, name="sma",               arguments=list(x=quote(cl(mktdata)[,1]), n=nfast),               label="nfast")  add.indicator(strategy.st, name="sma",               arguments=list(x=quote(cl(mktdata)[,1]), n=nslow),               label="nslow")  test <- applyindicators(strategy.st, mktdata=cl(fb)) head(test, 5)   #signals   add.signal(strategy.st, name="sigcrossover",            arguments=list(columns=c("nfast", "nslow"), relationship="gt"),            label="longentry")  add.signal(strategy.st, name="sigcrossover",            arguments=list(columns=c("nfast", "nslow"), relationship="lt"),            label="longexit")  test2 <- applysignals(strategy.st, mktdata=cl(fb))  error: error in if (length(j) == 0 || (length(j) == 1 && j == 0)) { :    missing value true/false needed 

i able solve issue code.

so, if use mktdata object instead of mktdata = cl(fb), quantstrat working fine. not able understand why working way, somehow worked fine.

test2 <- applysignals(strategy.st, mktdata) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -