-3

I am trying to use getSymbols (quantmod) package in R to download stock prices from a list of stocks that I have in a .csv file.

I have the .csv file imported into R but unsure on how to use getSymbols to read from a .csv file

So I have my list of stock symbols and I want getSymbols to download the price data for each symbol in the list.

user1016078
  • 103
  • 1
  • 4
  • 14
  • What code did you try? What didn't work? Was there an error (if so, what was the `traceback()`)? What is your `sessionInfo()`? – Joshua Ulrich Oct 20 '12 at 12:44

1 Answers1

3

The only difficulty I see is that getSymbols takes a character vector as inputs, not a factor. So you'll have to be careful and use stringsAsFactors = FALSE when reading your symbols from a file:

csv <- read.csv(textConnection("

SYMBOLS
IBM
GOOG
YHOO

"), stringsAsFactors = FALSE)

library(quantmod)
getSymbols(csv$SYMBOLS)
# [1] "IBM"  "GOOG" "YHOO"

Alternatively, if you already have your symbols in a factor named x, you can run getSymbols(as.character(x)).

flodel
  • 87,577
  • 21
  • 185
  • 223