Applying Stochastic Methods#

Getting Started#

This tutorial focuses on using stochastic methods to estimate ultimates.

# Black linter, optional
# import jupyter_black as jb
# jb.load()

import pandas as pd
import numpy as np
import chainladder as cl
import matplotlib.pyplot as plt
import statsmodels.api as sm

print("pandas: " + pd.__version__)
print("numpy: " + np.__version__)
print("chainladder: " + cl.__version__)
pandas: 3.0.3
numpy: 2.4.6
chainladder: 0.9.2

Disclaimer#

Note that a lot of the examples shown might not be applicable in a real world scenario, and is only meant to demonstrate some of the functionalities included in the package. The user should always follow all applicable laws, the Code of Professional Conduct, applicable Actuarial Standards of Practice, and exercise their best actuarial judgement.

Intro to MackChainladder#

Like the basic Chainladder method, the MackChainladder is entirely specified by its selected development pattern. In fact, it is the basic Chainladder, but with extra features.

clrd = (
    cl.load_sample("clrd")
    .groupby("LOB")
    .sum()
    .loc["wkcomp", ["CumPaidLoss", "EarnedPremNet"]]
)

cl.Chainladder().fit(clrd["CumPaidLoss"]).ultimate_ == cl.MackChainladder().fit(
    clrd["CumPaidLoss"]
).ultimate_
np.True_

Let’s create a Mack’s Chainladder model.

mack = cl.MackChainladder().fit(clrd["CumPaidLoss"])

MackChainladder has the following additional fitted features that the deterministic Chainladder does not:

  • full_std_err_: The full standard error

  • total_process_risk_: The total process error

  • total_parameter_risk_: The total parameter error

  • mack_std_err_: The total prediction error by origin period

  • total_mack_std_err_: The total prediction error across all origin periods

Notice these are all measures of uncertainty, but where can they be applied? Let’s start by examining the link_ratios underlying the triangle between age 12 and 24.

clrd_first_lags = clrd[clrd.development <= 24][clrd.origin < "1997"]["CumPaidLoss"]
clrd_first_lags
12 24
1988 285,804 638,532
1989 307,720 684,140
1990 320,124 757,479
1991 347,417 793,749
1992 342,982 781,402
1993 342,385 743,433
1994 351,060 750,392
1995 343,841 768,575
1996 381,484 736,040

A simple average link-ratio can be directly computed.

clrd_first_lags.link_ratio.to_frame().mean().iloc[0]
np.float64(2.2066789527531494)

We can also verify that the result is the same as the Development object.

cl.Development(average="simple").fit(clrd["CumPaidLoss"]).ldf_.to_frame(
    origin_as_datetime=False
).values[0, 0]
np.float64(2.2066789527531494)

The Linear Regression Framework#

Mack noted that the estimate for the LDF is really just a linear regression fit. In the case of using the simple average, it is a weighted regression where the weight is \(\left (\frac{1}{X} \right )^{2}\).

Let’s take a look at the fitted coefficient and verify that this ties to the direct calculations that we made earlier. With the regression framework in hand, we can get more information about our LDF estimate than just the coefficient.

y = clrd_first_lags.to_frame(origin_as_datetime=True).values[:, 1]
x = clrd_first_lags.to_frame(origin_as_datetime=True).values[:, 0]

model = sm.WLS(y, x, weights=(1 / x) ** 2)
results = model.fit()
results.summary()
WLS Regression Results
Dep. Variable: y R-squared (uncentered): 0.997
Model: WLS Adj. R-squared (uncentered): 0.997
Method: Least Squares F-statistic: 2887.
Date: Wed, 24 Jun 2026 Prob (F-statistic): 1.60e-11
Time: 22:10:05 Log-Likelihood: -107.89
No. Observations: 9 AIC: 217.8
Df Residuals: 8 BIC: 218.0
Df Model: 1
Covariance Type: nonrobust
coef std err t P>|t| [0.025 0.975]
x1 2.2067 0.041 53.735 0.000 2.112 2.301
Omnibus: 7.448 Durbin-Watson: 1.177
Prob(Omnibus): 0.024 Jarque-Bera (JB): 2.533
Skew: -1.187 Prob(JB): 0.282
Kurtosis: 4.058 Cond. No. 1.00


Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.

