I'm trying to get all the price data of DJIA components and combine them into a single dataframe, then export it to a .csv file.
This is what I have currently, but I'm not sure how to proceed.
# dates
fr <- '2010-01-01'
to <- '2022-01-01'
DJIA_list <- c("MMM", "AXP", "AAPL", "BA", "CAT", "CVX", "CSCO", "KO", "DOW", "XOM",
"GS", "HD", "INTC", "IBM", "JNJ", "JPM", "MCD", "MRK", "MSFT","NKE",
"PFE", "PG", "RTX", "TSLA", "TRV", "UNH", "VZ", "V", "WBA", "WMT")
count <- 1
# Getting adjusted prices of assets
for (i in DJIA_list){
asset <- getSymbols(i, src = 'yahoo', from = as.Date(fr), to = as.Date(to), auto.assign = FALSE)
assign(paste0("var_", i), asset[,6])
count <- count + 1
}
I now have a bunch of xts objects named like var_MMM, var_AAPL etc... Not sure how best to deal with them next. I tried to install the qmao add-on but it didn't work for me either.