Skip to content

Commit b2088e8

Browse files
committed
DOC: Improve explanation for exog forecasts
Add additional section to example notebook
1 parent d00198e commit b2088e8

File tree

4 files changed

+601
-171
lines changed

4 files changed

+601
-171
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)
1217+
fcast2 = res.forecast(start=2, method="simulation", simulations=1, x=x)
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/univariate_forecasting_with_exogenous_variables.ipynb

+578-169
Large diffs are not rendered by default.

examples/univariate_volatility_forecasting.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@
711711
"name": "python",
712712
"nbconvert_exporter": "python",
713713
"pygments_lexer": "ipython3",
714-
"version": "3.12.7"
714+
"version": "3.9.20"
715715
}
716716
},
717717
"nbformat": 4,

0 commit comments

Comments
 (0)