Skip to content

adding support for multi-triangle in mackchainladder#873

Open
henrydingliu wants to merge 1 commit into
mainfrom
#871-mack-fix
Open

adding support for multi-triangle in mackchainladder#873
henrydingliu wants to merge 1 commit into
mainfrom
#871-mack-fix

Conversation

@henrydingliu
Copy link
Copy Markdown
Collaborator

@henrydingliu henrydingliu commented May 28, 2026

Summary of Changes

adding multi-triangle support for mackchainllader
removed a html sample from friedland chapter 7 that was accidentally left in during development

Related GitHub Issue(s)

closes #871

Additional Context for Reviewers

one line fix plus a new test to match

  • 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
Changes Mack standard-error weighting for multi-dimensional triangles; wrong results would affect reserve uncertainty, but scope is one line with a new parity test.

Overview
MackChainladder now builds the trailing weight slice in _get_full_std_err_ with shape matching the triangle’s index and column axes (val.shape[0], val.shape[1]) instead of a fixed (1, 1, …), so batch fits over multi-index triangles get correct full_std_err_ (and downstream Mack risk) per slice.

A new test compares batch full_std_err_ on a multi-triangle CLRD sample to fitting each (index, column) slice alone. Friedland chapter 7 docs drop a stray HTML table and duplicate code block left from development; doctest output stays.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.06%. Comparing base (449b5c1) to head (d473402).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #873      +/-   ##
==========================================
+ Coverage   87.04%   87.06%   +0.02%     
==========================================
  Files          86       86              
  Lines        4986     4987       +1     
  Branches      646      646              
==========================================
+ Hits         4340     4342       +2     
+ Misses        456      455       -1     
  Partials      190      190              
Flag Coverage Δ
unittests 87.06% <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 Sentry.
📢 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.

@genedan
Copy link
Copy Markdown
Collaborator

genedan commented May 28, 2026

@kennethshsu I'd like to take a shot at reviewing this one, I need to gain more experience at the actuarial parts of the package.

@kennethshsu
Copy link
Copy Markdown
Collaborator

kennethshsu commented May 28, 2026

All yours!

Do you guys want to do a review roulette? So we all get about the same amount of PR to review? In addition to spreading the load, it'll also make the package more democratic. Maybe should be part of the CEP?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happened here? Accident?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

i was trying to show gene that regular html doesn't automatically look as nice as ipynb. basically, trying to make .rst visually pleasing would be quite a feat.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ahh ok, I think I'd like a show & tell on this lol... I still don't know what's best.

Anyways I'll shut up here to not hijack the thread and let @genedan do the review.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

we'll have a basis to do a comparison once you are done with your notebook recreation of chapter 8.

@genedan
Copy link
Copy Markdown
Collaborator

genedan commented May 30, 2026

I ran this little snippet to test out the new code and got some warnings:

import chainladder as cl

clrd = cl.load_sample('clrd')
tri = clrd.loc['Agway Ins Co']['IncurLoss','CumPaidLoss']
mack = cl.MackChainladder().fit(tri)
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:120: RuntimeWarning: overflow encountered in exp
  sigma_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:124: RuntimeWarning: overflow encountered in exp
  std_err_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:127: RuntimeWarning: invalid value encountered in multiply
  sigma_ = sigma_ * 0
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:128: RuntimeWarning: invalid value encountered in multiply
  std_err_ = std_err_* 0

I didn't get them in the single-dimension case:

raa = cl.load_sample('raa')
cl.MackChainladder().fit(raa)
Out[25]: MackChainladder()

@genedan
Copy link
Copy Markdown
Collaborator

genedan commented May 30, 2026

I looked through test_mack.py, and I didn't see a test for checking whether MackChainladder.fit() produced the correct values. It would be good to add one (assuming the method produces the correct values using clrd) prior to tackling the warning.

@genedan
Copy link
Copy Markdown
Collaborator

genedan commented May 31, 2026

I have some thoughts about handling warnings in general and how we can test for them, will put them in #840 and would like to hear yours too.

@henrydingliu
Copy link
Copy Markdown
Collaborator Author

I ran this little snippet to test out the new code and got some warnings:

import chainladder as cl

clrd = cl.load_sample('clrd')
tri = clrd.loc['Agway Ins Co']['IncurLoss','CumPaidLoss']
mack = cl.MackChainladder().fit(tri)
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:120: RuntimeWarning: overflow encountered in exp
  sigma_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:124: RuntimeWarning: overflow encountered in exp
  std_err_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:127: RuntimeWarning: invalid value encountered in multiply
  sigma_ = sigma_ * 0
/home/ubuntu/Repos/chainladder-python/chainladder/tails/base.py:128: RuntimeWarning: invalid value encountered in multiply
  std_err_ = std_err_* 0

I didn't get them in the single-dimension case:

raa = cl.load_sample('raa')
cl.MackChainladder().fit(raa)
Out[25]: MackChainladder()

that's because there's a boatload of empty triangles in clrd.

tri = cl.load_sample('clrd').loc['Agway Ins Co']['IncurLoss','CumPaidLoss']
for i in range(len(tri.index)):
    for j in range(len(tri.columns)):
        cl.MackChainladder().fit(tri.iloc[i,j])
/Workspace/Users/henry.liu1@zurichna.com/CL_Dev/chainladder-python/chainladder/tails/base.py:120: RuntimeWarning: overflow encountered in exp
  sigma_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/Workspace/Users/henry.liu1@zurichna.com/CL_Dev/chainladder-python/chainladder/tails/base.py:124: RuntimeWarning: overflow encountered in exp
  std_err_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/Workspace/Users/henry.liu1@zurichna.com/CL_Dev/chainladder-python/chainladder/tails/base.py:127: RuntimeWarning: invalid value encountered in multiply
  sigma_ = sigma_ * 0
/Workspace/Users/henry.liu1@zurichna.com/CL_Dev/chainladder-python/chainladder/tails/base.py:128: RuntimeWarning: invalid value encountered in multiply
  std_err_ = std_err_* 0

@henrydingliu
Copy link
Copy Markdown
Collaborator Author

I looked through test_mack.py, and I didn't see a test for checking whether MackChainladder.fit() produced the correct values. It would be good to add one (assuming the method produces the correct values using clrd) prior to tackling the warning.

there is in the doctest. i can copy them into test_mack

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.

mackchainladder doesn't work on multi-triangles

3 participants