Skip to content

Commit

Permalink
Merge pull request #753 from bashtage/fix-exog-forecast
Browse files Browse the repository at this point in the history
DOC: Improve explanation for exog forecasts
  • Loading branch information
bashtage authored Nov 4, 2024
2 parents d00198e + 75d0cc5 commit cc9fb9b
Show file tree
Hide file tree
Showing 12 changed files with 480 additions and 3,230 deletions.
19 changes: 19 additions & 0 deletions arch/tests/univariate/test_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,3 +1205,22 @@ def test_forecast_simulation_horizon_1():
res = mod.fit(first_obs=0, last_obs=98)
res.forecast(start=1, x=x, method="simulation", simulations=2)
res.forecast(start=1, x=x, method="simulation", simulations=1)


def test_forecast_start():
rg = np.random.default_rng(0)
y = rg.standard_normal(10)
x = pd.DataFrame(rg.standard_normal((10, 1)), columns=["x"])
mod = ARX(y, x=x, lags=3)
res = mod.fit(first_obs=0, last_obs=98)
fcast = res.forecast(start=2, x=x.shift(-1))
fcast2 = res.forecast(start=2, method="simulation", simulations=1, x=x.shift(-1))
assert_allclose(fcast.mean, fcast2.mean)

c, p1, p2, p3, b, _ = res.params
oos = np.full((8, 1), np.nan)
for i in range(2, 9):
oos[i - 2, 0] = (
c + p1 * y[i] + p2 * y[i - 1] + p3 * y[i - 2] + b * x.iloc[i + 1, 0]
)
assert_allclose(fcast.mean, oos)
4 changes: 3 additions & 1 deletion arch/univariate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,8 @@ def forecast(
with a horizon of 10, then the input can be (1, 10). Alternatively,
if the original data had 1000 observations, then the input can be
(1000, 10), and only the final row is used to produce forecasts.
When using an (nobs, horizon) array, the values much be aligned
so that all values in row t are all out-of-sample at time-t.
* A dictionary of 2-d array-like: This format is identical to the
previous except that the dictionary keys must match the names of
the exog variables. Requires that the exog variables were
Expand All @@ -1014,7 +1016,7 @@ def forecast(
Due to the complexity required to accommodate all scenarios, please
see the example notebook that demonstrates the valid formats for
x.
x, and discusses alignment.
.. versionadded:: 4.19
Expand Down
302 changes: 53 additions & 249 deletions examples/bootstrap_examples.ipynb

Large diffs are not rendered by default.

183 changes: 23 additions & 160 deletions examples/multiple-comparison_examples.ipynb

Large diffs are not rendered by default.

505 changes: 33 additions & 472 deletions examples/unitroot_cointegration_examples.ipynb

Large diffs are not rendered by default.

479 changes: 61 additions & 418 deletions examples/unitroot_examples.ipynb

Large diffs are not rendered by default.

601 changes: 165 additions & 436 deletions examples/univariate_forecasting_with_exogenous_variables.ipynb

Large diffs are not rendered by default.

230 changes: 16 additions & 214 deletions examples/univariate_using_fixed_variance.ipynb

Large diffs are not rendered by default.

310 changes: 46 additions & 264 deletions examples/univariate_volatility_forecasting.ipynb

Large diffs are not rendered by default.

861 changes: 39 additions & 822 deletions examples/univariate_volatility_modeling.ipynb

Large diffs are not rendered by default.

214 changes: 21 additions & 193 deletions examples/univariate_volatility_scenarios.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jupyter
notebook
nbconvert
sphinx-autodoc-typehints

pickleshare

0 comments on commit cc9fb9b

Please sign in to comment.