Skip to content

[ENH] Support cumulative on-level factors in ParallelogramOLF - #1181

Merged
henrydingliu merged 3 commits into
mainfrom
feature/issue-922-cumulative-olf
Aug 6, 2026
Merged

[ENH] Support cumulative on-level factors in ParallelogramOLF#1181
henrydingliu merged 3 commits into
mainfrom
feature/issue-922-cumulative-olf

Conversation

@priyam0k

@priyam0k priyam0k commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Summary of Changes

Adds a cumulative flag to ParallelogramOLF and parallelogram_olf so 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=True reads change_col as 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 is 1/factor. Rolling average, vertical_line, and leap-year handling are unchanged. Non-positive factors raise a ValueError.

So the tort example drops the gymnastics:

# before
"RateChange": [(0.67 / 0.75) - 1, 0.75 - 1, 0.00]
# after
"Factor": [0.67, 0.75, 1.00]  # cumulative=True

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] with cumulative=True.

Additional Context for Reviewers

New tests in test_parallelogram.py: the issue's tort example, a cumulative-vs-incremental equivalence check across M/D grain and vertical_line True/False, and a non-positive-factor guard.

  • I passed tests locally for both code (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 cumulative to ParallelogramOLF and parallelogram_olf so rate history can use cumulative rate-level factors (e.g. 0.67, 0.75, 1.00) instead of converting to incremental decimals. Default cumulative=False keeps 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_olf maps factors to implied rate levels via 1/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_dates now collapses same-date rows with last() for cumulative factors (incremental mode still compounds with prod). 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.

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
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

Pyright Type Completeness

View the full pyright --verifytypes output for this commit

Project (full chainladder package, at this PR's head): 15.0% of exported symbols fully typed (196 / 1311)

Known Ambiguous Unknown Total
Project (head) 196 111 1004 1311

Other symbols referenced but not exported by chainladder: 13

Known Ambiguous Unknown Total
Other (head) 3 1 9 13

Symbols without documentation:

  • Functions without docstring: 316
  • Functions without default param: 0
  • Classes without docstring: 10

Patch (exported symbols added or changed by this PR): 0.0% fully typed (0 / 6)

Known Ambiguous Unknown Total
Patch 0 1 5 6
Patch symbol details
Symbol Status Change
chainladder.adjustments.parallelogram.ParallelogramOLF.cumulative ⚠️ ambiguous new
chainladder.adjustments.tests.test_parallelogram.test_cumulative_duplicate_date_last_wins ❌ unknown new
chainladder.adjustments.tests.test_parallelogram.test_cumulative_factor_predates_window ❌ unknown new
chainladder.adjustments.tests.test_parallelogram.test_cumulative_matches_incremental ❌ unknown new
chainladder.adjustments.tests.test_parallelogram.test_cumulative_rejects_non_positive ❌ unknown new
chainladder.adjustments.tests.test_parallelogram.test_cumulative_tort_reform ❌ unknown new

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread chainladder/utils/utility_functions.py Outdated
Comment thread chainladder/adjustments/parallelogram.py Outdated
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.17%. Comparing base (10abe53) to head (b5c84ca).
⚠️ Report is 20 commits behind head on main.

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     
Flag Coverage Δ
unittests 91.17% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.
Comment thread chainladder/utils/utility_functions.py
@priyam0k
priyam0k marked this pull request as draft August 5, 2026 13:55
@priyam0k
priyam0k marked this pull request as ready for review August 6, 2026 08:21
@henrydingliu
henrydingliu merged commit 19a50e8 into main Aug 6, 2026
15 checks passed
henrydingliu pushed a commit that referenced this pull request Aug 6, 2026
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.
@henrydingliu
henrydingliu deleted the feature/issue-922-cumulative-olf branch August 6, 2026 15:18
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.

cl.ParallelogramOLF to support cumulative factors

2 participants