We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d00198e commit 814a754Copy full SHA for 814a754
arch/tests/univariate/test_forecast.py
@@ -1205,3 +1205,22 @@ def test_forecast_simulation_horizon_1():
1205
res = mod.fit(first_obs=0, last_obs=98)
1206
res.forecast(start=1, x=x, method="simulation", simulations=2)
1207
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/mean.py
@@ -918,8 +918,12 @@ def _reformat_forecast_x(
918
f"the original sample size ({self._y.shape[0]}) or the number of "
919
f"forecasts ({self._y.shape[0] - start})."
920
)
921
- if arr.shape[1] > (self._y.shape[0] - start):
922
- arr = arr[:, start:]
+ if arr.shape[1] == self._y.shape[0]:
+ arr = arr[:, start:].copy()
923
+ arr[:, :-1, :] = arr[:, 1:, :]
924
+ # Nan fill last value because true out-of-sample not available
925
+ # When using x same size as original y
926
+ arr[:, -1:, :] = np.nan
927
return arr
928
929
def forecast(
0 commit comments