# 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)
This code returns me an error because of
return(c(supp, rest))
at the end of a.ari.fun()
function I wrote; I'm sure about that because if a.ari.fun()
returns just
return(rest)
it works fine.
How do I have to arrange the a.ari.fun()
in order to obtain an object suitable to rollapplyr()
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…