Skip to main content

distributions.Grid

A distribution on the points 0, step, 2*step, ...: the discretized

Usage

Source

distributions.Grid()

representation that FFT and Panjer aggregation work on.

Parameters

step: float

Grid step; must be positive.

probs: list of float

Probabilities at 0, step, ...; non-negative, summing to 1 within 1e-9.

normalize: bool = False
Divide probs by their sum first, for hand-built or rounded probabilities; the sum must be positive.

Raises

ValueError
If the step is not positive or the probabilities are invalid.

Examples

>>> from prospicio.distributions import Grid, Lognormal
>>> grid, report = Grid.local_moment(Lognormal(7.0, 0.5), 100.0, 200)
>>> report.tail_mass < 1e-8

True

Attributes

Name Description
probs Probabilities at 0, step, 2*step, ....
step Grid step.

probs

Probabilities at 0, step, 2*step, ....

probs: list[float]


step

Grid step.

step: float

Methods

Name Description
cdf() Distribution function P(X <= x).
layer() Expected loss to the layer limit xs attachment.
lev() Limited expected value E[min(X, limit)], exact on the grid.
local_moment() Discretizes a severity by local moment matching on the mean.
lower() Discretizes a severity by moving each cell’s mass to its left end: a
map() The distribution of f(X) on the same step.
mean() Mean of the distribution.
quantile() Smallest grid point x with P(X <= x) >= p.
remove_fuzz() The grid with every probability below eps set to 0: the
rounding() Discretizes a severity by rounding each loss to the nearest point.
stop_loss() Expected excess E[max(X - retention, 0)], exact on the grid.
tvar() Tail value at risk at p: the mean of the worst 1 - p of the
tvar_threshold() The level t with TVaR(t) = VaR(p) (the lower VaR), as
variance() Variance of the distribution.
window_tvar() Window TVaR: the mean of the grid between the levels p_low and

cdf()

Distribution function P(X <= x).

Usage

Source

cdf(x)
Parameters
x: float
Returns
float

layer()

Expected loss to the layer limit xs attachment.

Usage

Source

layer(limit, attachment)
Parameters
limit: float
attachment: float
Returns
float

lev()

Limited expected value E[min(X, limit)], exact on the grid.

Usage

Source

lev(limit)
Parameters
limit: float
Returns
float

local_moment()

Discretizes a severity by local moment matching on the mean.

Usage

Source

local_moment(severity, step, points)
Parameters
severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)
step: float
points: int
Returns
tuple of (Grid, DiscretizationReport)
Raises
ValueError
If step is not positive or points is 0.

lower()

Discretizes a severity by moving each cell’s mass to its left end: a

Usage

Source

lower(severity, step, points)

stochastic lower bound.

Parameters
severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)
step: float
points: int
Returns
tuple of (Grid, DiscretizationReport)
Raises
ValueError
If step is not positive or points is 0.

map()

The distribution of f(X) on the same step.

Usage

Source

map(f)

Each point’s mass moves to f(x). A value between two points is split between them so its mean is kept, so the mean is always exact and the whole distribution is exact when every value lands on a point. f is a Python callable, evaluated once per point with mass.

Parameters
f: callable
Maps a loss to a finite, non-negative value.
Returns
tuple of (Grid, bool)
The grid and whether every value landed on a grid point.
Raises
ValueError
If f returns a negative or non-finite value.
Examples
>>> from prospicio.distributions import Grid
>>> x = Grid(1.0, [0.2, 0.3, 0.3, 0.2])
>>> layer, exact = x.map(lambda v: min(max(v - 1.0, 0.0), 1.0))
>>> layer.probs, exact

([0.5, 0.5], True)


mean()

Mean of the distribution.

Usage

Source

mean()
Returns
float

quantile()

Smallest grid point x with P(X <= x) >= p.

Usage

Source

quantile(p)
Parameters
p: float
Returns
float
Raises
ValueError
If p is outside [0, 1].

remove_fuzz()

The grid with every probability below eps set to 0: the

Usage

Source

remove_fuzz(eps=...)

round-off an FFT leaves where the true mass is zero, as aggregate’s remove_fuzz. Tower.on_grid already removes it from its ceded and net grids.

Parameters
eps: float = machine epsilon (2.22e-16)
Returns
Grid
Examples
>>> from prospicio.distributions import Grid
>>> Grid(1.0, [0.5, 0.5 - 1e-20, 1e-20]).remove_fuzz().probs[2]

0.0


rounding()

Discretizes a severity by rounding each loss to the nearest point.

Usage

Source

rounding(severity, step, points)
Parameters
severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)
step: float
points: int
Returns
tuple of (Grid, DiscretizationReport)
Raises
ValueError
If step is not positive or points is 0.

stop_loss()

Expected excess E[max(X - retention, 0)], exact on the grid.

Usage

Source

stop_loss(retention)
Parameters
retention: float
Returns
float

tvar()

Tail value at risk at p: the mean of the worst 1 - p of the

Usage

Source

tvar(p)

distribution, the point at the VaR counted with its mass above p.

Parameters
p: float
Returns
float
Raises
ValueError
If p is outside [0, 1].

tvar_threshold()

The level t with TVaR(t) = VaR(p) (the lower VaR), as

Usage

Source

tvar_threshold(p)

aggregate’s tvar_threshold; t <= p, and p = 0 gives 0.

Parameters
p: float
Returns
float
Raises
ValueError
If p is outside [0, 1].
Examples
>>> from prospicio.distributions import Grid
>>> g = Grid(1.0, [0.4, 0.3, 0.2, 0.1])
>>> t = g.tvar_threshold(0.85)
>>> round(g.tvar(t), 12) == g.quantile(0.85)

True


variance()

Variance of the distribution.

Usage

Source

variance()
Returns
float

window_tvar()

Window TVaR: the mean of the grid between the levels p_low and

Usage

Source

window_tvar(p_low, p_high)

p_high, each point counted with the share of its mass inside the window, ((1 - p_low) tvar(p_low) - (1 - p_high) tvar(p_high)) / (p_high - p_low).

Parameters
p_low: float

0 <= p_low < p_high <= 1.

p_high: float
0 <= p_low < p_high <= 1.
Returns
float
Examples
>>> from prospicio.distributions import Grid
>>> g = Grid(1.0, [0.5, 0.3, 0.2])
>>> round(g.window_tvar(0.6, 0.9), 12)

1.333333333333