By toggling the weights of our regression, we can handle the most common types of averaging used in picking loss development factors.

  • For simple average, the weights are \(\left (\frac{1}{X} \right )^{2}\)

  • For volume-weighted average, the weights are \(\left (\frac{1}{X} \right )\)

  • For “regression” average, the weights are 1

print("Simple average:")
print(
    round(
        cl.Development(average="simple")
        .fit(clrd_first_lags)
        .ldf_.to_frame(origin_as_datetime=False)
        .values[0, 0],
        10,
    )
    == round(sm.WLS(y, x, weights=(1 / x) ** 2).fit().params[0], 10)
)

print("Volume-weighted average:")
print(
    round(
        cl.Development(average="volume")
        .fit(clrd_first_lags)
        .ldf_.to_frame(origin_as_datetime=False)
        .values[0, 0],
        10,
    )
    == round(sm.WLS(y, x, weights=(1 / x)).fit().params[0], 10)
)

print("Regression average:")
print(
    round(
        cl.Development(average="regression")
        .fit(clrd_first_lags)
        .ldf_.to_frame(origin_as_datetime=False)
        .values[0, 0],
        10,
    )
    == round(sm.OLS(y, x).fit().params[0], 10)
)
Simple average:
True
Volume-weighted average:
True
Regression average:
True

The regression framework is what the Development estimator uses to set development patterns. Although we discard the information in the deterministic methods, in the stochastic methods, Development has two useful statistics for estimating reserve variability, both of which come from the regression framework. The stastics are sigma_ and std_err_ , and they are used by the MackChainladder estimator to determine the prediction error of our reserves.

dev = cl.Development(average="simple").fit(clrd["CumPaidLoss"])
dev.sigma_
12-24 24-36 36-48 48-60 60-72 72-84 84-96 96-108 108-120
(All) 0.1232 0.0340 0.0135 0.0091 0.0074 0.0067 0.0073 0.0097 0.0032
dev.std_err_
12-24 24-36 36-48 48-60 60-72 72-84 84-96 96-108 108-120
(All) 0.0411 0.0120 0.0051 0.0037 0.0033 0.0033 0.0042 0.0068 0.0032

Remember that std_err_ is calculated as \(\frac{\sigma}{\sqrt{N}}\).

np.round(
    dev.sigma_.to_frame(origin_as_datetime=False).transpose()["(All)"].values
    / np.sqrt(
        clrd["CumPaidLoss"].age_to_age.to_frame(origin_as_datetime=False).count()
    ).values,
    4,
)
array([0.0411, 0.012 , 0.0051, 0.0037, 0.0033, 0.0033, 0.0042, 0.0068,
       0.0032])

Since the regression framework uses the weighting method, we can easily turn “on and off” any observation we want using the dropping capabilities such as drop_valuation in the Development estimator. Dropping link ratios not only affects the ldf_ and cdf_, but also the std_err_ and sigma of the estimates.

Can we eliminate the 1988 valuation from our triangle, which is identical to eliminating the first observation from our 12-24 regression fit? Let’s calculate the std_err for the ldf_ of ages 12-24, and compare it to the value calculated using the weighted least squares regression.

clrd["CumPaidLoss"]
12 24 36 48 60 72 84 96 108 120
1988 285,804 638,532 865,100 996,363 1,084,351 1,133,188 1,169,749 1,196,917 1,229,203 1,241,715
1989 307,720 684,140 916,996 1,065,674 1,154,072 1,210,479 1,249,886 1,291,512 1,308,706
1990 320,124 757,479 1,017,144 1,169,014 1,258,975 1,315,368 1,368,374 1,394,675
1991 347,417 793,749 1,053,414 1,209,556 1,307,164 1,381,645 1,414,747
1992 342,982 781,402 1,014,982 1,172,915 1,281,864 1,328,801
1993 342,385 743,433 959,147 1,113,314 1,187,581
1994 351,060 750,392 993,751 1,114,842
1995 343,841 768,575 962,081
1996 381,484 736,040
1997 340,132
round(
    cl.Development(average="volume", drop_valuation="1988")
    .fit(clrd["CumPaidLoss"])
    .std_err_.to_frame(origin_as_datetime=False)
    .values[0, 0],
    8,
) == round(sm.WLS(y[1:], x[1:], weights=(1 / x[1:])).fit().bse[0], 8)
np.True_

With sigma_ and std_err_ in hand, Mack goes on to develop recursive formulas to estimate parameter_risk_ and process_risk_.

