【发布时间】:2012-08-18 14:00:06
【问题描述】:
# Loading packages
require(forecast)
require(quantmod)
# Loading OHLC xts object
getSymbols('SPY', from = '1950-01-01')
# Selecting weekly Close prices
x <- Cl(to.weekly(SPY))
# ARIMA(p,d,q) estimation and forecasting function
a.ari.fun <- function(x) {
a.ari <- auto.arima(x = x, d = 1, max.p = 50, max.q = 50, max.P = 50,
max.Q = 50, ic = 'aic', approximation = TRUE)
fore <- forecast.Arima(object = a.ari, h = 4, level = c(.9))
supp <- tail(fore$lower, 1)
rest <- tail(fore$upper, 1)
return(c(supp, rest))
}
# Roll apply ARIMA(p,d,q) in rolling window
rollapplyr(data = tail(x, 800), width = 750, FUN = a.ari.fun)
此代码返回错误是因为
return(c(supp, rest))
在我写的a.ari.fun()函数的末尾;我很确定,因为如果 a.ari.fun() 只返回
return(rest)
效果很好。
我必须如何安排a.ari.fun() 以获得适合rollapplyr() 的对象?
【问题讨论】:
-
您希望输出是什么样的?你可以使用两次rollapply吗?也许this post会给你一些想法?
-
不幸的是,完成所有迭代需要大量时间,我不能重复等待时间;我想要的结果是一个具有 n 行和 2 列的矩阵:第一列包含“supp”时间序列,而第二列包含“rest”时间序列。
-
它看起来与您链接的帖子完全相反:那个朋友有多个输出结果,他只需要一个值;我需要相反的,即多值输出:)