我想使用tidyquant
包(或任何其他包)从雅虎检索财务数据。
为了检索 Microsoft(索引:MSFT)的收盘价,以下代码可以正常工作:
#load packages
library(tidyquant)
#acquire monthly average stock prices
getSymbols("MSFT", from = "2000-08-01", to = "2021-07-31", src = 'yahoo', periodicity = 'daily')
output <- aggregate(MSFT$MSFT.Close, list(format(index(MSFT), "%Y-%m")), mean)
colnames(output) <- c('ClosingPrice')
#create time series for closing stock prices
price = ts(output$ClosingPrice, frequency=12, start=c(2000,08))
summary(price)
但是,对于检索原油价格(索引:CL=F),它不起作用,因为索引包含特殊字符。更具体地说,我在这里收到一条错误消息:
#acquire monthly average stock prices
getSymbols("CL=F", from = "2000-08-01", to = "2021-07-31", src = 'yahoo', periodicity = 'daily')
output <- aggregate(CL=F$CL=F.Close, list(format(index(MSFT), "%Y-%m")), mean)
有谁知道如何解决这个问题?非常感谢!