0
$\begingroup$

i am using the GARCH package in Python to forecast volatility of the SPX Index. According to the documentation, there are two arguments "first_obs" and "last_obs"

first_obs({int, str, datetime, Timestamp}) – First observation to use when fixing model

last_obs({int, str, datetime, Timestamp}) – Last observation to usewhen fixing mode

I tried testing out-of-sample with increasing observations by applying a rolling window forecast using the last_obs argument as follows

am = arch_model(returns["SPX"].dropna(), mean = 'Zero', vol='Garch', p=1, o=0, q=1, dist='Normal')
forecasts = {}
for i in range(1500,len(returns["SPX"])):
    sys.stdout.write('.')
    sys.stdout.flush()
    res = am.fit(last_obs=i, disp='off')
    temp = res.forecast(horizon=1).variance
    fcast = temp.iloc[i]
    forecasts[fcast.name] = fcast

Comparing this to a real out-of-sample forecast using

Sigma=pd.Series(index=returns["SPX"].index)
for t in range(1500,len(returns["SPX"])):
    am = arch_model(returns["SPX"].dropna()[:t], mean = 'Zero', vol='Garch', p=1, o=0, q=1, dist='Normal')
    res = am.fit(disp='off')
    omega = res.params[0]
    alpha = res.params[1]
    beta = res.params[2]

    sigma2 = res.forecast().variance["h.1"][-1:].values[-1]
    Sigma.iloc[t]=sigma2
    Sigma=Sigma.shift(1)

There are slight differences, sometimes even larger

               Last_obs  Rolling
2010-11-22     NaN        NaN
2010-11-23     NaN      0.000114
2010-11-24  0.000109    0.000108
2010-11-25  0.000121    0.000122
2010-11-26  0.000117    0.000117
... ... ...
2020-07-27  0.000180    0.000180
2020-07-28  0.000203    0.000203
2020-07-29  0.000184    0.000184
2020-07-30  0.000166    0.000163
2020-07-31  0.000150    0.000152

Vol Comparison

Am i using it wrong?

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.