Part A — make the per-day overlay loop O(1)-amortised (bit-EXACT, no numeric change):
- `_regime_lookback`: build the NaN matrix over only the last 2·L_min days (the rest of `rep`
is never read) + look up the ≤20 tail days directly instead of scanning each sleeve's full
dict. O(active·L_min) not O(active·D). Bit-identical (same numpy ops on the same values).
- `paper_book_returns` + `IncrementalRiskOverlay`: feed `adaptive_target_vol` a running list
(`out_vals`) mirroring `out`'s chronological values, instead of rebuilding `list(out.values())`
(O(D)) every day. Bit-identical (same values, same order; only the [-win:] tail is read).
Keeps `paper_book_returns`'s exact `==` golden (the live==replay regime signal) untouched.
Part B — separate the expensive overlay from the cheap knobs (instant slider drags):
- `overlay_pass(returns, sleeves, controller, kelly, start, end) -> OverlayPass`: the EXPENSIVE
half (per-day weights/eff_lev/killed/gross_ret/eff_w). kelly stays here — it does NOT factor
out linearly (clamped by max_leverage + sizes the killswitch's regime signal).
- `apply_knobs(OverlayPass, capital, cost_bps) -> SimResult`: the CHEAP half (~3ms on full
history); capital + cost_bps are the genuinely-cheap knobs. Bit-identical to full simulate_book.
- `simulate_book` composes the two internally; signature + behaviour unchanged.
Timing: full ~1473-day run ~1.7s -> ~1.15s; cheap capital/cost re-apply ~3ms (was ~1.2s/tick).
Tests (TDD): frozen pre-optimization golden (full SimResult, abs_tol 1e-9, 4 controller/kelly/
cost/capital combos); cheap-reapply == full simulate_book (bit-exact) over many knob combos;
overlay-pass capital/cost-independence; perf bounds (full <1.6s, cheap <50ms). Full suite green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>