为什么不直接抓取数据,一旦您拥有过去 10 年的数据dplyr
,就可以按日期和符号过滤您想要的行?
您必须安装tidyquant
- install.packages("tidyquant")
。
library(tidyquant)
tickers <- c("PYPL", "GOOG", "SHOP", "NVDA", "MSFT", "SPY") ####### Select the stocks to download
time_from <- "2010-01-01" ####### Starting date
time_to <- "2018-08-03" ####### Ending date
stock_returns_daily <- tickers %>%
tq_get(get = "stock.prices",
from = time_from,
to = time_to)
compare <- stock_returns_daily %>%
group_by(symbol) %>%
select(symbol, date, close) %>%
filter(symbol == c("PYPL", "SPY")) %>% ####### Select the stocks you want to compare to SPY
filter(between(date, as.Date("2015-09-05"),as.Date("2015-09-17"))) ####### Select the date ranges you are interested in
compare
我确信那里有一个更优雅的解决方案,但这或多或少符合您正在寻找的路线?这里的问题是您必须编辑#######
要分析的股票出现的代码行。