I want to download all S&P 500 companies daily highest market price data using R. How can I do that?
I want data results to be like this:
Date MSFT AAPL GOOGL
25-01-05 21.03 4.87 88.56
26-01-05 21.02 4.89 94.62
27-01-05 21.10 4.91 94.04
28-01-05 21.16 5.00 95.17
31-01-05 21.24 5.20 97.81
The quantmod provide that functionality.
require(quantmod)
getSymbols(c("MSFT", "AAPL", "GOOGL"), auto.assign = TRUE, from = "2005-01-05",src="google")
Then, just grab the closing price i.e. the second column of each table. It will give you the list of 3 assets closing price.
high = lapply(list(AAPL, GOOGL, MSFT), function(x) x[,2])
In case you need a matrix:
df = data.matrix(as.data.frame(high))