mack.parameter_risk_
12 24 36 48 60 72 84 96 108 120 9999
1988 0 0 0 0 0 0 0 0 0 0 0
1989 0 0 0 0 0 0 0 0 0 4 4
1990 0 0 0 0 0 0 0 0 9,520 9,616 9,616
1991 0 0 0 0 0 0 0 5,984 11,629 11,747 11,747
1992 0 0 0 0 0 0 4,588 7,468 12,252 12,376 12,376
1993 0 0 0 0 0 4,037 5,981 8,187 12,259 12,384 12,384
1994 0 0 0 0 4,163 5,980 7,555 9,503 13,302 13,438 13,438
1995 0 0 0 4,921 6,736 8,137 9,446 11,118 14,502 14,649 14,649
1996 0 0 8,824 11,289 12,895 14,101 15,190 16,513 19,141 19,336 19,336
1997 0 14,499 21,075 24,749 27,093 28,657 29,907 31,164 33,103 33,440 33,440
mack.process_risk_
12 24 36 48 60 72 84 96 108 120 9999
1988 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1989 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.72 3.72
1990 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 11.40 12.15 12.15
1991 0.00 0.00 0.00 0.00 0.00 0.00 0.00 8.71 14.63 15.30 15.30
1992 0.00 0.00 0.00 0.00 0.00 0.00 7.96 11.84 16.64 17.25 17.25
1993 0.00 0.00 0.00 0.00 0.00 8.28 11.50 14.42 18.41 18.97 18.97
1994 0.00 0.00 0.00 0.00 9.66 13.11 15.59 18.04 21.51 22.06 22.06
1995 0.00 0.00 0.00 13.27 17.28 19.90 21.95 23.99 26.87 27.40 27.40
1996 0.00 0.00 29.09 36.00 40.10 42.79 44.84 46.72 48.93 49.58 49.58
1997 0.00 74.58 102.38 118.47 128.48 134.72 139.27 143.01 146.29 147.83 147.83

Assumption of Independence#

The Mack model makes a lot of assumptions about independence (i.e. the covariance between random processes is 0). This means that many of the Variance estimates in the MackChainladder model follow the form of \(Var(A+B) = Var(A)+Var(B)\).

First, mack_std_err_2 \(=\) parameter_risk_2 \(+\) process_risk_2, the parameter risk and process risk is assumed to be independent.

mack.parameter_risk_**2 + mack.process_risk_**2
12 24 36 48 60 72 84 96 108 120 9999
1988
1989 29 29
1990 90,622,872 92,477,185 92,477,185
1991 35,806,255 135,235,171 138,002,323 138,002,323
1992 21,045,684 55,767,544 150,102,429 153,173,785 153,173,785
1993 16,294,082 35,768,727 67,024,596 150,277,824 153,352,766 153,352,766
1994 17,326,856 35,766,132 57,073,639 90,308,920 176,950,222 180,570,922 180,570,922
1995 24,214,697 45,371,037 66,217,721 89,219,298 123,616,047 210,301,239 214,604,352 214,604,352
1996 77,861,948 127,434,995 166,276,879 198,834,627 230,731,895 272,691,303 366,371,931 373,868,487 373,868,487
1997 210,235,570 444,183,929 612,506,466 734,069,280 821,246,548 894,468,239 971,219,052 1,095,822,851 1,118,245,081 1,118,245,081
mack.mack_std_err_**2
12 24 36 48 60 72 84 96 108 120 9999
1988 0 0 0 0 0 0 0 0 0 0 0
1989 0 0 0 0 0 0 0 0 0 29 29
1990 0 0 0 0 0 0 0 0 90,622,872 92,477,185 92,477,185
1991 0 0 0 0 0 0 0 35,806,255 135,235,171 138,002,323 138,002,323
1992 0 0 0 0 0 0 21,045,684 55,767,544 150,102,429 153,173,785 153,173,785
1993 0 0 0 0 0 16,294,082 35,768,727 67,024,596 150,277,824 153,352,766 153,352,766
1994 0 0 0 0 17,326,856 35,766,132 57,073,639 90,308,920 176,950,222 180,570,922 180,570,922
1995 0 0 0 24,214,697 45,371,037 66,217,721 89,219,298 123,616,047 210,301,239 214,604,352 214,604,352
1996 0 0 77,861,948 127,434,995 166,276,879 198,834,627 230,731,895 272,691,303 366,371,931 373,868,487 373,868,487
1997 0 210,235,570 444,183,929 612,506,466 734,069,280 821,246,548 894,468,239 971,219,052 1,095,822,851 1,118,245,081 1,118,245,081

