Just another way to do what Josh said...

A very recent addition to the 'instrument' function (for which 'stock' is a
wrapper),
is that if you provide a 'src' argument, it will call setSymbolLookup for
you.

> currency('USD')
[1] "USD"
> stock.str='^NYA'
> stock.str <- stock(toupper(gsub("\\^","",stock.str)), currency='USD',
src=list(name=stock.str,src='yahoo'))
> stock.str
[1] "NYA"
> getSymbols(stock.str)
[1] "NYA"

Regards,
Garrett

On Sat, Sep 17, 2011 at 7:42 PM, Joshua Ulrich <josh.m.ulrich@gmail.com>wrote:

> Hi Dan,
>
> You can do this with quantmod::setSymbolLookup.  It's mentioned in the
> See Also section of ?getSymbols.  I mention this because it's my
> favorite section to find functionality I may not be aware of.
>
> Something like this should do the trick:
> setSymbolLookup(NYA=list(name="^NYA",src="yahoo"))
> stock.str <- "NYA"
>
> Best,
> --
> Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
>
>
>
> On Sat, Sep 17, 2011 at 7:20 PM, Dan Avery <DAvery@marketingleverage.com>
> wrote:
> > 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
> >
> > ________________________________________
> > _______________________________________________
> > R-SIG-Finance@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions
> should go.
> >
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

