Skip to content

Commit cc9fb9b

Browse files
authored
Merge pull request #753 from bashtage/fix-exog-forecast
DOC: Improve explanation for exog forecasts
2 parents d00198e + 75d0cc5 commit cc9fb9b

12 files changed

+480
-3230
lines changed

arch/tests/univariate/test_forecast.py

+19
Original file line numberDiff line numberDiff line change
@@ -1205,3 +1205,22 @@ def test_forecast_simulation_horizon_1():
12051205
res = mod.fit(first_obs=0, last_obs=98)
12061206
res.forecast(start=1, x=x, method="simulation", simulations=2)
12071207
res.forecast(start=1, x=x, method="simulation", simulations=1)
1208+
1209+
1210+
def test_forecast_start():
1211+
rg = np.random.default_rng(0)
1212+
y = rg.standard_normal(10)
1213+
x = pd.DataFrame(rg.standard_normal((10, 1)), columns=["x"])
1214+
mod = ARX(y, x=x, lags=3)
1215+
res = mod.fit(first_obs=0, last_obs=98)
1216+
fcast = res.forecast(start=2, x=x.shift(-1))
1217+
fcast2 = res.forecast(start=2, method="simulation", simulations=1, x=x.shift(-1))
1218+
assert_allclose(fcast.mean, fcast2.mean)
1219+
1220+
c, p1, p2, p3, b, _ = res.params
1221+
oos = np.full((8, 1), np.nan)
1222+
for i in range(2, 9):
1223+
oos[i - 2, 0] = (
1224+
c + p1 * y[i] + p2 * y[i - 1] + p3 * y[i - 2] + b * x.iloc[i + 1, 0]
1225+
)
1226+
assert_allclose(fcast.mean, oos)

arch/univariate/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ def forecast(
10031003
with a horizon of 10, then the input can be (1, 10). Alternatively,
10041004
if the original data had 1000 observations, then the input can be
10051005
(1000, 10), and only the final row is used to produce forecasts.
1006+
When using an (nobs, horizon) array, the values much be aligned
1007+
so that all values in row t are all out-of-sample at time-t.
10061008
* A dictionary of 2-d array-like: This format is identical to the
10071009
previous except that the dictionary keys must match the names of
10081010
the exog variables. Requires that the exog variables were
@@ -1014,7 +1016,7 @@ def forecast(
10141016
10151017
Due to the complexity required to accommodate all scenarios, please
10161018
see the example notebook that demonstrates the valid formats for
1017-
x.
1019+
x, and discusses alignment.
10181020
10191021
.. versionadded:: 4.19
10201022

examples/bootstrap_examples.ipynb

+53-249
Large diffs are not rendered by default.

examples/multiple-comparison_examples.ipynb

+23-160
Large diffs are not rendered by default.

examples/unitroot_cointegration_examples.ipynb

+33-472
Large diffs are not rendered by default.

examples/unitroot_examples.ipynb

+61-418
Large diffs are not rendered by default.

examples/univariate_forecasting_with_exogenous_variables.ipynb

+165-436
Large diffs are not rendered by default.

examples/univariate_using_fixed_variance.ipynb

+16-214
Large diffs are not rendered by default.

examples/univariate_volatility_forecasting.ipynb

+46-264
Large diffs are not rendered by default.

examples/univariate_volatility_modeling.ipynb

+39-822
Large diffs are not rendered by default.

examples/univariate_volatility_scenarios.ipynb

+21-193
Large diffs are not rendered by default.

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jupyter
3434
notebook
3535
nbconvert
3636
sphinx-autodoc-typehints
37-
37+
pickleshare

0 commit comments

Comments
 (0)