BootstrapODPSample#

class chainladder.BootstrapODPSample(n_sims=1000, n_periods=-1, hat_adj=True, drop=None, drop_high=None, drop_low=None, drop_valuation=None, random_state=None)[source]#

Class to generate bootstrap samples of triangles. Currently this Only supports ‘single’ triangles (single index and single column).

Parameters:
n_sims: int (default=1000)

Number of simulations to generate

n_periods: integer, optional (default=-1)

number of origin periods to be used in the ldf average calculation. For all origin periods, set n_periods=-1

hat_adj: bool (default=False)

Adjust standardized Pearson residuals with the hat matrix adjustment factor. If false, Degree of Freedom adjustment is used.

drop: tuple or list of tuples

Drops specific origin/development combination(s) from residual sample

drop_high: bool or list of bool (default=None)

Drops highest link ratio(s) from residual sample

drop_low: bool or list of bool (default=None)

Drops lowest link ratio(s) from residual sample

drop_valuation: str or list of str (default=None)

Drops specific valuation periods from residual sample. str must be date convertible.

random_state: int, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

Attributes:
resampled_triangles_: Triangle

A set of triangles represented by each simulation

scale_:

The scale parameter to be used in generating process risk

See also

MackChainladder

Estimates prediction error for chainladder reserves.

Examples

Generate ODP bootstrap samples of the RAA sample triangle. The estimator re-samples standardized Pearson residuals to produce n_sims synthetic triangles stacked along the index axis of resampled_triangles_, and exposes the scale parameter scale_ used to generate process risk. random_state and a small n_sims keep the output deterministic and fast.

raa = cl.load_sample('raa')
boot = cl.BootstrapODPSample(n_sims=100, random_state=42).fit(raa)
print(boot.resampled_triangles_.shape)
print(round(float(boot.scale_), 2))
(100, 1, 10, 10)
983.64

Because resampled_triangles_ is itself a Triangle (with the simulation index along the first axis), it can be fed straight into any downstream reserving estimator to obtain a stochastic distribution of ultimates and IBNR. Below, a deterministic chain-ladder is fit on the resampled triangle and the total IBNR is summarised across the 100 simulations.

sims = cl.BootstrapODPSample(
    n_sims=100, random_state=42
).fit_transform(raa)
ibnr = cl.Chainladder().fit(sims).ibnr_.sum('origin')
print(ibnr.shape)
print(round(float(ibnr.mean()), 2))
print(round(float(ibnr.std()), 2))
(100, 1, 1, 1)
51301.13
16149.47

The estimator also supports a leave-one-out sensitivity check on the residual distribution. Setting drop_high=True excludes the highest link ratio in each development column before computing residuals, without making any outlier judgement, so the resulting scale_ measures how influential the column maxima are on the bootstrap. For the RAA triangle this shrinks scale_ from 983.64 to 648.94.

boot_dh = cl.BootstrapODPSample(
    n_sims=100, random_state=42, drop_high=True
).fit(raa)
print(round(float(boot_dh.scale_), 2))
648.94

Two further levers control how the residual pool is built. n_periods restricts the internal Development fit to the most recent origin periods, which changes the Pearson residuals and therefore scale_, while hat_adj swaps the hat matrix adjustment for the simpler degree-of-freedom adjustment when standardizing residuals before resampling.

short_hist = cl.BootstrapODPSample(
    n_sims=100, random_state=42, n_periods=3
).fit(raa)
dof = cl.BootstrapODPSample(
    n_sims=100, random_state=42, hat_adj=False
).fit(raa)
print(round(float(short_hist.scale_), 2))
print(round(float(dof.scale_), 2))
322.4
983.64
fit(X, y=None, sample_weight=None)[source]#
transform(X)[source]#

If X and self are of different shapes, align self to X, else return self.

Parameters:
X: Triangle

The triangle to be transformed

Returns:
X_new: New triangle with transformed attributes.

Inherited Methods

BootstrapODPSample.fit_transform

Fit to data, then transform it.

BootstrapODPSample.get_metadata_routing

Get metadata routing of this object.

BootstrapODPSample.get_params

Get parameters for this estimator.

BootstrapODPSample.pipe

Apply func(self, *args, **kwargs).

BootstrapODPSample.set_backend

Converts triangle array_backend.

BootstrapODPSample.set_output

Set output container.

BootstrapODPSample.set_params

Set the parameters of this estimator.

BootstrapODPSample.to_json

Serializes triangle object to json format

BootstrapODPSample.to_pickle

Serializes triangle object to pickle.