私は次の分析にこだわっています。
library(quantstrat)
stock_size = 200
tickers = c("XOM", "MCD")
init.date = as.Date("2008-01-01")
usd = "USD"
currency(usd)
for(ticker in tickers){
stock(ticker, currency=usd, multiplier = 1)
}
options("getSymbols.warning4.0"=FALSE)
getSymbols(tickers,from=init.date,to.assign=TRUE)
suppressWarnings(rm(strat, port, acct, ords))
port.name <- "MyPort"
port <- initPortf(port.name,tickers,initDate=init.date)
acct.name <- "MyAcct"
acct <- initAcct(acct.name,portfolios=port.name, initDate=init.date, initEq=35000)
ords <- initOrders(portfolio=port.name,initDate=init.date)
strat.name <- "MyStrat"
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=stock_size, 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))
charts.PerformanceSummary()
このいくつかのエラーが発生したため:
Error in `colnames<-`(`*tmp*`, value = c("XOM.Adjusted.SMA.50", "XOM.Adjusted.SMA.20.ma20.SMA.50" :
length of 'dimnames' [2] not equal to array extent
Error in inherits(x, "xts") : argument "R" is missing, with no default
誰が間違っているかを見つけるのを手伝ってくれますか?