Good morning, I have a problem in R. I am fitting an ARIMA and GARCH model on the interest rates of the FED. The problem is as follows. The ugarchspec
function does not allow me to specify the differencing parameter I of the ARIMA, but only the AR and MA parameters. Consequently, I differenced the series myself, so my forecasts are differenced forecasts. Now I need to undifference them, but I can’t get what I want.
h<-12
n <- length(test)
pred <- rep(NA, n)
up_int<-rep(NA, n)
low_int<-rep(NA, n)
autoplot(ts_diff)
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(1, 1), include.mean = F), distribution.model = "std")
fit <- ugarchfit(spec, data = ts_diff[train])
for (i in 1:n) {
train_up <- c(train, test[1:i])
fit_coef<-getspec(fit)
setfixed(fit_coef)<-as.list(coef(fit));
forecast_up <- ugarchforecast(fit_coef, data=ts[train_up],n.ahead = h)
pred[i] <- forecast_up@forecast$seriesFor[h]
sigma<- forecast_up@forecast$sigmaFor[h]
#de-diff
pred[i] <- ts[test[i+h-1]]+ pred[i]
up_int[i] <- pred[i] + qstd(0.975, mean=0, sd=1,nu=4) * sigma
low_int[i] <- pred[i] - qstd(0.975, mean=0, sd=1,nu=4) * sigma
}
I tried to undifference as in the code, but obviously this is not correct because I am differencing using the last observed observation. In reality, I wouldn’t have this possibility. Theoretically, I should apply this slide but I am a bit confused on how to proceed. I thought of creating a function with a for loop inside it, but I’m having trouble building it. Do you have any ideas?