download companywise s&p 500 stock price data in R

2.5k views Asked by At

I can download companywise s&p 500 stock price data by using this code

require(quantmod)
getSymbols(c("MSFT", "AAPL", "GOOGL"), auto.assign = TRUE, from = "2005-01-05",src="google")

Now it is diffiult to type all 500 tickers like "MSFT", "AAPL", "GOOGL" this. Is there any solution to avoid this.

1

There are 1 answers

1
cephalopod On

use tidyquant library
tq_index("SP500")
tq_get_stock_index_options gives you indexes you can download
https://github.com/business-science/tidyquant