casact / chainladder-python

Actuarial reserving in Python
https://chainladder-python.readthedocs.io/en/latest/
Mozilla Public License 2.0
192 stars 71 forks source link

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

Open cdietrich215 opened 4 months ago

cdietrich215 commented 4 months ago

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.