Skip to content
Merged
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
51 changes: 32 additions & 19 deletions chainladder/adjustments/berqsherm.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def fit(self, X, y=None, sample_weight=None):
y0 = xp.log(y.values[..., :-1])
y1 = xp.log(y.values[..., 1:])
b = ((x0 * y0 + x1 * y1) / 2 - (x0 + x1) / 2 * (y0 + y1) / 2) / (
(x0 ** 2 + x1 ** 2) / 2 - ((x0 + x1) / 2) ** 2
(x0**2 + x1**2) / 2 - ((x0 + x1) / 2) ** 2
)
a = np.exp((y0 + y1) / 2 - b * (x0 + x1) / 2)

Expand All @@ -206,27 +206,39 @@ def fit(self, X, y=None, sample_weight=None):
# 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)
lookup[:, :, j, :] = np.clip(lookup[:, :, j, :], 0, n - j - 2)

a = (
xp.concatenate([
xp.concatenate(
[a[j:j+1, ..., i, lookup[j, 0, i:i+1, :]] for i in range(lookup.shape[-2])],
axis=-2
)
for j in range(a.shape[0]) # Process each batch independently
], axis=0)
* adj_closed_clm.nan_triangle[None, None, ...]
xp.concatenate(
[
xp.concatenate(
[
a[j : j + 1, ..., i, lookup[j, 0, i : i + 1, :]]
for i in range(lookup.shape[-2])
],
axis=-2,
)
for j in range(a.shape[0]) # Process each batch independently
],
axis=0,
)
* adj_closed_clm.nan_triangle[None, None, ...]
)
b = (
xp.concatenate([
xp.concatenate(
[b[j:j+1, ..., i, lookup[j, 0, i:i+1, :]] for i in range(lookup.shape[-2])],
axis=-2
)
for j in range(b.shape[0]) # Process each batch independently
], axis=0)
* adj_closed_clm.nan_triangle[None, None, ...]
xp.concatenate(
[
xp.concatenate(
[
b[j : j + 1, ..., i, lookup[j, 0, i : i + 1, :]]
for i in range(lookup.shape[-2])
],
axis=-2,
)
for j in range(b.shape[0]) # Process each batch independently
],
axis=0,
)
* adj_closed_clm.nan_triangle[None, None, ...]
)
# Adjust paids
adj_paid_claims = adj_closed_clm * 0 + xp.exp(adj_closed_clm.values * b) * a
Expand All @@ -251,7 +263,8 @@ def fit(self, X, y=None, sample_weight=None):
return self

def transform(self, X):
""" If X and self are of different shapes, align self to X, else
"""
If X and self are of different shapes, align self to X, else
return self.

Parameters
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ select = ["E2", "E4", "E7", "E9", "F", "B018", "UP034", "N802"]
# check can be required without blocking unrelated PRs. Remove entries as
# files are cleaned up.
[tool.ruff.lint.per-file-ignores]
"chainladder/adjustments/berqsherm.py" = ["E226", "E241", "E261"]
"chainladder/adjustments/bootstrap.py" = ["E231", "E721", "E722", "F841"]
"chainladder/adjustments/disposal.py" = ["E226", "E227", "E231", "E251", "E252", "E265", "F401"]
"chainladder/adjustments/tests/test_berqsherm.py" = ["F841"]
Expand Down
Loading