Skip to content
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

BerquistSherman class paid adjustment causes NaN's[BUG] #537

Open
cdietrich215 opened this issue Jul 17, 2024 · 6 comments
Open

BerquistSherman class paid adjustment causes NaN's[BUG] #537

cdietrich215 opened this issue Jul 17, 2024 · 6 comments
Assignees
Labels

Comments

@cdietrich215
Copy link

cdietrich215 commented Jul 17, 2024

Describe the bug
I believe the BerquistSherman class's paid adjustment has a bug (this probably some lesser used functionality again). This error occurs in the lookup array defined in line 127.

The procedure selects regression parameters (a and b) within the same AY, based on how close the adjusted closed claim count is to the raw closed claim counts in the row, as described in the Friedland paper, page 289. However, in this implementation, if the adjusted closed count is higher than the max of the AY row's unadjusted closed counts, this lookup produces a value that extends into the "lower triangle". This causes nan values for the a and b parameters, as well as the resulting paid loss values.

There should be a ceiling on the lookup values corresponding to the final regression in the AY row. This can be done after lookup is defined in line 143:

n = lookup.shape[-1]
for j in range(n - 1):
    lookup[:, :, j, :] = np.clip(lookup[:, :, :, j], 0,  n - j - 1)

Hope this makes sense - will try to produce an example at some point. Happy to help implement this.

@cdietrich215 cdietrich215 changed the title BerquistSherman class paid adjustment NaN's[BUG] BerquistSherman class paid adjustment causes NaN's[BUG] Jul 17, 2024
@cdietrich215
Copy link
Author

@jbogaardt I would be happy to help contribute on this or some of the other issues I brought up, let me know if that would be an option!

@jbogaardt
Copy link
Collaborator

@cdietrich215 , contributions are very welcome! Please contribute if you can! Any PR will be tested against the existing test suite. If you can keep those in a passing state, things should be good. Happy to provide further pointers on setting up a development environment (or alternatively you can reference https://chainladder-python.readthedocs.io/en/latest/library/contributing.html)

@cdietrich215
Copy link
Author

Sounds good, was able to get the environment set up. Will make a PR on this soon.

@cdietrich215
Copy link
Author

@jbogaardt Do I need additional permissions to do so? I'm getting permission denied errors when attempting to push a new branch: remote: Permission to casact/chainladder-python.git denied to cdietrich215.

@cdietrich215
Copy link
Author

cdietrich215 commented Jan 2, 2025

Additionally, this will replicate the error mentioned above. The code in the feature branch I'll push should prevent the issue.

import chainladder as cl
triangle = cl.load_sample("berqsherm").loc['MedMal']
xp = triangle.get_array_module()
# Purposefully cause negative closed development towards the end for demonstration
triangle.loc["MedMal", "Closed", "1969" , 84] = triangle.loc["MedMal", "Closed", "1969" , 72] * 0.9
triangle.loc["MedMal", "Closed", "1969" , 96] = triangle.loc["MedMal", "Closed", "1969" , 84] * 0.9
triangle.loc["MedMal", "Closed", "1970" , 84] = triangle.loc["MedMal", "Closed", "1970" , 72] * 0.9

berq = cl.BerquistSherman(
    paid_amount='Paid', incurred_amount='Incurred',
    reported_count='Reported', closed_count='Closed',
    trend=0.15)
# Transform triangle
berq_triangle = berq.fit_transform(triangle)

@jbogaardt
Copy link
Collaborator

Hi @cdietrich215,

You wouldn't be able to push anything directly to casact/chainladder-python without being a project maintainer. However, this is easy to resolve.

To submit a pull request (PR) to any public repository on GitHub, fork the repository, create a new branch on your fork, make your changes, commit them, push the changes to your fork, then navigate to the repository on GitHub and initiate a pull request by selecting the "Compare & pull request" option, choosing the appropriate branches, and providing a descriptive title and explanation for your changes; the repository maintainers will then review your PR and decide whether to merge your changes into the main codebase.

cdietrich215 pushed a commit to cdietrich215/chainladder-python-paid_bs_fix that referenced this issue Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants