I can't get the xts object in rstudio

I use getSymbols to get the return data of sp500 in R,but i can't use the xts data in Ad() function,here is my code:

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
}

the return result of as.name() is charactor,but I need the xts objcet,I don't know how to get it,thanks.

1 answer

  • answered 2018-01-14 09:56 zili sun

    getSymbols(identifier, src = "yahoo", from = "2007-01-01",to = "2016-12-31",auto.assign = FALSE) add auto.assign = FALSE,the issue was sovled