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

#537 #546

Merged
merged 2 commits into from
Jan 14, 2025
Merged

#537 #546

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions chainladder/adjustments/berqsherm.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def fit(self, X, y=None, sample_weight=None):
)
- 1
)

# Don't allow lookup values beyond the final value.
n = min(lookup.shape[-1], lookup.shape[-2])
for j in range(n - 1):
lookup[:, :, j, :] = np.clip(lookup[:, :, j, :], 0, n - j - 2)

a = (
xp.concatenate(
[
Expand Down
24 changes: 24 additions & 0 deletions chainladder/adjustments/tests/test_berqsherm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ def test_preserve_diagonal():
== 0
)
assert berq_triangle != triangle

def test_adjusted_values():
triangle = cl.load_sample("berqsherm").loc["MedMal"]
xp = triangle.get_array_module()
berq = cl.BerquistSherman(
paid_amount="Paid",
incurred_amount="Incurred",
reported_count="Reported",
closed_count="Closed",
trend=0.15,
)
berq_triangle = berq.fit_transform(triangle)

assert np.allclose(
triangle["Reported"].values, berq_triangle["Reported"].values, equal_nan=True
)

# Ensure that the incurred, paid, and closed count columns are as expected
berq_triangle.values[np.isnan(berq_triangle.values)] = 0
assert np.isclose(
berq_triangle["Incurred"].values.sum(), 1126985253.661, atol=1e-2
)
assert np.isclose(berq_triangle["Paid"].values.sum(), 182046766.054, atol=1e-2)
assert np.isclose(berq_triangle["Closed"].values.sum(), 8798.982, atol=1e-2)
Loading