diff --git a/chainladder/tails/bondy.py b/chainladder/tails/bondy.py index 9c97fefa3..5fbf1b1a3 100644 --- a/chainladder/tails/bondy.py +++ b/chainladder/tails/bondy.py @@ -184,8 +184,16 @@ def fit(self, X, y=None, sample_weight=None): tail = self.ldf_.values[..., 0, initial] tail = tail ** (self.b_ / (1 - self.b_)) f0 = self.ldf_.values[..., 0:1, initial : initial + 1] + # One fitted factor per development period up to the end of the + # projection, so the tail columns match those TailBase.fit added. + n_projected = self._ave_period[0] fitted = f0 ** ( - self.b_ ** (np.arange(sum(X.ddims >= earliest_age))[None, None, None, :]) + self.b_ + ** ( + np.arange(sum(X.ddims >= earliest_age) + n_projected - 1)[ + None, None, None, : + ] + ) ) fitted = xp.concatenate( (fitted, fitted[..., -1:] ** (self.b_ / (1 - self.b_))), axis=-1 @@ -201,7 +209,7 @@ def fit(self, X, y=None, sample_weight=None): self.ldf_.values = xp.concatenate( ( self.ldf_.values[..., : sum(X.ddims <= attachment_age)], - fitted[..., -sum(X.ddims >= attachment_age) :], + fitted[..., -(sum(X.ddims >= attachment_age) + n_projected - 1) :], ), axis=-1, ) diff --git a/chainladder/tails/tests/test_bondy.py b/chainladder/tails/tests/test_bondy.py index 9f981f39e..8b7ce6991 100644 --- a/chainladder/tails/tests/test_bondy.py +++ b/chainladder/tails/tests/test_bondy.py @@ -46,3 +46,40 @@ def test_bondy_fits_grouped_development_pattern(clrd: Triangle) -> None: assert list(grouped.b_.index) == list(summed.b_.index) assert np.allclose(grouped.b_.values, summed.b_.values, equal_nan=True) assert np.allclose(grouped.ldf_.values, summed.ldf_.values, equal_nan=True) + + +def test_bondy_fills_every_projected_tail_column( + raa: Triangle, qtr: Triangle, monthly: Triangle +) -> None: + """ + ``TailBondy`` fills each tail column that ``TailBase`` adds. + + ``TailBase.fit`` extends ``ldf_`` by one column per development period in + ``projection_period`` plus one for the rest of the tail, so quarterly and + monthly triangles, and annual ones with ``projection_period`` other than + 12, get more than two tail columns. ``TailBondy`` fills them from its + fitted curve, and its ``tail_`` is the same for every ``projection_period``. + + Parameters + ---------- + raa: Triangle + The raa sample data set, an annual triangle. + qtr: Triangle + The quarterly sample data set. + monthly: Triangle + The prism sample data set summed to a single monthly triangle. + + Returns + ------- + None + """ + for triangle in (raa, qtr, monthly): + dev = cl.Development().fit_transform(triangle) + default = cl.TailBondy().fit(dev) + for projection_period in (6, 12, 24): + bondy = cl.TailBondy(projection_period=projection_period).fit(dev) + constant = cl.TailConstant(projection_period=projection_period).fit(dev) + + assert bondy.ldf_.shape == constant.ldf_.shape + assert list(bondy.ldf_.ddims) == list(constant.ldf_.ddims) + assert np.allclose(bondy.tail_.values, default.tail_.values, equal_nan=True)