[R] pass character vector in instrument field of get.hist.quote function

algotr8der algotr8der at gmail.com
Sat Mar 12 21:08:41 CET 2011


I am new to R so I apologize if my question is trivial. I have not been able
to figure out whether what I want to do is even possible.

I have a data frame of stock ticker symbols which I store into R space from
a txt file as follows:

tickers <- read.csv("stocks.txt", header=FALSE, sep=",") 
tickers <- tickers[1]     / the tickers are stored in the first column 

> tickers 
    V1 
1 BCSI 
2 WBSN 
3 NTAP 
4 FFIV 
5   SU 

> is.vector(tickers) 
[1] FALSE 
> 
> is.data.frame(tickers) 
[1] TRUE 

I tried to do the following without success.

stockdata <- data.frame()
stockdata <- coredata(get.hist.quote(instruments=tickers,
start="2011-01-01", end="2011-01-31", quote=c("Close"), provider="yahoo")) 

Error in get.hist.quote(instruments = tickers, start = "2011-01-01", end =
"2011-01-31",  : 
  unused argument(s) (instruments = tickers) 

So I coerced the data stored in 'tickers' to be a character as follows:

> as.character(tickers)

Then I tried to execute get.hist.quote as above with the same erro.

stockdata <- coredata(get.hist.quote(instruments=tickers,
start="2011-01-01", end="2011-01-31", quote=c("Close"), provider="yahoo")) 

Error in get.hist.quote(instruments = tickers, start = "2011-01-01", end =
"2011-01-31",  : 
  unused argument(s) (instruments = tickers) 

I dont want to use loops because of inefficiencies. I know in Matlab I can
take advantage of the matrix/vector environment by passing a variable as a
vector. I think there should be a clean way to do what I want to do. I have
1500+ tickers and I dont want to cycle through each of them in a loop.

I would greatly appreciate some guidance.

--
View this message in context: http://r.789695.n4.nabble.com/pass-character-vector-in-instrument-field-of-get-hist-quote-function-tp3350779p3350779.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list