Files
fxhnt/tests
jgrusewski 7d9c329921 perf(paper): accumulate sleeve returns in-memory in backfill (O(N^2)->O(N) DB)
backfill_paper_book re-queried repo.sleeve_returns(before=date) on every date
of the ascending loop, re-fetching the entire growing per-sleeve return history
each date (O(N^2) DB round-trips, the dominant cost on a multi-year backfill).
The loop already computes each date's per-sleeve return at the bottom, so seed
an accumulator once with the history strictly before the first date and append
each computed return after that date's overlay runs. Identical values + same
strictly-before causality => identical results, O(N) DB.

paper_risk_overlay (+ isv_adaptive_weights / paper_book_returns /
vol_target_leverage / _regime_lookback / _waterfill) verified read-only over
returns_by_sleeve, so the shared accumulator is passed un-copied (no per-date
deep copy that would reintroduce O(N^2)).

Tests: perf invariant (sleeve_returns queried exactly once) + behaviour-unchanged
(accumulator == per-date strictly-before DB requery for every date). Full suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 18:12:09 +02:00
..