[英]I can't get the xts object in rstudio
我使用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()的返回结果是字符,但是我需要xts objcet,谢谢,我不知道该如何获取。
getSymbols(identifier,src =“ yahoo”,从=“ 2007-01-01”,到=“ 2016-12-31”,auto.assign = FALSE)添加auto.assign = FALSE,此问题已解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.