我使用getSymbols来获取R中sp500的返回数据,但我不能在Ad()函数中使用xts数据,这是我的代码:
identifiers <- read.csv("sp500.csv",header = FALSE)
getSymbols("GOOG", src = "yahoo", from = "2013-01-02") #Stock: Google
LogRetGOOG = drop(coredata(na.omit(diff(log(lag(Ad(GOOG)))))))
stocks = matrix(nrow = length(LogRetGOOG),ncol = nrow(identifiers))
for (sedol in identifiers$V1) {
getSymbols(sedol, src = "yahoo", from = "2018-01-02") #Stock: Google
# dealead_data <- drop(coredata(na.omit(diff(log(lag(Ad(sedol)))))))
# stocks[,i] = dealead_data
# i <- i + 1
}
i <- 1
for (sedol in objs) {
x <- get(sedol)
# getSymbols(sedol, src = "yahoo", from = "2018-01-02") #Stock:
Google
dealead_data <-
drop(coredata(na.omit(diff(log(lag(as.name(sedol)))))))
stocks[,i] = dealead_data
i <- i + 1
}
as.name()的返回结果是charactor,但是我需要xts objcet,我不知道如何得到它,谢谢。
答案 0 :(得分:0)
getSymbols(identifier,src =“yahoo”,from =“2007-01-01”,to =“2016-12-31”,auto.assign = FALSE) 添加auto.assign = FALSE,问题已解决