[R-SIG-Finance] QuantStrat Using ^NYA

Dan Avery DAvery at marketingleverage.com
Sun Sep 18 02:20:42 CEST 2011


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

> currency('USD')
[1] "USD"

> stock(stock.str,currency='USD',multiplier=1)
[1] "X.NYA"

> initDate='2006-12-31'

> initEq=1000000

> portfolio.st='bbands'

> account.st='bbands'

> initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
[1] "bbands"

> initAcct(account.st,portfolios='bbands', initDate=initDate)
[1] "bbands"

> 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)
[1] "NYA"

> start_t<-Sys.time()

> out<-try(applyStrategy(strategy=stratBBands , portfolios='bbands',parameters=list(sd=SD,n=N)) )
Error in get(symbol) : object '^NYA' not found

> end_t<-Sys.time()

> print("strat execution time:")
[1] "strat execution time:"

> print(end_t-start_t)
Time difference of 0.00999999 secs

> start_t<-Sys.time()

> 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
   
________________________________________


More information about the R-SIG-Finance mailing list