r - "Error in mktdata[, keep] : number of dimensions incorrect " due to stock "T" referring to TRUE? -
i have problem when trying run example of quantstrat on stock at&t referred symbole "t". believe because r somewhere thinking t refering true. here code:
library(quantstrat) ticker="t" total_hist.start = as.date("2006-06-22") total_hist.end = as.date("2008-06-20") total_hist = total_hist.end - total_hist.start currency("usd") stock(ticker,currency="usd",multiplier=1) getsymbols(ticker,from=total_hist.start,to=total_hist.end,to.assign=true) init.date = initdate=total_hist.start-1 strat.name<- "mystrat" port.name <- "myport" acct.name <- "myacct" tradesize = 1000 initeq=as.numeric( tradesize*max(ad(get(ticker)) ) ) port <- initportf(port.name,ticker,initdate=init.date) acct <- initacct(acct.name,portfolios=port.name, initdate=init.date, initeq=initeq) ords <- initorders(portfolio=port.name,initdate=init.date) strat<- strategy(strat.name) strat<- add.indicator(strategy = strat, name = "sma", arguments = list(x=quote(ad(mktdata)), n=20),label= "ma20" ) strat<- add.indicator(strategy = strat, name = "sma", arguments = list(x=quote(ad(mktdata)), n=50),label= "ma50") strat<- add.signal(strat,name="sigcrossover",arguments = list(columns=c("ma20","ma50"),relationship="gte"),label="ma20.gt.ma50") strat<- add.signal(strat,name="sigcrossover",arguments = list(column=c("ma20","ma50"),relationship="lt"),label="ma20.lt.ma50") strat<- add.rule(strategy = strat,name='rulesignal', arguments = list(sigcol="ma20.gt.ma50",sigval=true, orderqty=tradesize, ordertype='market', orderside='long', pricemethod='market'),type='enter', path.dep=true) strat<- add.rule(strategy = strat,name='rulesignal', arguments = list(sigcol="ma20.lt.ma50",sigval=true, orderqty='all', ordertype='market', orderside='long', pricemethod='market'),type='exit', path.dep=true) out<-try(applystrategy(strategy=strat, portfolios=port.name)) i error message:
error in mktdata[, keep] : nombre de dimensions incorrect i tried stock agilent technologies who's symbol "a" , don't error sure problem coming fact t true. help!
your problem isn't in quantstrat, in getsymbols
> head(t) [1] true > get('t') [1] true > getsymbols(t,from=total_hist.start,to=total_hist.end,to.assign=true) error in do.call(paste("getsymbols.", symbol.source, sep = ""), list(symbols = current.symbols, : not find function "getsymbols.true" > getsymbols('t',from=total_hist.start,to=total_hist.end,to.assign=true) [1] "t" > head(t) t.open t.high t.low t.close t.volume t.adjusted 2006-06-22 27.34 27.44 27.13 27.29 14123800 19.85 2006-06-23 27.15 27.61 27.05 27.37 10474500 19.91 2006-06-26 27.32 27.53 27.19 27.33 11311200 19.88 2006-06-27 27.38 27.49 27.29 27.35 9869100 19.89 2006-06-28 27.27 27.44 27.24 27.41 14853300 19.94 2006-06-29 27.42 27.79 27.42 27.70 17314300 20.15 one workaround instead:
stock('att',currency='usd') ticker<-'att' att<-getsymbols('t',from=total_hist.start,to=total_hist.end,auto.assign=false) this avoid t/f confusion in r true/false (which horrible idea, imo).
regards,
- brian
Comments
Post a Comment