Second, total_process_risk_ 2 \(= \sum_{origin} \) process_risk_ 2, the process risk is assumed to be independent between origins.

mack.total_process_risk_**2
12 24 36 48 60 72 84 96 108 120 9999
1988 0 5,563 11,328 15,508 18,507 20,616 22,327 23,960 25,939 26,602 26,602
(mack.process_risk_**2).sum(axis="origin")
12 24 36 48 60 72 84 96 108 120 9999
1988 5,563 11,328 15,508 18,507 20,616 22,327 23,960 25,939 26,602 26,602

Lastly, independence is also assumed to apply to the overall standard error of reserves, as expected.

(mack.parameter_risk_**2 + mack.process_risk_**2).sum(axis=2).sum(axis=3)
np.float64(13766856369.20736)
(mack.mack_std_err_**2).sum(axis=2).sum(axis=3)
np.float64(13766856369.20736)

This over-reliance on independence is one of the weaknesses of the MackChainladder method. Nevertheless, if the data align with this assumption, then total_mack_std_err_ is a reasonable esimator of reserve variability.

Mack Reserve Variability#

The mack_std_err_ at ultimate is the reserve variability for each origin period.

mack.mack_std_err_[
    mack.mack_std_err_.development == mack.mack_std_err_.development.max()
]
9999
1988
1989 5
1990 9,617
1991 11,747
1992 12,376
1993 12,384
1994 13,438
1995 14,649
1996 19,336
1997 33,440

With the summary_ method, we can more easily look at the result of the MackChainladder model.

mack.summary_
Latest IBNR Ultimate Mack Std Err
1988 1,241,715 1,241,715
1989 1,308,706 13,321 1,322,027 5
1990 1,394,675 42,210 1,436,885 9,617
1991 1,414,747 79,409 1,494,156 11,747
1992 1,328,801 119,709 1,448,510 12,376
1993 1,187,581 167,192 1,354,773 12,384
1994 1,114,842 260,401 1,375,243 13,438
1995 962,081 402,403 1,364,484 14,649
1996 736,040 636,834 1,372,874 19,336
1997 340,132 1,056,335 1,396,467 33,440

Let’s visualize the paid to date, the estimated reserves, and their standard errors with a histogram.

plt.bar(
    mack.summary_.to_frame(origin_as_datetime=True).index.year,
    mack.summary_.to_frame(origin_as_datetime=True)["Latest"],
    label="Paid",
)
plt.bar(
    mack.summary_.to_frame(origin_as_datetime=True).index.year,
    mack.summary_.to_frame(origin_as_datetime=True)["IBNR"],
    bottom=mack.summary_.to_frame(origin_as_datetime=True)["Latest"],
    yerr=mack.summary_.to_frame(origin_as_datetime=True)["Mack Std Err"],
    label="Reserves",
)
plt.legend(loc="upper left")
plt.ylim(0, 1800000)
(0.0, 1800000.0)
../../_images/bff5b6e15806af7a708695f5b63354dc5a03d8396201d4a1c7b8f361bfaf7cdd.png

We can also simulate the (assumed) normally distributed IBNR with np.random.normal().

ibnr_mean = mack.ibnr_.sum()
ibnr_sd = mack.total_mack_std_err_.values[0, 0]
n_trials = 10000

np.random.seed(2021)
dist = np.random.normal(ibnr_mean, ibnr_sd, size=n_trials)

