Skip to content

arima: implement bootstrap prediction intervals in forecast_arima - #1207

Open
Coro (AlejandroCoronadoN) wants to merge 1 commit into
Nixtla:mainfrom
AlejandroCoronadoN:arima-bootstrap-intervals
Open

Coro (AlejandroCoronadoN) wants to merge 1 commit into
Nixtla:mainfrom
AlejandroCoronadoN:arima-bootstrap-intervals

Conversation

@AlejandroCoronadoN

Copy link
Copy Markdown

Summary

forecast_arima(..., bootstrap=True) raised NotImplementedError("bootstrap=True"), even
though the bootstrap simulation infrastructure already exists
(simulate_arima(..., error_distribution="bootstrap"), which resamples the in-sample
residuals). This PR wires that infrastructure in so bootstrap=True produces empirical
prediction intervals instead of raising. Addresses #1191 (the ARIMA part).

What it does

When bootstrap=True, instead of the parametric pred ± q·se formula, forecast_arima
now simulates npaths future sample paths by resampling the fitted residuals
(simulate_arima(..., error_distribution="bootstrap")) and takes the empirical quantiles
for each requested level. This is the standard empirical/bootstrap prediction-interval
method (Hyndman & Athanasopoulos, Forecasting: Principles and Practice; the same approach
as R's forecast::forecast(bootstrap=TRUE)), implemented natively with the library's own
simulate_arima/sample_errors — no external code.

Notes:

  • The caller's future xreg (before the internal drift column is appended) is passed to
    simulate_arima, which adds the drift term itself, so drift is not double-counted.
  • A clear ValueError is raised if the fitted model does not store residuals.
  • Output shape and columns (["80%", "95%"], etc.) match the parametric branch.

Verification

model = AutoARIMA(season_length=1).fit(y).model_
fb = forecast_arima(model, h=12, level=[80, 95], bootstrap=True)   # no longer raises
  • New test test_forecast_arima_bootstrap_intervals: intervals are finite, bracket the
    mean, and the 80% band sits inside the 95% band.
  • All 47 existing tests/test_arima.py tests still pass.
  • ruff check/ruff format clean on the changed lines.

Follow-up

The issue also mentions the bootstrap argument being unused in the ETS path
(pegelsfcast_C). Wiring bootstrap through the ETS interval computation (routing the
analytic classes through the existing simulation path) is more involved and left as a
follow-up so this PR stays focused on the ARIMA NotImplementedError.

forecast_arima(bootstrap=True) raised NotImplementedError despite the bootstrap
simulation infra already existing. Wire simulate_arima(error_distribution=
"bootstrap") so it produces empirical prediction intervals: simulate npaths
future paths by resampling the in-sample residuals and take empirical quantiles.
Adds a regression test.

Addresses Nixtla#1191 (ARIMA part).
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants