fix(#978): train-only detrend + Almon distributed-lag regression #1040

Merged
bot-backend merged 1 commit from fix/978-almon-adl-regression into main 2026-06-04 06:39:39 +00:00
Collaborator

REOPENED #978 (951-B §9.6).

PART A (leakage fix): backtest --detrend fit ln(units) trend over train+test then split -> test data shaped the detrend -> inflated OOS. _detrend_log now fits trend on TRAIN only + projects (a,b) point-in-time to test. Synthetic-verified leaky != train-only.

PART B (DoD): new regression.py — Almon polynomial distributed-lag (deg2, key_rate lags 0..6) via OLS + manual Newey-West HAC (NO statsmodels) + per-district {best_lag_months,coef,r2,n,per_lag_coef,hac_se} + fallback gate (n<30/R2<0.1/sumbeta>=0) + §9.6 phrase. 31 synthetic-recovery tests. ADVISORY, shipped standalone, wiring DEFERRED (documented) to protect live consumers.

125+31 tests green, ruff clean. Prod backtest re-run pending (couldn't run from worker sandbox). Refs #978

REOPENED #978 (951-B §9.6). PART A (leakage fix): backtest --detrend fit ln(units) trend over train+test then split -> test data shaped the detrend -> inflated OOS. _detrend_log now fits trend on TRAIN only + projects (a,b) point-in-time to test. Synthetic-verified leaky != train-only. PART B (DoD): new regression.py — Almon polynomial distributed-lag (deg2, key_rate lags 0..6) via OLS + manual Newey-West HAC (NO statsmodels) + per-district {best_lag_months,coef,r2,n,per_lag_coef,hac_se} + fallback gate (n<30/R2<0.1/sumbeta>=0) + §9.6 phrase. 31 synthetic-recovery tests. ADVISORY, shipped standalone, wiring DEFERRED (documented) to protect live consumers. 125+31 tests green, ruff clean. Prod backtest re-run pending (couldn't run from worker sandbox). Refs #978
bot-backend added 1 commit 2026-06-04 06:39:35 +00:00
fix(#978): train-only detrend in rate backtest + Almon distributed-lag regression
All checks were successful
Deploy / deploy (push) Successful in 1m9s
Deploy / changes (push) Successful in 5s
Deploy / build-frontend (push) Has been skipped
Deploy / build-backend (push) Successful in 1m29s
Deploy / build-worker (push) Successful in 2m20s
9a845646fd
REOPENED 951-B §9.6.
PART A: fix look-ahead leakage in backtest_rate_sensitivity --detrend. The
ln(units) trend was fit over train+test then split, so test data shaped the
detrend and inflated the OOS hit-rate. _detrend_log now takes fit_n; backtest_tier
fits the trend on TRAIN months only (same split evaluate_oos uses) and projects
(a,b) point-in-time onto test. Default fit_n=None preserves prior behaviour.

PART B (DoD): new app/services/forecasting/regression.py — Almon polynomial
distributed-lag (deg 2) of Δln(district demand) on Δkey_rate lags 0..6 via
OLS-on-Almon-regressors (numpy lstsq) + per-lag reconstruction + manual
Newey-West HAC SEs (NO statsmodels). Output {best_lag_months, coef=long-run
multiplier, x_pct, r2, n, per_lag_coef, hac_se,...}; gate mirrors _elasticity_coef
(n<30 OR R²<0.1 OR Σβ≥0 → fallback); §9.6 phrase from the lag shape. ADVISORY,
shipped standalone (integration point documented), NOT wired — protects the live
compute_rate_sensitivity consumers.

125+31 tests (synthetic known-lag recovery, HAC computed/differs-from-OLS,
fallback gating, no-leakage detrend). ruff clean. Refs #978
bot-backend merged commit 9a845646fd into main 2026-06-04 06:39:39 +00:00
bot-backend deleted branch fix/978-almon-adl-regression 2026-06-04 06:39:39 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#1040
No description provided.