[R] Download multiple stock quotes in a loop

Vladimir Eremeev wl2776 at gmail.com
Thu Jul 26 12:51:45 CEST 2007

Owe Jessen wrote:
> Hi all,
> this should be a simple question, but I haven't been able to do it 
> right. I am trying to download multiple stock quotes in a loop, so that 
> every timeseries is safed with the symbol of the stock. Can anybody help 
> me out? Here's the code:
> require(tseries)
> startd <- "2000-06-01"
> stocks <- c("bmw.de", "vow.de", "dte.de")
> for(stock in stocks)
> stock <- as.timeSeries(get.hist.quote(instrument=stock, start=startd, 
> quote="Close", compress="d"))
> }
> Thanks in advance,
> Owe

The variable stock is assigned values twice in the cycle.
First, it gets the value of "bmw.de", and immediately after that it is
assigned with the result returned by as.timeSeries(  ... )

If you replace the interior of the loop with the

  assign(paste("stock.",stock,sep=""), as.timeSeries(get.hist.quote  [etc]))

you will get three variables, namely, stock.bmw.de, stock.vow.de and
View this message in context: http://www.nabble.com/Download-multiple-stock-quotes-in-a-loop-tf4150838.html#a11808177
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list