Skip to contents

Gesmann and Morris' (2020) hierarchical compartmental reserving model with one outstanding compartment, their models 1 and 2, fitted to paid and outstanding jointly with NUTS. Claims flow from exposure into outstanding as they are reported, at rate k_er, and from outstanding into paid as they settle, at rate k_p. For origin i with premium P_i and development time t in years, with g(t) = (exp(-k_p t) - exp(-k_er t)) / (k_er - k_p), OS_i(t) = P_i RLR_i k_er g(t) and PD_i(t) = P_i RLR_i RRF_i [(1 - exp(-k_p t)) - k_p g(t)], so RLR_i is the reported loss ratio, RRF_i the reserve robustness factor (paid over reported) and RLR_i RRF_i the ultimate loss ratio. RLR and RRF vary by origin with correlated effects (LKJ prior on the correlation) on the priors' o scale; the priors can add origin effects on the rates and development-year effects on any of the four (compartmental_priors()), each cell then taking its own parameters. NUTS samples on a pilot run's dense scale, with the gradient from dual numbers (docs/design/reserving-compartmental.md).

Usage

compartmental_fit(ptr)

compartmental(
  triangle,
  paid,
  premium,
  priors,
  outstanding = NULL,
  incurred = NULL,
  likelihood = c("normal", "lognormal"),
  scale = c("amount", "loss_ratio"),
  paid_response = c("cumulative", "incremental"),
  fitted = c("paid_and_outstanding", "paid_and_incurred", "paid_only", "incurred_only"),
  rate_order = c("free", "ordered"),
  development_levels = c("per_age", "by_year"),
  start = c("data", "prior_centre"),
  chains = 4,
  tune = 1000,
  draws = 2000,
  n_sims = 10000,
  seed = 0,
  target_accept = 0.99,
  max_depth = 10
)

compartmental_model_2(
  triangle,
  paid,
  premium,
  priors,
  outstanding = NULL,
  incurred = NULL,
  rate_order = c("free", "ordered"),
  development_levels = c("per_age", "by_year"),
  start = c("data", "prior_centre"),
  chains = 4,
  tune = 2000,
  draws = 8000,
  n_sims = 10000,
  seed = 0,
  target_accept = 0.999,
  max_depth = 10
)

Arguments

ptr

A CompartmentalFit pointer; used internally.

triangle

A cumulative triangle with one segment.

paid

Name of the column of cumulative paid amounts.

premium

Name of the column with each origin's premium (its latest value); the fit's origins are this column's.

priors

A compartmental_priors list; required.

outstanding

Name of a column of outstanding amounts.

incurred