plt.hist(dist, bins=50)
(array([  1.,   2.,   8.,   7.,  13.,  17.,  30.,  29.,  41.,  72.,  66.,
         94., 142., 185., 195., 274., 312., 351., 392., 419., 509., 491.,
        546., 540., 577., 537., 534., 524., 483., 448., 401., 348., 300.,
        268., 210., 163., 118.,  94.,  68.,  59.,  41.,  25.,  19.,  18.,
          7.,   5.,   3.,   5.,   5.,   4.]),
 array([2419463.05710306, 2434136.10852954, 2448809.15995603,
        2463482.21138252, 2478155.26280901, 2492828.3142355 ,
        2507501.36566199, 2522174.41708848, 2536847.46851497,
        2551520.51994146, 2566193.57136795, 2580866.62279443,
        2595539.67422092, 2610212.72564741, 2624885.7770739 ,
        2639558.82850039, 2654231.87992688, 2668904.93135337,
        2683577.98277986, 2698251.03420635, 2712924.08563284,
        2727597.13705932, 2742270.18848581, 2756943.2399123 ,
        2771616.29133879, 2786289.34276528, 2800962.39419177,
        2815635.44561826, 2830308.49704475, 2844981.54847124,
        2859654.59989773, 2874327.65132421, 2889000.7027507 ,
        2903673.75417719, 2918346.80560368, 2933019.85703017,
        2947692.90845666, 2962365.95988315, 2977039.01130964,
        2991712.06273613, 3006385.11416262, 3021058.1655891 ,
        3035731.21701559, 3050404.26844208, 3065077.31986857,
        3079750.37129506, 3094423.42272155, 3109096.47414804,
        3123769.52557453, 3138442.57700102, 3153115.62842751]),
 <BarContainer object of 50 artists>)
../../_images/a07c822687675fd8275c0c50f9f932f18bf28b0a3acbff3b05541fd642929904.png

ODP Bootstrap Model#

The MackChainladder focuses on a regression framework for determining the variability of reserve estimates. An alternative approach is to use the statistical bootstrapping, or sampling from a triangle with replacement to simulate new triangles.

Bootstrapping imposes less model constraints than the MackChainladder, which allows for greater applicability in different scenarios. Sampling new triangles can be accomplished through the BootstrapODPSample estimator. This estimator will take a single triangle and simulate new ones from it. To simulate new triangles randomly from an existing triangle, we specify n_sims with how many triangles we want to simulate, and access the resampled_triangles_ attribute to get the simulated triangles. Notice that the shape of resampled_triangles_ matches n_sims at the first index.

samples = (
    cl.BootstrapODPSample(n_sims=10000).fit(clrd["CumPaidLoss"]).resampled_triangles_
)
samples
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/adjustments/bootstrap.py:311: UserWarning: 'where' used without 'out', expect unitialized memory in output. If this is intentional, use out=None.
  hat = xp.diagonal(xp.sqrt(xp.divide(1, abs(1 - hat), where=(1 - hat) != 0)))
