【问题标题】:I can't get the xts object in rstudio我无法在 rstudio 中获取 xts 对象
【发布时间】:2018-06-23 05:23:57
【问题描述】:

我使用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,不知道怎么弄,谢谢。

【问题讨论】:

    标签: r core-data xts quantmod


    【解决方案1】:

    getSymbols(标识符, src = "yahoo", from = "2007-01-01",to = "2016-12-31",auto.assign = FALSE) 添加 auto.assign = FALSE,问题已解决

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-05
      • 1970-01-01
      • 2023-02-05
      • 1970-01-01
      • 2016-06-30
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多