Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* add additional berquist sherman test

* #537

---------

Co-authored-by: connor dietrich <connor@MacBook-Pro-2.local>
  • Loading branch information
cdietrich215 and connor dietrich authored Jan 14, 2025
1 parent 6e71f98 commit 2ea3c1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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)

0 comments on commit 2ea3c1d

Please sign in to comment.