extremeloss¶
Extreme-value tail estimation for large claims: peaks-over-threshold with the
generalized Pareto distribution (GPD), tail analytics, and large-claim loading.
numpy and scipy only; matplotlib is optional via the plot extra, and
lossmodels integration via the splice extra.
The package covers threshold selection, GPD estimation, and the analytics built
on a fitted tail — return levels, exceedance probabilities, and excess-layer
charges — plus integration helpers for splicing an empirical body to a fitted
tail. It composes with lossmodels and the pooling primitives in actuarialpy.
Empirical tail measures follow the ecosystem VaR/TVaR estimators, and
simulation-backed quantities accept the shared rng argument — see
Conventions.
See the API reference below for the full surface; each object’s docstring carries its own usage.
API reference¶
- class BootstrapResult(estimate: float, bootstrap_estimates: ndarray, method: str = 'percentile', ci: tuple[float, float] | None = None, stderr: float | None = None, alpha: float | None = None)[source]¶
Bases:
objectBootstrap uncertainty summary for a scalar statistic.
- class GEVFit(xi: float, loc: float, scale: float, n_blocks: int, block_size: int | None = None, fit_method: str = 'mle', covariance: ndarray | None = None)[source]¶
Bases:
objectFitted generalized extreme value distribution for block maxima.
- class GPDFit(threshold: float, xi: float, beta: float, exceedance_fraction: float, n_exceedances: int, fit_method: str = 'mle', covariance: ndarray | None = None)[source]¶
Bases:
objectFitted generalized Pareto distribution above a threshold.
- class GPDTail(threshold: float, xi: float, beta: float)[source]¶
Bases:
objectConditional generalized-Pareto tail on
[threshold, inf), for splicing.A thin distribution object wrapping
scipy.stats.genparetowith shapexi, scalebetaand locationthreshold. UnlikeGPDFit(which carries the exceedance rate and reports unconditional VaR/TVaR), this represents the tail conditional onX > threshold:cdf(threshold) == 0and the density integrates to one over[threshold, inf). It exposes thecdf/pdf/sample/quantile/mean/varianceinterface thatlossmodels.SplicedSeverityconsumes as a tail. Moments raise when they do not exist (xi >= 1for the mean,xi >= 1/2for the variance), mirroring heavy-tailed severities.
- class TailEstimateResult(estimate: float, method: str, stderr: float | None = None, ci: tuple[float, float] | None = None, n: int | None = None, effective_n: float | None = None, threshold: float | None = None, quantile: float | None = None, diagnostics: dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
objectContainer for tail-estimation results.
- class ThresholdScan(thresholds: ndarray, mean_excess: ndarray, xi: ndarray, beta: ndarray, n_exceedances: ndarray)[source]¶
Bases:
objectThreshold-diagnostic results across a grid of thresholds.
- empirical_tvar(losses, q)[source]¶
Empirical TVaR via the average-quantile (Acerbi-Tasche) plug-in.
Implements
TVaR_q = (1/(1-q)) * integral_q^1 VaR_u duexactly on the empirical distribution: with sorted losses andk = ceil(n*q),TVaR_q = [ sum_{i>k} x_(i) + x_(k) * (k - n*q) ] / (n * (1 - q)).
Correct in the presence of ties/atoms and always
>= empirical_var. Ecosystem-standard estimator shared withrisksimandlossmodels.qmay be scalar (returnsfloat) or array-like (returns array).
- empirical_var(losses, q)[source]¶
Empirical VaR: the order statistic
x_(ceil(n*q)).Implements
VaR_q = inf{x : F(x) >= q}on the empirical distribution (identical tonp.quantile(..., method="inverted_cdf")). This is the ecosystem-standard estimator shared withrisksimandlossmodels; it serves as the crude-Monte-Carlo baseline that the variance-reduced estimators in this subpackage are compared against.qmay be scalar (returnsfloat) or array-like (returns array).
- estimate_tail_probability(data, threshold: float, *, size: int | None = None, alpha: float = 0.05) TailEstimateResult[source]¶
Estimate P(X > threshold) from simulated or observed losses.
- estimate_tail_probability_cmc(conditional_probabilities, *, threshold: float | None = None, alpha: float = 0.05) TailEstimateResult[source]¶
Estimate an exceedance probability from conditional exceedance probabilities.
- Parameters:
conditional_probabilities – Samples of P(X > u | Y) from a conditioning variable Y.
threshold – Optional tail threshold associated with the conditional probabilities.
- estimate_tvar_cmc(conditional_tail_expectations, *, q: float, threshold: float | None = None, alpha: float = 0.05) TailEstimateResult[source]¶
Estimate TVaR from conditional expectations of tail losses.
conditional_tail_expectations should contain draws of E[X | X >= VaR_q, Y] or another conditionally unbiased TVaR contribution.
- estimate_tvar_is(losses, weights, q: float) TailEstimateResult[source]¶
Weighted TVaR under the ecosystem average-quantile convention.
Implements the weighted Acerbi-Tasche plug-in for
TVaR_q = (1/(1-q)) * integral_q^1 VaR_u du: with values sorted, weights normalized, cumulative weightsW_iandkthe weighted-VaR index,TVaR_q = [ sum_{i>k} w_i x_i + x_k (W_k - q) ] / (1 - q).
The atom at VaR contributes only the weight mass above level
q, which keeps the estimator coherent with ties and makes it reduce exactly toempirical_tvarwhen all weights are equal.
- fit_gpd(excesses, threshold: float = 0.0, method: str = 'mle') GPDFit[source]¶
Fit a generalized Pareto distribution to excess losses.
- fit_spliced_gpd(body, data, *, threshold: float, weight: float | None = None)[source]¶
Fit a GPD tail above
threshold(peaks-over-threshold) and splice it ontobody, returning alossmodels.SplicedSeverity.- Parameters:
body (severity model) – Any fitted body severity (e.g. a
lossmodelsLognormal).data (array-like) – Loss sample used to fit the tail and, by default, to set the body mass.
threshold (float) – Peaks-over-threshold cutoff
u.weight (float, optional) – Body mass
P(X <= u). Defaults to1 - exceedance_fractionfrom the POT fit (the empirical fraction at or below the threshold), consistent with the fitted exceedance rate.package. (Requires the lossmodels)
- splice_gpd_tail(body, fit, *, weight: float | None = None)[source]¶
Splice an already-fitted GPD tail (a
GPDFit) ontobody.Returns a
lossmodels.SplicedSeveritywhose body isbody(any fitted body severity) and whose tail is the conditional GPD offitabove its threshold. The mixing weight defaults to the body mass implied by the fit,1 - fit.exceedance_fraction(i.e.P(X <= threshold)).