Triangle Summary
Valuation: 1997-12
Grain: OYDY
Shape: (10000, 1, 10, 10)
Index: [LOB, Simulation_#]
Columns: [CumPaidLoss]

Alternatively, we could use BootstrapODPSample to transform our triangle into a resampled set.

The notion of the ODP Bootstrap is that as our simulations approach infinity, we should expect our mean simulation to converge on the basic Chainladder estimate of of reserves.

Let’s apply the basic chainladder to our original triangle and also to our simulated triangles to see whether this holds true.

ibnr_cl = cl.Chainladder().fit(clrd["CumPaidLoss"]).ibnr_.sum()
ibnr_bootstrap = cl.Chainladder().fit(samples).ibnr_.sum("origin").mean()

print(
    "Chainladder's IBNR estimate:",
    ibnr_cl,
)
print(
    "BootstrapODPSample's mean IBNR estimate:",
    ibnr_bootstrap,
)
print("Difference $:", ibnr_cl - ibnr_bootstrap)
print("Difference %:", abs(ibnr_cl - ibnr_bootstrap) / ibnr_cl)
Chainladder's IBNR estimate: 2777812.6890986315
BootstrapODPSample's mean IBNR estimate: 2778644.866616378
Difference $: -832.1775177465752
Difference %: 0.00029958014124293144
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:120: RuntimeWarning: overflow encountered in exp
  sigma_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:124: RuntimeWarning: overflow encountered in exp
  std_err_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:127: RuntimeWarning: invalid value encountered in multiply
  sigma_ = sigma_ * 0
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:128: RuntimeWarning: invalid value encountered in multiply
  std_err_ = std_err_* 0

Using Deterministic Methods with Bootstrapped Samples#

Our samples is just another triangle object with all the functionality of a regular triangle. This means we can apply any functionality we want to our samples including any deterministic methods we learned about previously.

pipe = cl.Pipeline(
    steps=[("dev", cl.Development(average="simple")), ("tail", cl.TailConstant(1.05))]
)

pipe.fit(samples)
Pipeline(steps=[('dev', Development(average='simple')),
                ('tail', TailConstant(tail=1.05))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

Now instead of a single ldf_ (and cdf_) array across developmental ages, we have 10,000 arrays of ldf_ (and cdf_).

pipe.named_steps.dev.ldf_.iloc[0]
12-24 24-36 36-48 48-60 60-72 72-84 84-96 96-108 108-120
(All) 2.1346 1.3106 1.1510 1.0866 1.0511 1.0309 1.0293 1.0215 1.0120
pipe.named_steps.dev.ldf_.iloc[1]
12-24 24-36 36-48 48-60 60-72 72-84 84-96 96-108 108-120
(All) 2.2914 1.3230 1.1491 1.0820 1.0473 1.0400 1.0177 1.0275 1.0075
pipe.named_steps.dev.ldf_.iloc[9999]
12-24 24-36 36-48 48-60 60-72 72-84 84-96 96-108 108-120
(All) 2.1693 1.3084 1.1477 1.0770 1.0410 1.0317 1.0290 1.0241 1.0103

This allows us to look at the varibility of any fitted property used. Let’s look at the distribution of the age-to-age factor between age 12 and 24, and compare it against the LDF calculated from the non-bootstrapped triangle.

resampled_ldf = pipe.named_steps.dev.ldf_
plt.hist(pipe.named_steps.dev.ldf_.values[:, 0, 0, 0], bins=50)

orig_dev = cl.Development(average="simple").fit(clrd["CumPaidLoss"])
plt.axvline(orig_dev.ldf_.values[0, 0, 0, 0], color="black", linestyle="dashed")
<matplotlib.lines.Line2D at 0x731a4f111d10>
../../_images/28aadd23f7b05fda8752c48a2dbdf865f5fb9176af02abb964ed82a9c5caaaaa.png

Bootstrap vs Mack#

We can approximate some of the Mack’s parameters calculated using the regression framework.

bootstrap_vs_mack = resampled_ldf.std("index").to_frame(origin_as_datetime=False).T
bootstrap_vs_mack.rename(columns={"(All)": "Std_Bootstrap"}, inplace=True)
bootstrap_vs_mack = bootstrap_vs_mack.merge(
    orig_dev.std_err_.to_frame(origin_as_datetime=False).T,
    left_index=True,
    right_index=True,
)
bootstrap_vs_mack.rename(columns={"(All)": "Std_Mack"}, inplace=True)

bootstrap_vs_mack
Std_Bootstrap Std_Mack
12-24 0.043661 0.041066
24-36 0.012139 0.012024
36-48 0.007259 0.005101
48-60 0.005214 0.003734
60-72 0.004090 0.003303
72-84 0.003727 0.003337
84-96 0.003769 0.004190
96-108 0.004113 0.006831
108-120 0.004184 0.003222
width = 0.3
ages = np.arange(len(bootstrap_vs_mack))

plt.bar(
    ages - width / 2,
    bootstrap_vs_mack["Std_Bootstrap"],
    width=width,
    label="Bootstrap",
)
plt.bar(ages + width / 2, bootstrap_vs_mack["Std_Mack"], width=width, label="Mack")
plt.legend(loc="upper right")
plt.xticks(ages, bootstrap_vs_mack.index)
([<matplotlib.axis.XTick at 0x731a4ee95810>,
  <matplotlib.axis.XTick at 0x731a4f034990>,
  <matplotlib.axis.XTick at 0x731a4f04da90>,
  <matplotlib.axis.XTick at 0x731a4f04fa90>,
  <matplotlib.axis.XTick at 0x731a4f051a90>,
  <matplotlib.axis.XTick at 0x731a4f053b10>,
  <matplotlib.axis.XTick at 0x731a4f034690>,
  <matplotlib.axis.XTick at 0x731a4f01a650>,
  <matplotlib.axis.XTick at 0x731a4f01c6d0>],
 [Text(0, 0, '12-24'),
  Text(1, 0, '24-36'),
  Text(2, 0, '36-48'),
  Text(3, 0, '48-60'),
  Text(4, 0, '60-72'),
  Text(5, 0, '72-84'),
  Text(6, 0, '84-96'),
  Text(7, 0, '96-108'),
  Text(8, 0, '108-120')])
../../_images/d6475810898180a5ae722cd261cfd0ba2867514dce6e871dc8bc47bc43703f67.png

While the MackChainladder produces statistics about the mean and variance of reserve estimates, the variance or precentile of reserves would need to be fited using maximum likelihood estimation or method of moments. However, for BootstrapODPSample based fits, we can use the empirical distribution from the samples directly to get information about variance or the precentile of the IBNR reserves.

ibnr = cl.Chainladder().fit(samples).ibnr_.sum("origin")

ibnr_std = ibnr.std()
print("Standard deviation of reserve estimate: " + f"{round(ibnr_std,0):,}")
ibnr_99 = ibnr.quantile(q=0.99)
print("99th percentile of reserve estimate: " + f"{round(ibnr_99,0):,}")
Standard deviation of reserve estimate: 139,153.0
99th percentile of reserve estimate: 3,106,429.0
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:120: RuntimeWarning: overflow encountered in exp
  sigma_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:124: RuntimeWarning: overflow encountered in exp
  std_err_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:127: RuntimeWarning: invalid value encountered in multiply
  sigma_ = sigma_ * 0
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:128: RuntimeWarning: invalid value encountered in multiply
  std_err_ = std_err_* 0

Let’s see how the MackChainladder reserve distribution compares to the BootstrapODPSample reserve distribution.

plt.hist(ibnr.to_frame(origin_as_datetime=True), bins=50, label="Bootstrap", alpha=0.3)
plt.hist(dist, bins=50, label="Mack", alpha=0.3)
plt.legend(loc="upper right")
<matplotlib.legend.Legend at 0x731a4ef03ed0>
../../_images/1a24cb73518e0bf2faf0ce52eabff12185a070772954e80975518c3bc725ea1a.png

Expected Loss Methods with Bootstrap#

So far, we’ve only applied the multiplicative methods (i.e. basic chainladder) in a stochastic context. It is possible to use an expected loss method like the BornhuetterFerguson method does.

To do this, we will need an exposure vector.

sample_weight = clrd["EarnedPremNet"].latest_diagonal

Passing an apriori_sigma to the BornhuetterFerguson estimator tells it to consider the apriori selection itself as a random variable. Fitting a stochastic BornhuetterFerguson looks very much like the determinsitic version.

# Fit Bornhuetter-Ferguson to stochastically generated data
bf = cl.BornhuetterFerguson(0.65, apriori_sigma=0.10)
bf.fit(samples, sample_weight=sample_weight)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:120: RuntimeWarning: overflow encountered in exp
  sigma_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:124: RuntimeWarning: overflow encountered in exp
  std_err_ = xp.exp(time_pd * reg.slope_ + reg.intercept_)
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:127: RuntimeWarning: invalid value encountered in multiply
  sigma_ = sigma_ * 0
/home/docs/checkouts/readthedocs.org/user_builds/chainladder-python/envs/main/lib/python3.11/site-packages/chainladder/tails/base.py:128: RuntimeWarning: invalid value encountered in multiply
  std_err_ = std_err_* 0
BornhuetterFerguson(apriori=0.65, apriori_sigma=0.1)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

We can use our knowledge of Triangle manipulation to grab most things we would want out of our model.

# Grab completed triangle replacing simulated known data with actual known data
full_triangle = bf.full_triangle_ - bf.X_ + clrd["CumPaidLoss"]
# Limiting to the current year for plotting
current_year = (
    full_triangle[full_triangle.origin == full_triangle.origin.max()]
    .to_frame(origin_as_datetime=True)
    .T
)

As expected, plotting the expected development of our full triangle over time from the Bootstrap BornhuetterFerguson model fans out to greater uncertainty the farther we get from our valuation date.

# Plot the data
current_year.iloc[:, :200].reset_index(drop=True).plot(
    color="red",
    legend=False,
    alpha=0.1,
    title="Current Accident Year Expected Development Distribution",
)
<Axes: title={'center': 'Current Accident Year Expected Development Distribution'}>
../../_images/8e9c16622cd387244f61243fbd235ba2e40ba6bf180c322e1388a801f443a62a.png

Recap#

  • The Mack method approaches stochastic reserving from a regression point of view

  • Bootstrap methods approach stochastic reserving from a simulation point of view

  • Where they assumptions of each model are not violated, they produce resonably consistent estimates of reserve variability

  • Mack does impose more assumptions (i.e. constraints) on the reserve estimate making the Bootstrap approach more suitable in a broader set of applciations

  • Both methods converge to their corresponding deterministic point estimates