Repository navigation
Description
Are you on the latest chainladder version?
- Yes, this bug occurs on the latest version (main at c113fd9: chainladder 0.10.1).
Describe the bug in words
Dropping the oldest origins from a triangle leaves it with more development ages than origins, and every method on it then fails. Development().fit succeeds, but its ldf_ has 9 columns of values and only 7 age labels, so the first cdf_ call fails in nan_triangle (core/base.py L512). Chainladder, MackChainladder, BornhuetterFerguson and a Pipeline all fail the same way, as do raa[raa.origin >= "1982"] and genins[genins.origin >= "2004"].
The labels come from X.link_ratio.ddims in Development._param_property (development.py L568). link_ratio keeps only ratios dated before the valuation date (triangle.py L1350-L1351), and that filter drops the link-ratio columns no origin has reached yet (96-108 and 108-120 here). The ldf_ values keep one column per link ratio, 9 in all.
Mack (1993, ASTIN Bulletin 23(2), 213-225, p. 214) estimates each factor from the origins observed at both ages, so a subset of origins is still a valid triangle. On origins 1983-1990, a numpy chain ladder gives factors 3.166717, 1.709347, 1.245174, 1.15799, 1.093401, 1.033812 and 1.026374, no data after 96 months, and an IBNR of 44,554.44 with a factor of 1 after that. Chainladder gives the same 44,554.44 once the two empty ages are trimmed.
Setting obj.ddims = X.ddims[:-1] at L568 fixes it in a local copy: the repro below gives 44,554.44 without the trim, raa[raa.origin >= "1982"] gives 54,901.61 and genins[genins.origin >= "2004"] gives 12,013,150.15, all equal to the numpy chain ladder, and the development, core and methods tests pass. MackChainladder then fits, but total_mack_std_err_ is NaN on the untrimmed triangle and 17,876.64 on the trimmed one: the two ages no origin has reached get NaN factors and sigmas, and WeightedRegression counts -1 degrees of freedom there (weighted_regression.py L171), which also spoils the log-linear sigma fill at 84 months. Giving those ages a factor of 1 and a sigma of 0 makes the untrimmed result equal the trimmed one; I'd raise that separately.
#1304 (head 4559f5c) renames this line to obj.development = X.link_ratio.development and still fails, earlier, at its core/base.py L387 ("Length mismatch: Expected axis has 9 elements, new values have 7 elements"). #1419 merged locally into main does not change the result. #1553's new _ldf_like helper already uses X.ddims[:-1] for this reason. clark.py, munich.py and outstanding.py also take labels from X.link_ratio.ddims. On this shape CaseOutstanding fails the same way (outstanding.py L257), for example on clrd commercial auto origins from 1992, and the same change fixes it: the paid IBNR is then 1,205,826.14, equal to the case outstanding development technique (Friedland, 2010, ch. 12) computed by hand. ClarkLDF returns no factor for the oldest origin's age so its ultimate is NaN, and MunichAdjustment fails earlier, at munich.py L240.
How can the bug be reproduced?
import chainladder as cl
raa = cl.load_sample("raa")
tri = raa[raa.origin >= "1983"] # 8 origins, 10 development ages
dev = cl.Development().fit(tri)
print(dev.ldf_.values.shape, len(dev.ldf_.ddims))
print(cl.Chainladder().fit(tri.iloc[..., :8]).ibnr_.sum()) # drop the two empty ages
cl.Chainladder().fit(tri)(1, 1, 1, 9) 7
44554.4444544517
Traceback (most recent call last):
...
File ".../chainladder/methods/base.py", line 33, in _align_cdf
return X.cdf_.align_pattern(X, sample_weight)
File ".../chainladder/core/common.py", line 117, in cdf_
return self.ldf_.incr_to_cum()
File ".../chainladder/core/triangle.py", line 1519, in incr_to_cum
self.values = values * self.nan_triangle
File ".../chainladder/core/base.py", line 512, in nan_triangle
val_array = np.array(self.valuation).reshape(self.shape[-2:], order="f")
ValueError: cannot reshape array of size 7 into shape (1,9)
What is the expected behavior?
assert len(dev.ldf_.ddims) == dev.ldf_.shape[-1]
assert round(float(cl.Chainladder().fit(tri).ibnr_.sum()), 2) == 44554.44Would you be willing to contribute this ticket?
- Yes, absolutely!
- Yes, but I would like some help.
- No.
(This issue was written with Árbol, an AI assistant, under my direction.)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Scope
Effort
Projects
- StatusShow more project fieldsIn progress
Activity