This will download dividend data for multiple stocks, each in a separate variable. The R data file names are the name of the stock followed by ".div". I.e., for Microsoft, the file would be "MSFT.div".
require(quantmod)
DJ30_symbols.ls <- c("MSFT", "IBM")
nDiv <- length(DJ30_symbols.ls)
for (i in 1:nDiv) {
cat("Downloading ", i, " out of ", nDiv, "\n")
getDividends(DJ30_symbols.ls[i], from = "1970-01-01", to = Sys.Date())
}
When i try to save the individual files as a csv file in my working directory, as follows:
write.zoo(paste(DJ30_symbols.ls[i], ".div", sep=' '),
file = paste(DJ30_symbols.ls[i], ".csv", sep=''), index.name = "date")
I save files, but the data saved is not the dividends downloaded from Yahoo, but the symbol name (e.g. "MSFT.div"). I get the downloaded dividend information in a csv file if I do:
write.zoo(MSFT.div, file = "MSFT_div.csv", index.name = "date")
Is there any way I can use the variable names to read the data and save the files?