Skip to content

fix(capecod): include on-level factor in exposure weighting (#1308, #1319) - #1339

Open
priyam0k wants to merge 3 commits into
mainfrom
fix/issue-1308-capecod-onlevel
Open

fix(capecod): include on-level factor in exposure weighting (#1308, #1319)#1339
priyam0k wants to merge 3 commits into
mainfrom
fix/issue-1308-capecod-onlevel

Conversation

@priyam0k

@priyam0k priyam0k commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Included sample weight on-level factors in the Cape Cod weighted exposure calculation so premium rate changes are properly reflected in the a priori loss ratio.
  • Updated Friedland Chapter 10 Exhibit II to use native CapeCod on-level functionality directly in the pipeline instead of manual pandas steps.
  • Fixed notebook lint issues in Chapter 10 and removed its grandfathered ignore entry from pyproject.toml.
  • Added a unit test validating Cape Cod with both rate level changes and tort reform against textbook values.

Related GitHub Issue(s)

Additional Context for Reviewers

All pre-commit ruff checks and tests pass cleanly.

Checklist

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run --directory docs jb build . --builder=custom --custom-builder=doctest)

Note

Medium Risk
Changes core Cape Cod apriori math for any fit with on-leveled sample_weight, which directly shifts derived loss ratios and ultimates; scope is narrow and guarded by new textbook reconciliation tests.

Overview
Cape Cod now multiplies used-up exposure by the sample-weight on-level factor (sw_olf_array) when building weighted_exposure for the all-years apriori, so rate-level adjustments on earned premium affect the weighted loss ratio the same way they already did in the loss numerator.

A regression test reproduces Friedland Chapter 10 Exhibit II (rate parallelogram on premium, tort OLF on losses, floored development, trend) and checks apriori, detrended_apriori_, and total ultimate. The Chapter 10 notebook is updated to drive Exhibit II through a Pipeline and model outputs (detrended_apriori_, expectation_, ibnr_, ultimate_) instead of hand-rolled detrending; minor formatting fixes allow dropping the notebook’s ruff grandfather entry in pyproject.toml.

Reviewed by Cursor Bugbot for commit a98795e. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Sep 11, 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.1% of exported symbols fully typed (208 / 1381)

Known Ambiguous Unknown Total
Project (head) 208 111 1062 1381

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: 327
  • Functions without default param: 0
  • Classes without docstring: 10

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

Known Ambiguous Unknown Total
Patch 0 0 1 1
Patch symbol details
Symbol Status Change
chainladder.methods.tests.test_capecod.test_capecod_onlevel_friedland_exhibit_ii ❌ unknown new

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.79%. Comparing base (d7479a4) to head (a98795e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1339      +/-   ##
==========================================
+ Coverage   91.76%   91.79%   +0.03%     
==========================================
  Files          96       96              
  Lines        5475     5475              
  Branches      706      706              
==========================================
+ Hits         5024     5026       +2     
+ Misses        327      326       -1     
+ Partials      124      123       -1     
Flag Coverage Δ
unittests 91.79% <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.

Comment thread chainladder/methods/tests/test_capecod.py Outdated
tort_history, change_col="rate_change", date_col="date", vertical_line=True
)

floored_patterns = dict(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

try Triangle.maximum

Comment thread chainladder/methods/tests/test_capecod.py Outdated
@henrydingliu henrydingliu self-assigned this Sep 11, 2026
…1319)

- Fix CapeCod._get_capecod_aprioris to weight exposure by on-level factors (sw_olf_array)

- Refactor Friedland Chapter 10 Exhibit II to route through CapeCod._onlevel natively

- Add test_capecod_onlevel_friedland_exhibit_ii to test_capecod.py
@priyam0k
priyam0k force-pushed the fix/issue-1308-capecod-onlevel branch from c89009b to a98795e Compare September 11, 2026 12:02
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.

[REFACTOR] Friedland Chapter 10 CapeCod on-leveling and add tests [BUG] Potential Bug in Capecod

2 participants