distributions.Grid
A distribution on the points 0, step, 2*step, ...: the discretized
Usage
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.
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-8True
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.
|
| 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.
|
| variance() | Variance of the distribution. |
cdf()
Distribution function P(X <= x).
Usage
cdf(x)Parameters
x: float
Returns
float
layer()
Expected loss to the layer limit xs attachment.
Usage
layer(limit, attachment)Parameters
limit: floatattachment: float
Returns
float
lev()
Limited expected value E[min(X, limit)], exact on the grid.
Usage
lev(limit)Parameters
limit: float
Returns
float
local_moment()
Discretizes a severity by local moment matching on the mean.
Usage
local_moment(severity, step, points)Parameters
severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)step: floatpoints: int
Returns
tuple of (Grid, DiscretizationReport)
Raises
lower()
Discretizes a severity by moving each cell’s mass to its left end: a
Usage
lower(severity, step, points)stochastic lower bound.
Parameters
severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)step: floatpoints: int
Returns
tuple of (Grid, DiscretizationReport)
Raises
map()
The distribution of f(X) on the same step.
Usage
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
freturns 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
mean()Returns
float
quantile()
Smallest grid point x with P(X <= x) >= p.
Usage
quantile(p)Parameters
p: float
Returns
float
Raises
ValueError-
If p is outside
[0, 1].
rounding()
Discretizes a severity by rounding each loss to the nearest point.
Usage
rounding(severity, step, points)Parameters
severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)step: floatpoints: int
Returns
tuple of (Grid, DiscretizationReport)
Raises
stop_loss()
Expected excess E[max(X - retention, 0)], exact on the grid.
Usage
stop_loss(retention)Parameters
retention: float
Returns
float
variance()
Variance of the distribution.
Usage
variance()Returns
float