Skip to content

BUG: Simulate a single in-sample step in ETS get_prediction - #10930

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-ets-simulated-one-step
Nov 22, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-ets-simulated-one-step

Conversation

@bashtage

Copy link
Copy Markdown
Member

With method="simulated" (the default for models with multiplicative
components), ETSResults.get_prediction simulates each in-sample
prediction one step ahead and the out-of-sample predictions from the end
of the sample. The one-step simulations ran only if nsmooth > 1, so a
prediction with exactly one in-sample period skipped it:

  • with no out-of-sample periods, for example
    get_prediction(start=10, end=10, method="simulated"), there was no
    simulation at all and it raised "ValueError: need at least one array
    to concatenate";
  • with out-of-sample periods, for example a multiplicative model's
    get_prediction(start=nobs - 1, end=nobs + 3), the simulations
    started one period late, so pred_int() and summary_frame() raised
    "Shape of passed values is (4, 2), indices imply (5, 2)" and
    var_pred_mean had 4 values for 5 predictions.

Changes:

  • The one-step simulations run for any number of in-sample periods
    (if nsmooth > 0).

Results that were returned before do not change: predictions with two
or more in-sample periods, or none, take the same path as before.
var_pred_mean in the second case above now has a value for every
prediction.

Tests: test_get_prediction_simulated_one_step covers a single in-sample
period at the start of the sample (simulated from the initial states)
and in the middle, and one in-sample period followed by four forecasts
for an additive and a multiplicative model. It checks the summary frame
against the one-step prediction plus the simulated errors, drawn from
the same generator, and against simulate from the end of the sample
for the forecasts. All four cases fail on main.

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code (Claude Opus 5.5).
    Used for: finding the bug in a contract audit, writing the fix and its tests, and checking them (tests failing on main, mutation check).
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

🤖 Generated with Claude Code

With `method="simulated"` (the default for models with multiplicative
components), `ETSResults.get_prediction` simulates each in-sample
prediction one step ahead and the out-of-sample predictions from the end
of the sample. The one-step simulations ran only `if nsmooth > 1`, so a
prediction with exactly one in-sample period skipped it:

- with no out-of-sample periods, for example
  `get_prediction(start=10, end=10, method="simulated")`, there was no
  simulation at all and it raised "ValueError: need at least one array
  to concatenate";
- with out-of-sample periods, for example a multiplicative model's
  `get_prediction(start=nobs - 1, end=nobs + 3)`, the simulations
  started one period late, so `pred_int()` and `summary_frame()` raised
  "Shape of passed values is (4, 2), indices imply (5, 2)" and
  `var_pred_mean` had 4 values for 5 predictions.

Changes:

- The one-step simulations run for any number of in-sample periods
  (`if nsmooth > 0`).

Results that were returned before do not change: predictions with two
or more in-sample periods, or none, take the same path as before.
`var_pred_mean` in the second case above now has a value for every
prediction.

Tests: `test_get_prediction_simulated_one_step` covers a single in-sample
period at the start of the sample (simulated from the initial states)
and in the middle, and one in-sample period followed by four forecasts
for an additive and a multiplicative model. It checks the summary frame
against the one-step prediction plus the simulated errors, drawn from
the same generator, and against `simulate` from the end of the sample
for the forecasts. All four cases fail on main.
@bashtage
bashtage force-pushed the wip-ets-simulated-one-step branch from 27b5a4c to 6fcf444 Compare November 22, 2026 14:04
@bashtage
bashtage marked this pull request as ready for review November 22, 2026 19:01
@bashtage
bashtage merged commit caf8903 into statsmodels:main Nov 22, 2026
11 of 12 checks passed
@bashtage
bashtage deleted the wip-ets-simulated-one-step branch November 22, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant