I am trying to get data for the 1632 stocks that comprise the NSE index in India using the quantmod
package. I am able to download stocks individually; however, when I loop over all the stocks, I am getting a timeout. How do I loop the getSymbols
function to download the desire data?
Following error is reported:
Error: '20MICRONS.NS' download failed after two attempts. Error message: HTTP error 404. 5. stop(Symbols.name, " download failed after two attempts. Error", " message:\n", attr(dl, "condition")$message, call. = FALSE) 4. getSymbols.yahoo(Symbols = "'20MICRONS.NS'", env = , verbose = FALSE, warnings = TRUE, auto.assign = TRUE) 3. do.call(paste("getSymbols.", symbol.source, sep = ""), list(Symbols = current.symbols, env = env, verbose = verbose, warnings = warnings, auto.assign = auto.assign, ...)) 2. getSymbols(as.character(x), src = "yahoo") 1. f(Symbol[i])
MyData <- read.csv(file="C:/Documents/EQUITY_L.csv", header=TRUE)
Symbol <- MyData$SYMBOL
f <- function(x) { getSymbols(as.character(x), src='yahoo') }
for (i in 1:1632) { f(Symbol[i]) }
20MICRONS.NS
in the error message looks suspicious. I had no problem runningquantmod::getSymbols("20MICRONS.NS")
on my machine just now. If you think you a pause between downloads would help, you can add a two second pause in each iteration of your loop withSys.sleep(2)
. To dig in further, I would need to see what's in the "Equity_L.csv" file. – DanY