Load multiple characters with csv using quantmod

I am trying to download multiple characters using a csv file rather than loading from Yahoo. The source code works fine and uses

load.packages('quantmod')
tickers = spl('TLT,IWM,GLD')
data <- new.env()
getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data,
           auto.assign = T)

when I try to use the code below, however, it leads to "lower index below" errors in the script:

load.packages('quantmod')
tickers = spl('TLT,IWM,GLD')
data <- new.env()
getSymbols(tickers, src="csv", dir= "C:/Users/Admiral/Downloads/",
           env = data, auto.assign = T)

Does anyone have any thoughts why the second code is not working? For verification, I just downloaded csv data from Yahoo and saved locally (windows). I do not get error indexes if I just use a single csv file. I also tried the code below, but I get the same errors later in the script:

setSymbolLookup(tickers=list(src="csv", dir= "C:/Users/Admiral/Downloads/"))
getSymbols(tickers, auto.assign = T, from = '1980-01-01', env=data)
+5
source share
1 answer

I would do it using the FinancialInstrument package

require('quantmod')
require('FinancialInstrument')
tickers <- c("TLT", "IWM", "GLD")
data <- new.env()
getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data)

# Now save the data in a directory
tmpdir <- tempdir()
saveSymbols.common(tickers, tmpdir, env=data)

#remove the data    
rm(list=tickers, pos=data)
ls(data) # see that there is nothing there
# Now load the data back from disk
getSymbols(tickers, src='FI', dir=tmpdir, env=data, split_method='common')
ls(data)

getSymbols.csv, Date 6 (OHLCVA)

#write data to csv files on disk
for (i in seq_along(tickers)) {      
  write.zoo(get(tickers[i], pos=data), file=paste0(tmpdir, "/", tickers[i], ".csv"), sep=",")
}
rm(list=tickers, pos=data) #remove from memory
getSymbols(tickers, src='csv', dir=tmpdir)#, env=data)  #load from csv files
+2

All Articles