I'm having some trouble getting equity pricing data into R. I have a list of over 4k symbols, and some are no longer active/ valid. I was using an lapply with get.hist.quote on the list, but some bad tickers stopped it in its tracks too much for it to be a practical approach. Following this post: l_ply: how to pass the list's name attribute into the function? and attempting to use the accepted answer is the seemingly best approach I can find, but it isn't working. The l_ply doesn't load any symbols into my workspace. I get these warnings:
Warning messages:
1: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
downloaded length 90279 != reported length 200
2: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
downloaded length 87827 != reported length 200
3: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
downloaded length 89737 != reported length 200
The code from the post cited above that I'm trying to use is below. Is there a fix to this? I'm seeing other postings regarding similar situations, but fixes such as this one aren't working for me. If anyone else has a good way for me to get daily data on many tickers, I'm open to all suggestions. Thanks in advance.
library(quantmod)
library(plyr)
symbols <- c("MSFT","C","MMM")
#1
l_ply(symbols, function(sym) try(getSymbols(sym)))
symbols <- symbols[symbols %in% ls()]
#2
sym.list <- llply(symbols, get)
#3
data <- xts()
for(i in seq_along(symbols)) {
symbol <- symbols[i]
data <- merge(data, get(symbol)[,paste(symbol, "Close", sep=".")])
}