Name of a column of incurred amounts: outstanding is incurred less paid, cell by cell (the papers' outstanding on company 337 is incurred with bulk and IBNR less paid). Give exactly one of outstanding and incurred, or neither under fitted = "paid_only".

likelihood

"normal" (model 1) or "lognormal" (model 2).

scale

The response scale: "amount" (model 1) or "loss_ratio", amounts over the origin's premium (model 2).

paid_response

"cumulative" (model 1) or "incremental" (model 2).

fitted

"paid_and_outstanding", "paid_and_incurred" (incurred replaces outstanding as the second response, as above), "paid_only" or "incurred_only" (one response alone, with rate_order = "ordered").

rate_order

"free" or "ordered", as above.

development_levels

The width of a development level, for priors with development effects (model 2): "per_age" (the default), one level for each age, or "by_year", one for each development year (counted from the origin's start: ages 1 to 12 months, 13 to 24 and so on). Choose with bayes_loo(); see "Fitting sub-annual data" in compartmental(). The same fit at annual grain. An error for "by_year" with priors that have no development effects (model 1).

start

Where the pilot run starts: "data", a least-squares fit of the population curve (the prior centre if that fit fails, and under one response if its log posterior is below the prior centre's), or "prior_centre".

chains, tune, draws

NUTS chains, warm-up draws per chain and kept draws per chain.

n_sims

Number of predictive simulations; positive.

seed

Seed of the chains and of the simulations, a non-negative whole number.

target_accept

Target mean acceptance rate (the paper's adapt_delta, 0.99).

max_depth

Largest NUTS tree depth.

Value

A compartmental_fit object.

Details

Model 1 (the defaults) has normal outstanding and cumulative paid amounts about these curves, each type with its own sigma. Model 2 (compartmental_model_2(), with gesmann_morris_2_priors()) has log-normal outstanding and incremental paid loss ratios to premium; every combination of likelihood, scale and paid_response is built. Under likelihood = "lognormal" every response must be positive, and under paid_response = "incremental" each paid cell needs the paid at the age before; the fit stops with an error naming the cell otherwise. fitted = "paid_and_incurred" fits paid and incurred, with incurred in place of outstanding as the second response: the mean of an incurred cell is RLR_i (OS(t) + RRF_i PD(t)) times premium (or as a loss ratio), with the cumulative PD even under paid_response = "incremental", and log_sigma_os is the incurred sigma. Give the incurred column as incurred, or an outstanding column as outstanding and the incurred is outstanding plus paid where both are observed. The fit's outstanding then holds the future incurred cells.

fitted = "paid_only" and fitted = "incurred_only" fit one response alone and need rate_order = "ordered" (an error under "free"): from one response the means do not change under the rate swap below, and from paid alone only RLR x RRF is identified, so the priors carry the split of RLR and RRF. The model then has one sigma, sigma_pd or sigma_os. Under "paid_only" the second column is not read (outstanding and incurred may both be left out) and the fit's outstanding is NULL. Under "incurred_only" the incurred is given as for "paid_and_incurred" and the paid column supplies each origin's latest paid only: the reserve is the expected paid at the last age less the latest paid, and the future paid cells are expected values, without noise, since no paid cell is fitted. Of the one-year views and the backtest candidates only Python and Rust take these settings. compartmental_diffuse_priors() is the starting point for "paid_only". Under "incurred_only" the incurred does not identify the payment rate k_p, so its prior sets the paid run-off and the reserve at every width (on company 337 the paper's narrow prior put the reserve 26% above the fit to paid and outstanding): the fit refuses a k_p prior with a log-scale sd above 0.5, so the diffuse preset is an error there, and you give a k_p prior you believe, for example from the book's paid history or from a paid-and-incurred fit of a similar book.

compartmental_model_2() is compartmental() with model 2's likelihood, scale and paid response, and a longer, finer sampler: four chains of 2,000 warm-up and 8,000 kept draws with target acceptance 0.999. With 87 parameters, effect sds whose posteriors pile up near 0 and a slowly mixing k_p, model 1's sampler left divergent transitions or an R-hat above 1.01 on most seeds; this one passes every threshold on 195 of 200 seeds on company 337. A fit takes about a minute.

An origin with a premium and no observed cell (the papers' training triangle has one) draws its effects from the population in each simulation, and so does a development age with no observed cell. The reserve is the paid at the square's last age less the latest paid; the square runs for as many origin periods as the premium column has origins, in development periods (40 quarterly ages for ten annual origins). The development grain may be finer than the origin grain (the triangle's own grains), and each cell's development time is its age in years on every grain, so the rates are per year and an incremental paid cell is the increment over one development period. The coming year of compartmental_one_year() is the next twelve months of calendar time, up to four quarterly cells per origin. One seed replays a fit exactly: the chains and the simulations each take a seed derived from it.

The means are exactly invariant under swapping the two rates (with RLR and RRF rescaled), so only the priors tell the two modes apart. Under rate_order = "free" (the paper's priors) the fit warns when any posterior draw has population rates with k_er <= k_p; rate_order = "ordered" samples k_er = k_p + exp(delta), the same priors restricted to k_er > k_p. With effects on the rates, the fit's cell_rate_swaps is the share of draws and observed cells with k_er <= k_p (NA when the rates are shared).

Fitting sub-annual data. Quarterly or monthly development cells are allowed. What follows is from a study on simulated books (design note decision 14, knowledge/findings/compartmental-subannual.md); no real sub-annual triangle was available.

  • Rate priors: the rates are per year on every grain, and the paper's presets are kept as they are. Finer cells pull the preset towards the truth; a line whose first year runs much faster or slower than the preset's k_er of about 3 needs priors of its own.

  • Development levels (model 2): development_levels = "per_age" or "by_year", a choice to make with bayes_loo(). Where effects move by year, by-year levels agree with per-age ones on the reserve (0.10 sd apart on average in the study), win elpd in 30 of 30 quarterly books and on 10 monthly books under a short sampler took 89 s against 126 s (rough times) with a worst R-hat of 1.07 against 1.62, though a median bulk ESS of 101 against 114; where effects move within a year they lose 361 of elpd in 30 of 30 books and widen the reserve's sd by 59%.

  • Seasonality: there is no seasonal term. Model 1 reads a season as noise (the interval widens, by up to 54% in the sd for a 30% season, and the mean can sit nearly 1 sd off the outcome), and model 2's per-age levels do not absorb a season unless every origin starts in the same calendar quarter. A calendar-quarter factor is not built.

  • Cumulative paid: the interval narrows as the cells get finer, right where the noise of the cells is independent and too narrow where it persists. In the study's world with persistent payment noise, at one persistence chosen by hand and fitted to no book (PERSIST_PHI 25, PERSIST_RHO 0.95; a smaller fall is expected with less, untested), the 90% interval covered 88%, 70% and 56% at annual, quarterly and monthly cells and the RMSE rose from 1,623 to 2,033. A fit with cumulative paid on cells finer than a year therefore warns, asking you to check the residuals; it also warns when the fit is calibrated, since the data do not say which world they are in. paid_response = "incremental" keeps the interval but, in that world, ran 1.3 to 2 times too wide, with a worse RMSE at quarterly and monthly grain and a failing Meyers' D at annual grain. Neither is chosen for you.

  • Earned exposure: all of an origin's exposure starts at age 0, so sub-annual development of annual origins fits an exposure the model does not have; use quarterly origins where the data allow. On simulated books with earned premium annual origins failed Meyers' D at annual, quarterly and monthly development, and quarterly origins of the same books passed narrowly (17.8 against a critical 19.2, on a short sampler, with 3 books at the default sampler); that comparison also changes the number of origins and the effects' variance. A setting that spreads the exposure over the origin's period is not built.

Failed MCMC diagnostics (R-hat above 1.01, bulk or tail ESS below 100 per chain, any divergent transition) and rate swaps do not fail the fit: compartmental() raises one warning() listing them, and they stay in the fit's diagnostics. With the defaults, 194 of 200 seeds on company 337 passed every threshold for model 1, and with compartmental_model_2()'s sampler 195 of 200 for model 2; each of the others just missed one.

Properties of the fit: origins (those of the premium column), premium, latest_paid (0 for an origin with none), population_origins (origins drawn from the population), reserves (a predictive_distribution with dimension origin, laid out as odp_bootstrap()'s), paid and outstanding (the future cells of the square, dimensions origin and age in months, from the same simulations), ultimate_loss_ratio (each origin's posterior mean RLR_i RRF_i), rate_swaps, cell_rate_swaps, diagnostics, summary (also summary(fit)), draws (a matrix of the posterior draws: on the natural scale k_er, k_p, RLR, RRF (population values, at a zero effect), sigma_os, sigma_pd, RLR[o] and RRF[o] for each origin o with an observed cell, with origin effects on the rates k_er[o] and k_p[o] too, and with development effects dev_ker[a], dev_kp[a], dev_RLR[a] and dev_RRF[a] for each development age a (months) with an observed cell, on the o scale; then b_ker, b_kp, b_RLR, b_RRF, tau_RLR, tau_RRF (and tau_ker, tau_kp), rho (and tau_dev_ker, tau_dev_kp, tau_dev_RLR, tau_dev_RRF), log_sigma_os and log_sigma_pd, a name in parentheses only when the priors have that effect), and paid_table and outstanding_table (one row per future cell: origin, development, mean, std_dev, q05, q50 and q95). as.data.frame() has one row per origin with the premium, latest_paid, the mean and std_dev of the posterior predictive reserve and the ultimate_loss_ratio; totals_frame() has the totals. bayes_loo() gives the PSIS-LOO of the observed cells, outstanding first, with the full log density of each response, normal or log-normal (with its -log y term), as brms' log_lik, on the response's scale (compare it only with fits of the same responses), plus n_outstanding, elpd_outstanding and elpd_paid.

Errors: if fitted is "paid_only" or "incurred_only" and rate_order is not "ordered"; if a response is not positive under the log-normal, or a paid cell has no paid at the age before under incremental paid; if not exactly one of outstanding and incurred is given (at most one under "paid_only"); if a column is missing, the triangle has several segments, or a premium is missing or not positive; if a prior or sampler setting is invalid; or if there are no more observed cells than parameters.

Examples

long <- data.frame(year = rep(1988:1992, 5:1),
                   age = unlist(lapply(5:1, function(k) 12 * seq_len(k))),
                   paid = c(9.6, 22.8, 33.3, 40.3, 45.1, 7.9, 19.5, 29.6, 36.8,
                            8.7, 24.3, 35.4, 13.3, 33.0, 11.4),
                   incurred = c(62.7, 64.0, 65.6, 65.3, 62.3, 62.1, 56.7, 56.6, 56.8,
                                64.0, 61.5, 63.2, 73.9, 75.1, 77.1),
                   premium = rep(c(104.4, 88.9, 86.0, 99.3, 104.9), 5:1))
tri <- triangle(long, "year", "age", c("paid", "incurred", "premium"))
# Check the priors first: the mean paid of 1988 at 60 months over its premium.
paths <- compartmental_prior_predictive(tri, "premium", gesmann_morris_priors(),
                                        n_sims = 1000)
quantile(marginal(paths$paid, list(origin = "1988", age = 60)), c(0.05, 0.95)) / 104.4
#> [1] 0.3861675 0.8243818
# Short chains may miss a diagnostic threshold.
fit <- suppressWarnings(compartmental(tri, "paid", "premium", gesmann_morris_priors(),
                                      incurred = "incurred", chains = 2, tune = 150,
                                      draws = 150, target_accept = 0.9, n_sims = 1000))
head(fit@summary)
#>   parameter       mean         sd       q05        q50        q95     rhat
#> 1      k_er  2.7306437 0.28412001 2.3483302  2.6853328  3.2658730 1.004734
#> 2       k_p  0.7332346 0.10332432 0.5504169  0.7372765  0.9014630 1.012102
#> 3       RLR  0.6396757 0.10477064 0.5035675  0.6200863  0.8790525 1.008300
#> 4       RRF  0.6714473 0.07786225 0.5423122  0.6704949  0.7982243 1.006757
#> 5  sigma_os 22.1851781 7.54821678 7.7733733 22.3405413 34.5120243 1.008611
#> 6  sigma_pd  4.5924274 1.09622956 3.1668348  4.4380488  6.6164371 1.032341
#>   ess_bulk  ess_tail
#> 1 288.8899 199.94416
#> 2 142.4556  76.63950
#> 3 163.3143  90.81861
#> 4 263.4548 224.46741
#> 5 173.3731  62.79509
#> 6 187.7110 173.37420
as.data.frame(fit)
#>   origin premium latest_paid      mean  std_dev ultimate_loss_ratio
#> 1   1988   104.4        45.1  0.000000 0.000000           0.4160989
#> 2   1989    88.9        36.8 -1.232139 5.353349           0.4188703
#> 3   1990    86.0        35.4 -0.219013 5.349932           0.4266311
#> 4   1991    99.3        33.0  7.708076 5.402561           0.4283016
#> 5   1992   104.9        11.4 30.565047 5.695441           0.4197128
# Model 2, with short chains for the example (the defaults take about a
# minute on company 337).
fit2 <- suppressWarnings(compartmental_model_2(tri, "paid", "premium",
                                               gesmann_morris_2_priors(),
                                               incurred = "incurred", chains = 2,
                                               tune = 150, draws = 150,
                                               target_accept = 0.9, n_sims = 1000))
#> Error in compartmental(triangle, paid, premium, priors, outstanding = outstanding,     incurred = incurred, likelihood = "lognormal", scale = "loss_ratio",     paid_response = "incremental", rate_order = match.arg(rate_order),     development_levels = match.arg(development_levels), start = match.arg(start),     chains = chains, tune = tune, draws = draws, n_sims = n_sims,     seed = seed, target_accept = target_accept, max_depth = max_depth): Bayesian reserving: 30 observed cells for 55 parameters; the model needs more cells than parameters
fit2@cell_rate_swaps
#> Error: object 'fit2' not found
as.data.frame(fit2)
#> Error: object 'fit2' not found