[ENH] Support cumulative on-level factors in ParallelogramOLF - #1181
Conversation
Adds a cumulative flag to ParallelogramOLF and parallelogram_olf so that a rate history can be stated as cumulative on-level factors instead of incremental rate changes. Each factor is in force from its effective date until the next one, and the earliest factor extends backwards to cover the lookback window. The implied rate level is the reciprocal of the factor, so all downstream logic (rolling average, vertical_line, leap year handling, current rate level normalization) is unchanged. Refs #922
Pyright Type CompletenessView the full Project (full
Other symbols referenced but not exported by
Symbols without documentation:
Patch (exported symbols added or changed by this PR): 0.0% fully typed (0 / 6)
Patch symbol details
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fbf8e6b. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1181 +/- ##
==========================================
+ Coverage 91.14% 91.17% +0.03%
==========================================
Files 91 91
Lines 5365 5395 +30
Branches 681 688 +7
==========================================
+ Hits 4890 4919 +29
Misses 340 340
- Partials 135 136 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Addresses two Cursor Bugbot findings on #1181. (1) The cumulative branch reindexed factors onto the calendar grid before ffill/bfill, dropping any factor whose effective date was off-grid or predated the triangle window (start_date is anchored to X.origin[0]); replaced with a backward/asof match via searchsorted so each factor stays in force from its date until the next and the earliest extends back. (2) _combine_duplicate_dates multiplied cumulative factors sharing a date; cumulative factors are absolute levels, so last-wins instead. Added tests for a factor predating the window and duplicate-date last-wins.
Addresses two Cursor Bugbot findings on #1181. (1) The cumulative branch reindexed factors onto the calendar grid before ffill/bfill, dropping any factor whose effective date was off-grid or predated the triangle window (start_date is anchored to X.origin[0]); replaced with a backward/asof match via searchsorted so each factor stays in force from its date until the next and the earliest extends back. (2) _combine_duplicate_dates multiplied cumulative factors sharing a date; cumulative factors are absolute levels, so last-wins instead. Added tests for a factor predating the window and duplicate-date last-wins.

Summary of Changes
Adds a
cumulativeflag toParallelogramOLFandparallelogram_olfso a rate history can be given as cumulative on-level factors instead of incremental rate changes.cumulative=False(default) is the current behavior, fully backwards compatible.cumulative=Truereadschange_colas cumulative factors: each is in force from its effective date to the next, the earliest extends back over the lookback window, and the rate level is1/factor. Rolling average,vertical_line, and leap-year handling are unchanged. Non-positive factors raise aValueError.So the tort example drops the gymnastics:
Related GitHub Issue(s)
closes #922
Also completes a follow-up from #1180 (Chapter 10): its Exhibit II tort step can drop the
[-0.1067, -0.25]conversion for a clean[0.67, 0.75, 1.0]withcumulative=True.Additional Context for Reviewers
New tests in
test_parallelogram.py: the issue's tort example, a cumulative-vs-incremental equivalence check acrossM/Dgrain andvertical_lineTrue/False, and a non-positive-factor guard.uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)Note
Medium Risk
Touches premium on-leveling math in a widely used estimator, but the new path is opt-in and covered by equivalence and edge-case tests against the incremental implementation.
Overview
Adds
cumulativetoParallelogramOLFandparallelogram_olfso rate history can use cumulative rate-level factors (e.g.0.67,0.75,1.00) instead of converting to incremental decimals. Defaultcumulative=Falsekeeps existing behavior.With
cumulative=True, each factor applies from its effective date until the next; the earliest factor extends backward over the lookback window.parallelogram_olfmaps factors to implied rate levels via1/factor, uses backward/asof matching on the internal calendar, and rejects non-positive factors. Rolling averages,vertical_line, and leap-year handling stay the same._combine_duplicate_datesnow collapses same-date rows withlast()for cumulative factors (incremental mode still compounds withprod). Docs and tests cover the GH #922 tort example, cumulative vs incremental agreement across grains, pre-window factors, and duplicate effective dates.Reviewed by Cursor Bugbot for commit b5c84ca. Bugbot is set up for automated code reviews on this repo. Configure here.