I am using the Quantmod package in R for some data analysis. Now I can downbload price history of particular stocks or index with the following code:-

library(quantmod) # Loading quantmod library

getSymbols("^DJI", from = as.character(Sys.Date()-365*3))

I want to download all the ticker symbols that are composite of a particular Index such as DJI for example. What will be the best way to do that through R?

Thanks a lot in advance.


You need the components. You could use yahoo or cnn site, and read the table from that. Then get the tickers. Read all to an environment and work with the data.

urlt <- "http://money.cnn.com/data/dow30/" 
doc.html = htmlTreeParse(urlt, useInternal = TRUE)
tables <- readHTMLTable(doc.html,as.data.frame=FALSE)
tables <- readHTMLTable(doc.html,
                        stringsAsFactors=FALSE,which = 2)

#ticker <- as.vector(as.character(ticker))
StockData <- new.env()
data <- getSymbols(ticker, env = StockData)
do.call(merge, eapply(StockData, Cl)[ticker])
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.