Rolling regression xts object in R

你说的曾经没有我的故事 提交于 2019-11-29 12:10:01

Your rollapply call should call a function that returns the t-values. Right now it returns a lm object, which is not a valid value for the coredata of a zoo object.

Make your function only return the t-values and it will work.

library(quantmod)
getSymbols("SPY;IEF")
x <- merge(Cl(SPY),Cl(IEF))
f <- function (x) {
  res <- coef(summary(lm(x ~ time(x))))
  sapply(res, "[" ,"(Intercept)"  ,"t value")
}
r <- rollapplyr(x, 100, f, by.column=FALSE)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!