0
$\begingroup$

I am trying to produce one-step ahead forecast using GARCH in Python using a fixed windows method. I ultimately want to put the code below in a for loop, but this code snippet does not perform as I expect.

egarch = arch_model(train_data, mean='zero', lags=0, vol='EGARCH', p=1, o=1, q=1, dist='normal')
egarch_fit = egarch.fit();
prediction = egarch_fit.forecast(horizon=1);
prediction.variance

I expected the final line to print a numeric value, the one step ahead prediction based on train_data. However, the output I get is a dataframe with many NaN values and the prediction. How do I obtain the numerical forecasts? And how come the length of the returned dataframe is equal to the original sample size and not the size of train_data?

I read the reference (https://arch.readthedocs.io/en/latest/univariate/forecasting.html#arch.univariate.base.ARCHModelForecast) and it makes me believe that a for loop is not necessary to get one-step ahead forecasts based on a fixed window. However, I do not know how to obtain such a result. Furthermore, the code in the reference returns a dataframe, but I prefer a simple array of predictions.

$\endgroup$
0
$\begingroup$

Given mu for mean,and var for variance, next step forecast is:

mu=prediction.mean.iloc[-1,0]
var=prediction.variance.iloc[-1,0]
$\endgroup$
2
  • $\begingroup$ Thank you so much. I do believe there exists a more efficient method without for loop, but this definitely works. $\endgroup$ – Xtiaan Jun 12 '20 at 11:43
  • 1
    $\begingroup$ there's no for loop. "mu for mean" means "mu variable" is used for predicting the mean of the process, not a for loop. $\endgroup$ – alexprice Jun 12 '20 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.