[R] pass character vector in instrument field of get.hist.quote function
David Winsemius
dwinsemius at comcast.net
Sat Mar 12 22:46:21 CET 2011
On Mar 12, 2011, at 3:08 PM, algotr8der wrote:
> 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)
No, you did not. You need to make an assignment of any result, AND you
need to reference the column name:
tickers$V1 <- as.character(tickers$V1)
You should also have reference the package from which get.hist.quote
was being used.
--
david.
>
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list