【发布时间】:2018-06-20 20:06:02
【问题描述】:
我正在编写一个代码来从 S&P500 收集数据。我确实得到了我需要的数据,但现在我为每只股票都有一个 xts 对象,我想将其转换为一个大 data.frame,因此我可以运行事件研究或创建图表。
url <- "https://en.wikipedia.org/wiki/List_of_S%26P_500_companies"
tables <- getURL(url)
tables <- readHTMLTable(tables, stringsAsFactors = F)
sp500symbols <- tables[[1]][,1:2]
head(sp500symbols)
rm(list="tables", "url")
tix <- c(sp500symbols$`Ticker symbol`)
quantmod_list = tix
for(company in quantmod_list) {
try(getSymbols(company, from="2009-12-29", to="2009-12-30"))
print(company)
}
【问题讨论】:
-
欢迎来到 Stack Overflow!为了给您一个很好的答案,如果您还没有看过How to Ask,它可能会对我们有所帮助。如果您可以提供minimal reproducible example,它可能也很有用。