Hi All,
First, hats off to all involved in the quantstrat and related projects - very impressive stuff.
I ran the bbands.R example from the demo using the supplied stock.str = 'IBM' and the program ran to completion without a problem. However, when I tried to run the the demo script with stock.str = '^NYA' the program couldn't find the stock data. Looks like the symbol in the portfolio retains the leading '^' but the getSymbol brings in the data and uses NYA as the symbol.
The following shows the input and error message
suppressWarnings(rm("order_book.bbands",pos=.strategy))
suppressWarnings(rm("account.bbands","portfolio.bbands",pos=.blotter))
suppressWarnings(rm("account.st","portfolio.st","stock.str","stratBBands","initDate","initEq",'start_t','end_t'))
stock.str='^NYA' # what are we trying it on
SD = 2 # how many standard deviations, traditionally 2
N = 20 # how many periods for the moving average, traditionally 20
stock(stock.str,currency='USD',multiplier=1)
initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
initAcct(account.st,portfolios='bbands', initDate=initDate)
initOrders(portfolio=portfolio.st,initDate=initDate)
stratBBands <- strategy("bbands")
stratBBands <- add.indicator(strategy = stratBBands, name = "BBands",
+ arguments = list(HLC = quote(HLC(mktdata)), maType='SMA'))
stratBBands <- add.signal(stratBBands,name="sigCrossover",
+ arguments = list(columns=c("Close","up"),relationship="gt"),label="Cl.gt.UpperBand")
stratBBands <- add.signal(stratBBands,name="sigCrossover",
+ arguments = list(columns=c("Close","dn"),relationship="lt"),label="Cl.lt.LowerBand")
stratBBands <- add.signal(stratBBands,name="sigCrossover",
+ arguments = list(columns=c("High","Low","mavg"),relationship="op"),label="Cross.Mid")
stratBBands <- add.rule(stratBBands,name='ruleSignal', arguments = list(sigcol="Cl.gt.UpperBand",sigval=TRUE, orderqty=-100, ordertype='market', ord .... [TRUNCATED]
stratBBands <- add.rule(stratBBands,name='ruleSignal', arguments = list(sigcol="Cl.lt.LowerBand",sigval=TRUE, orderqty= 100, ordertype='market', ord .... [TRUNCATED]
stratBBands <- add.rule(stratBBands,name='ruleSignal', arguments = list(sigcol="Cross.Mid",sigval=TRUE, orderqty= 'all', ordertype='market', ordersi .... [TRUNCATED]
getSymbols(stock.str,from=initDate)
out<-try(applyStrategy(strategy=stratBBands , portfolios='bbands',parameters=list(sd=SD,n=N)) )
Error in get(symbol) : object '^NYA' not found
print("strat execution time:")
[1] "strat execution time:"
Time difference of 0.00999999 secs
updatePortf(Portfolio='bbands',Dates=paste('::',as.Date(Sys.time()),sep=''))
Error in get(Symbol, envir = as.environment(.GlobalEnv)) :
?object '^NYA' not found
In addition: Warning messages:
1: In getInstrument(symbol) :
?instrument ^NYA not found, please create it first.
2: In getInstrument(Symbol) :
?instrument ^NYA not found, please create it first.
3: In .updatePosPL(Portfolio = pname, Symbol = as.character(symbol), ?:
?Instrument ^NYA ?not found, things may break
Any insights would be appreciated.
Dan Avery