bashtage / arch

ARCH models in Python
Other
1.32k stars 245 forks source link

`arch_model` estimator is forecasting same value irrespective of the `horizon` parameter. #685

Closed Vasudeva-bit closed 11 months ago

Vasudeva-bit commented 11 months ago

The arch_model estimator from arch is forecasting same value irrespective of the horizon parameter.

# packages to be installed to reproduce the following behavior
# ! pip install arch
# ! pip install sktime
import pandas as pd
from sktime.datasets import load_airline
y = load_airline()
from arch import arch_model
model = arch_model(y, rescale=True)
model = model.fit(disp='off')
result = model.forecast(horizon=5)
print(result.mean.values[-1])

Output [20.2404549 20.2404549 20.2404549 20.2404549 20.2404549]

bashtage commented 11 months ago

You are seeing constant values because for a constant mean and you are seeing the mean forecasts (which are by construction constant). If you want to look at the forecast variances, you should look at the variances attribute.

In your case:

You are looking at the wrong value. result.variance is what you want.

print(result.variance.values[-1])
[530.57831213 534.01591322 537.4535143  540.89111539 544.32871648]

Or in a more traditional dataset:

from arch.data import sp500

y = sp500.load()["Adj Close"].pct_change().dropna()
model = arch_model(y, rescale=True)
model = model.fit(disp='off')
result = model.forecast(horizon=5)
print(result.variance)
                h.1       h.2       h.3       h.4       h.5
Date
2018-12-31  3.59647  3.568502  3.540887  3.513621  3.486701
Vasudeva-bit commented 11 months ago

Oh! Thanks for clarification.