Skip to contents

The slow path for a distribution the package does not have: give its cdf, and its quantile function if you have one (sampling inverts the cdf by bisection otherwise, about a hundred cdf calls per draw). The mean, variance, limited expected values and layer moments are computed by Gauss-Legendre quadrature of the survival function between the distribution's own quantiles, ignoring the probability above the 1 - 1e-12 quantile. It goes anywhere a severity does (layers, compound_distribution(), simulate_events(), copula marginals, mixture_distribution()); calculations that meet one run single-threaded on R's main thread, since every value calls back into R.

Usage

custom_distribution(cdf, quantile = NULL, name = "custom")

Arguments

cdf

function(x) returning P(X <= x) for one x >= 0: a number in [0, 1], non-decreasing in x. Losses are non-negative.

quantile

Optional function(p) returning the smallest x with cdf(x) >= p.

name

Shown in errors and when printed.

Value

A custom_distribution object, which inherits from distribution. Construction fails if a function errors, returns a value out of range, or the cdf never reaches 1 - 1e-12.

Details

Properties: d@name, d@has_quantile, d@upper (the 1 - 1e-12 quantile, where the integrals stop) and d@last_error (the first error a function raised after construction, or ""; that value became NaN).

Supports the same operations as pareto.

Examples

d <- custom_distribution(function(x) 1 - exp(-x / 100), name = "exponential")
mean(d)
#> [1] 100
lev(d, 50)
#> [1] 39.34693