Skip to content

[FIX] Label Development and CaseOutstanding patterns with one age per link ratio - #1636

Open
scks1 wants to merge 2 commits into
casact:mainfrom
scks1:fix-development-pattern-labels
Open

scks1 wants to merge 2 commits into
casact:mainfrom
scks1:fix-development-pattern-labels

Conversation

@scks1

@scks1 scks1 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Development._param_property now labels ldf_, sigma_ and std_err_ with X.ddims[:-1], one age per link ratio, instead of X.link_ratio.ddims. link_ratio drops the link-ratio columns that have no ratio before the valuation date, so a triangle with more development ages than origins, such as raa[raa.origin >= "1983"], got 9 parameter values and 7 labels, and every method failed in nan_triangle. CaseOutstanding._set_ldf took its ldf_ labels the same way and now uses X.ddims[:-1] too.

test_origin_subset_with_more_ages_than_origins checks that the labels match the value columns for all three parameters on raa origins from 1982 and from 1983 and on genins origins from 2004, on the numpy and sparse backends, and compares Chainladder's IBNR with a chain ladder computed in the test from the origins observed at both ages (Mack, 1993, p. 214). It fails on main at the label check and passes with the change.

A test of the same name in test_outstanding.py fits CaseOutstanding to clrd commercial auto origins from 1992 and from 1994 and to usauto origins from 2002, checks the labels of ldf_, paid_ldf_ and case_ldf_, and compares the paid IBNR with the case outstanding development technique (Friedland, 2010, ch. 12, Approach 1) computed in the test. It fails on main in fit and passes with the change.

Related GitHub Issue(s)

Closes #1635

AI/LLM Usage

This change was made with Árbol, an AI assistant running on Muse, working under my direction. It found the bug, wrote the change and the test, ran the checks below and drafted this description.

Additional Context for Reviewers

  1. Chainladder IBNR before and after:
Triangle main This PR Hand chain ladder
raa, origins from 1983 ValueError 44,554.44 44,554.44
raa, origins from 1982 ValueError 54,901.61 54,901.61
genins, origins from 2004 ValueError 12,013,150.15 12,013,150.15
raa, origins from 1983, first 8 ages 44,554.44 44,554.44 44,554.44
raa, origins to 1988 25,145.80 25,145.80
raa 52,135.23 52,135.23 52,135.23
  1. [FEAT] Hurlimann Credible Loss Ratio estimator #1553's _ldf_like helper already takes its labels from X.ddims[:-1] for the same reason. [FEAT]deprecate date dims #1304 changes this line to X.link_ratio.development and still fails on these triangles, and [FEAT] IncrementalAdditive Cleanup for Chapter 16 Part 1 #1419 does not change the result.

  2. Paid IBNR after CaseOutstanding before and after:

Triangle main This PR Hand case outstanding development
clrd comauto, origins from 1992 ValueError 1,205,826.14 1,205,826.14
clrd comauto, origins from 1994 ValueError 849,163.92 849,163.92
usauto, origins from 2002 ValueError 61,733,801.04 61,733,801.04
clrd comauto 1,434,089.05 1,434,089.05 1,434,089.05
usauto 68,718,279.63 68,718,279.63 68,718,279.63

The hand computation averages each ratio over the origins observed at both ages, as the estimator does by default, and adds no payment at an age no origin has reached. It matches main on all six clrd lines and on usauto before slicing.

  1. MackChainladder fits after this change, but total_mack_std_err_ is NaN on these triangles, because the ages that no origin has reached get NaN factors and sigmas. That is a separate change and is not in this PR.

The chainladder/development, chainladder/core and chainladder/methods tests pass (1247 passed, 8 skipped; 1238 passed on main), and ruff check and format are clean on the changed files.

Submitter's Checklist

  • I have reviewed and am adhering to the standards outlined in the project Governing Doc.
  • The PR subject title summarizes the changes, with one proper prefix ([FIX], [FEAT], [DOCS], [TST], [CHORE], or [BRK]).
  • I am a human (not a bot), and this PR form is written by a human.

Reviewer's Checklist

  • The implementation addresses the associated issue(s).
  • The implementation is appropriate, maintainable, and follows ARCHITECTURE.md.
  • PR subject title has the proper prefix and the subject is appropriate.
  • Relevant issue(s) are linked.
  • AI/LLM usage is disclosed and appropriate.
  • Documentation and tests are appropriate.
  • CI tests passed, or any failures are acceptable.
  • Leave a comment with the final recommendation (e.g. approve as is, request a secondary review, or flag an area for more review).

Development._param_property took the age labels for ldf_, sigma_ and
std_err_ from X.link_ratio.ddims. link_ratio drops link-ratio columns
with no ratio before the valuation date, so a triangle with more
development ages than origins, such as raa[raa.origin >= "1983"], got
9 parameter values and 7 labels, and every method failed in
nan_triangle. The labels now come from X.ddims[:-1], one per link ratio.

The new test checks the labels on three origin subsets and compares
Chainladder's IBNR with a hand chain ladder (Mack, 1993).

Developed with an AI assistant (Árbol, running Muse).
CaseOutstanding._set_ldf took the age labels for ldf_ from
X.link_ratio.ddims, which drops link-ratio columns with no ratio before
the valuation date. On a triangle with more development ages than
origins, such as comauto origins from 1992 in clrd, fit failed in
nan_triangle (cannot reshape array of size 30 into shape (6,9)). The
labels now come from X.ddims[:-1], as in Development.

The new test checks the labels on three origin subsets and compares the
paid IBNR with a hand case outstanding development (Friedland, 2010,
ch. 12).

Developed with an AI assistant (Árbol, running Muse).
@github-actions

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): 18.1% of exported symbols fully typed (303 / 1676)

Known Ambiguous Unknown Total
Project (head) 303 96 1277 1676

Other symbols referenced but not exported by chainladder: 24

Known Ambiguous Unknown Total
Other (head) 11 1 12 24

Symbols without documentation:

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

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

Known Ambiguous Unknown Total
Patch 0 0 2 2
Patch symbol details
Symbol Status Change
chainladder.development.tests.test_development.test_origin_subset_with_more_ages_than_origins ❌ unknown new
chainladder.development.tests.test_outstanding.test_origin_subset_with_more_ages_than_origins ❌ unknown new

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (c113fd9) to head (d03816d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1636      +/-   ##
==========================================
+ Coverage   95.00%   95.02%   +0.02%     
==========================================
  Files         100      100              
  Lines        6461     6491      +30     
  Branches      820      827       +7     
==========================================
+ Hits         6138     6168      +30     
  Misses        204      204              
  Partials      119      119              
Flag Coverage Δ
unittests 95.02% <100.00%> (+0.02%) ⬆️

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.

@henrydingliu

Copy link
Copy Markdown
Member

this is another one where i'd like to wait for #1304 to land.

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.

[BUG] Chainladder fails on a triangle with more development ages than origins, such as raa[raa.origin >= "1983"]

2 participants