API Reference
Distributions
Parametric, discretized and sampled representations.
- distributions.Lognormal
-
Lognormal distribution:
ln X ~ Normal(meanlog, sdlog**2). - distributions.Gamma
-
Gamma distribution with shape
alphaand scaletheta: mean - distributions.Tweedie
-
Tweedie distribution with mean
mu, dispersionphiand power - distributions.Weibull
-
Weibull distribution with shape
kand scalelam: - distributions.Loglogistic
-
Loglogistic (Fisk) distribution with shape
alphaand scale - distributions.Mixture
-
A finite mixture of severities: component
iwith probability - distributions.Custom
-
A loss severity defined by your own distribution function: the slow
- distributions.to_json()
-
A distribution as a JSON document: the family and the parameters its
- distributions.from_json()
-
A distribution from a document written by
to_json, as the class of - distributions.Grid
-
A distribution on the points
0, step, 2*step, ...: the discretized - distributions.DiscretizationReport
-
How a distribution was discretized, and the error that introduced.
- distributions.Sampled
-
A distribution known only through equally weighted draws.
Large-loss severities
The Pareto family for layer and treaty pricing, with maximum likelihood fits.
- distributions.Pareto
-
Single-parameter Pareto:
P(X > x) = (t / x) ** alphaforx >= t, - distributions.PiecewisePareto
-
Piecewise Pareto: alpha
alpha[k]above thresholdt[k], the - distributions.LogAffinePareto
-
Log-affine local Pareto: the local alpha
- distributions.GeneralizedPareto
-
Generalized Pareto severity with a location (Riegel’s parameterization
- distributions.local_pareto_to_piecewise()
-
Converts the local Pareto distribution with local alpha
alpha(x)
Claim counts
Frequency distributions for frequency-severity aggregation.
- distributions.Poisson
-
Poisson claim counts with mean
lam. - distributions.NegativeBinomial
-
Negative binomial claim counts: mean
r * beta, variance - distributions.Binomial
-
Binomial claim counts:
nrisks, each claiming with probability - distributions.claim_count()
-
The claim count with this mean and dispersion
Var[N] / E[N]:
Predictive distributions
The joint result every model returns.
- distributions.PredictiveDistribution
-
The joint result every model returns: draws for each simulation (row)
Aggregate loss
Compound distributions on a grid, and simulated years of losses.
- aggregate.panjer()
-
Aggregate loss
S = X_1 + ... + X_Nby Panjer’s recursion. - aggregate.fft()
-
Aggregate loss
S = X_1 + ... + X_Nby fast Fourier transform. - aggregate.CompoundReport
-
What a compound calculation produced and the error it introduced.
- aggregate.simulate_events()
-
Simulates
n_simsyears of claims: a count fromfrequency, then that - aggregate.EventSet
-
Simulated years of individual losses, for applying per-loss terms such
Reinsurance
Excess-of-loss layers and towers, applied to simulated losses or exactly on the grid.
- reinsurance.Layer
-
A per-occurrence excess-of-loss layer:
limitxsattachmenton each - reinsurance.Tower
-
A reinsurance programme: layers in inuring stages.
- reinsurance.TowerGrids
-
A tower’s annual distributions on the grid, from
Tower.on_grid.
Models
Terms and design matrices, GLMs and GAMs, metrics, resampling and MCMC diagnostics.
- models.Terms
-
The terms of a model: an intercept, numeric columns and factors.
- models.Coding
-
Terms with factor levels learned from training data, from
- models.Design
-
A design matrix with an offset and prior weights.
- models.Glm
-
A generalized linear model, fitted by IRLS.
- models.GlmFit
-
A fitted GLM, from
Glm.fit. - models.BayesGlm
-
A Bayesian GLM sampled with NUTS (nuts-rs, the Rust core of nutpie).
- models.BayesGlmFit
-
A sampled Bayesian GLM, from
BayesGlm.fit. - models.ElasticNet
-
An elastic-net GLM: the lasso (
alpha=1), ridge (alpha=0) and - models.ElasticNetFit
-
A fitted elastic net, from
ElasticNet.fitorElasticNet.path. - models.CvPath
-
Cross-validated scores along an elastic-net path, from
- models.Gam
-
A generalized additive model: a
Glmplus P-spline smooths of - models.GamFit
-
A fitted GAM, from
Gam.fit. - models.deviance()
-
Deviance
sum w d(y, mu)of a family. - models.gini()
-
Gini index of the ordered Lorenz curve.
- models.lift()
-
Lift table: rows sorted by predicted rate, cut into bands of about
- models.crps()
-
Continuous ranked probability score of equally likely draws for an
- models.log_score()
-
Mean log score
-(1/n) sum log f(y_i)of the outcomes under the - models.pit()
-
Probability integral transform of each outcome under the family’s
- models.pit_from_draws()
-
The PIT of
yunder the empirical distribution ofdraws, - models.pit_histogram()
-
Counts of PIT values in
binsequal-width bins of[0, 1]. - models.ks_uniform()
-
Kolmogorov-Smirnov distance from the uniform on
[0, 1]; about - models.k_fold()
-
k-fold splits ofnrows, shuffled withseed. - models.group_k_fold()
-
Grouped
k-fold splits: each group’s rows stay in one fold. - models.time_ordered()
-
Time-ordered splits: for each of the last
n_testperiods, train on - models.mcmc_diagnostics()
-
MCMC diagnostics of chains of draws (Vehtari et al. 2021, as R’s
- models.elpd_loo()
-
Leave-one-out cross-validation by Pareto-smoothed importance sampling
- models.stacking_weights()
-
Stacking weights from pointwise held-out log predictive densities
- models.pseudo_bma_weights()
-
Pseudo-BMA weights,
w_kproportional toexp(elpd_k); with - models.BayesStacking
-
Bayesian stacking: a posterior for the stacking weights, with a
- models.HierarchicalStacking
-
Hierarchical stacking (Yao, Pirš, Vehtari and Gelman, 2022): model
- models.StackingFit
-
Posterior stacking weights, from
BayesStacking.fitor - models.elpd_waic()
-
WAIC from pointwise log-likelihood draws:
lppdless the variance of - models.lppd()
-
In-sample log pointwise predictive density,
- models.Elpd
-
An ELPD estimate from
elpd_looorelpd_waic. - models.deviance_score()
-
A score for
cross_validate: the family’s mean deviance on the - models.cross_validate()
-
Fits
modelon each split’s training rows and scores it on the - models.grid_search()
-
Scores every candidate by
cross_validateon the same splits and - models.random_search()
-
Draws
ncandidates withdraw(rng)fromrandom.Random(seed) - models.log_uniform()
-
A draw log-uniform between
lowandhigh, for learning rates - models.SearchResult
-
The result of
grid_searchorrandom_search. - models.compare()
-
Fits every model on each split’s training rows and scores its test
- models.Comparison
-
The result of
compare: every model’s score on every metric and - models.actual_vs_expected()
-
Actual against expected by period for a stored model’s predictions on
- models.simulate_from_means()
-
Joint predictive draws from fitted means, for engines that give only
Gradient boosting
LightGBM and XGBoost behind the model protocol, with joint predictive draws.
- boosting.Booster
-
Gradient-boosted trees for a response family, through LightGBM or
- boosting.BoosterFit
-
A fitted
Booster: means and joint predictive draws.
Pricing
The collective model, layer rating, reinsurance tower matching, and risk-loaded prices from simulated losses.
- pricing.CollectiveModel
-
The collective risk model: a claim count and a severity, with layer
- pricing.ilf()
-
Increased limit factor
LEV(limit) / LEV(basic_limit). - pricing.loss_elimination_ratio()
-
Loss elimination ratio of a deductible,
LEV(deductible) / E[X]. - pricing.pareto_extrapolation()
-
Expected loss of layer
toper unit of expected loss of layer - pricing.alpha_between_layers()
-
The Pareto alpha at which two layers have the given expected losses.
- pricing.alpha_between_frequency_and_layer()
-
The Pareto alpha at which
frequencylosses a year above - pricing.alpha_between_frequencies()
-
The Pareto alpha between two excess frequencies.
- pricing.match_tower()
-
Matches a tower of contiguous layers, the last unlimited, with one
- pricing.fit_pml_curve()
-
The model through the points of a PML curve:
amounts[j]is - pricing.fit_references()
-
A model that reproduces every reference: expected layer losses (which
- pricing.TowerModel
-
A frequency and a piecewise Pareto severity that reproduce a tower,
- pricing.price()
-
Risk-loaded price of a cover from its simulated losses.
- pricing.price_portfolio()
-
Prices a portfolio and allocates the price to its components.
- pricing.Price
-
The risk-loaded price of a cover, or of one component’s share of a
- pricing.PortfolioPrice
-
Prices of a portfolio’s components and of the portfolio as a whole.
- pricing.Mbbefd
-
The MBBEFD exposure curve and destruction-rate distribution (Bernegger,
- pricing.TabulatedCurve
-
A tabulated exposure curve: points
(x, G(x))from(0, 0)to - pricing.RiskProfile
-
A risk profile for property per-risk business: bands of sum insured,
- pricing.severity_exposure_curve()
-
The exposure curve of a severity capped at the maximum possible loss
Reserving
Loss triangles, the chain ladder with tail factors, Mack’s model with its one-year view, the expected-loss methods, the ODP bootstrap and Clark’s growth curves.
- reserving.Triangle
-
A loss triangle with four axes: index (segment), column (measure), origin
- reserving.ChainLadder
-
The chain-ladder method: each origin’s latest value projected to
- reserving.ChainLadderFit
-
A fitted chain-ladder projection of every segment of a triangle column.
- reserving.TailConstant
-
A given tail factor, as chainladder-python’s
TailConstant. - reserving.TailCurve
-
A curve fitted to the estimated factors and extrapolated, as
- reserving.TailBondy
-
The Bondy tail, as chainladder-python’s
TailBondy. - reserving.TailLogLinear
-
R ChainLadder’s
tail = TRUErule (itstailfactorfunction). - reserving.Mack
-
Mack’s distribution-free chain ladder: the chain-ladder projection plus
- reserving.MackFit
-
A fitted Mack model of every segment: the chain-ladder fields, plus
- reserving.ClaimsDevelopmentResult
-
Merz and Wüthrich’s (2008) one-year view of a Mack fit: standard errors
- reserving.ExpectedLoss
-
The expected loss ratio method: each origin’s ultimate is
apriori - reserving.BornhuetterFerguson
-
The Bornhuetter–Ferguson method: each origin’s latest value plus the
- reserving.Benktander
-
The Benktander (iterated Bornhuetter–Ferguson) method: starting from
- reserving.CapeCod
-
The Cape Cod (Stanard–Bühlmann) method: Bornhuetter–Ferguson with each
- reserving.ExpectedLossFit
-
A fitted expected-loss method (
ExpectedLoss, - reserving.CapeCodFit
-
A fitted Cape Cod of every segment of a triangle column: the fields of
- reserving.OdpBootstrap
-
Over-dispersed Poisson bootstrap of the chain ladder (England and
- reserving.OdpBootstrapFit
-
A fitted ODP bootstrap of every segment.
- reserving.MackBootstrap
-
Mack’s bootstrap for the lifetime and one-year views (England, Verrall
- reserving.MackBootstrapFit
-
A fitted bootstrap of Mack’s model, the lifetime view, of every
- reserving.OneYearFit
-
The simulated one-year view of every segment, from
- reserving.ClarkLdf
-
Clark’s LDF method (Clark 2003), as R ChainLadder’s
ClarkLDF: each - reserving.ClarkCapeCod
-
Clark’s Cape Cod method (Clark 2003), as R ChainLadder’s
- reserving.ClarkFit
-
A fitted Clark LDF or Cape Cod model of every segment of a triangle
Risk measures
Distortion risk measures, and capital allocation to components.
- risk.Distortion
-
A distortion risk measure:
rho(X) = integral of g(S(x)) dxfor a - risk.allocate()
-
Allocates a distortion risk measure of the total to the components.
- risk.capital()
-
Allocates the distortion risk measure of a portfolio’s total to its
- risk.entropic()
-
Entropic risk measure
(1 / theta) log E[exp(theta X)]: the certainty - risk.esscher()
-
Esscher premium
E[X exp(h X)] / E[exp(h X)]: the mean after tilting - risk.marginal_expected_shortfall()
-
Marginal expected shortfall of each component at level
p: its mean - risk.covar()
-
CoVaR of a component: the total’s VaR at level
qover the - risk.esscher_allocation()
-
Esscher allocation: each component’s mean under the Esscher transform
- risk.Allocation
-
Capital allocation of a distortion risk measure, from
capital.
Dependence
Copulas, and reordering existing draws to a target correlation.
- risk.GaussianCopula
-
The Gaussian copula with correlation matrix
correlation. - risk.StudentTCopula
-
The Student t copula with correlation matrix
correlationandnu - risk.ArchimedeanCopula
-
An exchangeable Archimedean copula: Clayton, Gumbel, Frank or Joe.
- risk.simulate()
-
Simulates marginals joined by a copula.
- risk.iman_conover()
-
Reorders each component’s draws to a target correlation (Iman-Conover).
Extreme value tails
Generalized Pareto tails over a threshold, beyond the draws.
- risk.Gpd
-
The generalized Pareto distribution, as SciPy’s
- risk.PotTail
-
A peaks-over-threshold tail: draws above a threshold modelled by a
- risk.mean_excess()
-
The empirical mean-excess function
e(u) = E[X - u | X > u]at each - risk.hill()
-
Hill estimates of the tail index
xi(1 / alpha) from thek