Reputation: 135
I am currently facing a problem regarding the pulling of data in R.
With the getSymbols()
function I can already obtain data for each Dow Jones company.
For example, this gives me the data for apple from a chosen start_date
until end_date
:
getSymbols("AAPL", src = "yahoo", from = start_date, to = end_date
However I would somehow like to pull the data for all 30 companies. I dont want to do every company manually, so I was wondering if there is any way to pull the data all at once. So far I have not found any information regarding my problem.
I would be very thankfull for any help.
Upvotes: 0
Views: 90
Reputation: 269694
Try this. Replace dow
with the appropriate vector.
library(quantmod)
dow <- c("AAPL", "BA", "CAT")
getSymbols(dow, dow.env <- new.env())
ls(dow.env)
# [1] "AAPL" "BA" "CAT"
head(dow.env$AAPL)
## AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
## 2007-01-03 12.32714 12.36857 11.70000 11.97143 309579900 10.41635
## 2007-01-04 12.00714 12.27857 11.97429 12.23714 211815100 10.64755
## 2007-01-05 12.25286 12.31428 12.05714 12.15000 208685400 10.57173
## 2007-01-08 12.28000 12.36143 12.18286 12.21000 199276700 10.62393
## 2007-01-09 12.35000 13.28286 12.16429 13.22429 837324600 11.50647
## 2007-01-10 13.53571 13.97143 13.35000 13.85714 738220000 12.05711
unlist(eapply(dow.env, nrow))
## CAT AAPL BA
## 3250 3250 3250
Upvotes: 1