Repository navigation
[FEAT] Add one-year CDR standard errors to MackChainladder #1558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
530b699
Add one-year CDR standard errors to MackChainladder
scks1 8a7832d
Merge the CDR tests into test_mack.py
scks1 8fdc25e
Address review of the one-year CDR standard errors
scks1 740379d
Restore the mw2014 test, against Merz and Wüthrich (2014)
scks1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a blocker to approval. but just curious if you tried to do this through the triangle api, without falling back to numpy manipulation. we try to be intentional and comprehensive with our pandas passthroughs, groupby aggregations, and basic dunders. this is a good live test of how comprehensive triangle arithmetic is.. and whatever you can't easily accomplish here through the triangle api, we should raise as issue to contemplate adding to the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it. A version of
_get_cdr_msepwritten only with Triangle operations (origin sums, a valuation filter for the latest diagonal,latest_diagonal,shiftalong both axes,fillzeroand arithmetic) gives the same figures as the numpy code: the same NaN cells and a largest relative difference of 1.7e-16 on mw2008 (cumulative, incremental, one missing cell), mw2014, raa and clrd by LOB, numpy and sparse. It is 8.5 to 17 times slower per call (235–484 ms against 27–29 ms; the most on the 17-year mw2014). I have it on a local branch and can push it if you want to see it.What got in the way:
Triangle.cumsumraisesTypeError: nancumsum() got an unexpected keyword argument 'keepdims'along either axis and aftergroupby, so sums over later periods became shift loops ([BUG] Triangle.cumsum raises TypeError: nancumsum() got an unexpected keyword argument 'keepdims' #1573).X.cdf_.align_pattern(X)is all NaN without a tail ([BUG] Sparse arithmetic with a one-origin Triangle fills only the first origin when development lengths differ #1574). I kept both operands at the same length instead.latest_diagonalraises until the date is reset ([BUG] Arithmetic with a pattern gives the result the pattern's valuation date #1575).shifton a pattern stores the "12-24" labels asddims, which breaksdevelopment([BUG] shift on a pattern stores its display labels as development, and development then raises TypeError #1576).*keeps zeros while+and-turn them into NaN, so the missing-cell check needed acomplete / completemask. That is the zero/NaN question of cl.Triangle legitimate zeros converted to NaN #181, so I didn't open another issue.Given the speed, I'd keep numpy here and revisit once those are fixed, but I can switch if you'd rather have the Triangle version now.
(This reply was made with Árbol, an AI assistant, under my direction.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep numpy version
only 4 bugs is better than i expected. the ~10x speed degradation is worse than i expected. is it loops?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do: the PR stays on the numpy version (740379d).
Mostly loops, plus one slow property. Taking the fastest of 15 calls on the numpy backend, the Triangle version ran 232 ms against 28 ms for numpy on mw2008 (9×9), and 447 ms against 29 ms on mw2014 (17×17).
.valuesbrings the call to 105 / 122 ms, so they are 62% / 78% of the gap.valuation: on triangles with valuation dates on the development axis (latest_diagonal,ultimate_) it builds a DataFrame and callsunstack, which costs 2.5 / 3.9 ms against 0.04 ms on the original triangle, and+and-call it up to twice throughnan_triangle. It accounted for 42% / 53% of the profiled time. Building the same index with a singlenp.repeatand no DataFrame brings the call to 159 / 248 ms, with identical results.+takes about 0.5 ms where the numpy add takes about 1 µs.The
valuationchange should help arithmetic on any triangle with valuation dates on its development axis, so I can open a separate issue for it.(This reply was made with Árbol, an AI assistant, under my direction.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please open an issue on the valuation change.
thanks for the investigation! please keep the triangle version around, which we can land after dealing with those bugs. we need more corpus on the triangle API.