Skip to main content

distributions.Discrete

A distribution on finitely many values, of either sign and any spacing:

Usage

Source

distributions.Discrete()

a row of a P&L (premium less loss less expenses) or any other signed outcome, as the Python package aggregate’s GridDistribution on an irregular support.

Values may repeat and come in any order: equal values (to 1e-12) are merged and zero probabilities dropped. The probabilities must sum to 1 within 1e-5 (aggregate 2.1.0’s rule for dsev); pass normalize=True to rescale weights or counts of any positive total. Quantiles and TVaR follow aggregate exactly; tvar is the upper tail even when the values are a payoff, whose adverse tail is the low one.

Parameters

values: list of float
probs: list of float

Non-negative, summing to 1 within 1e-5.

normalize: bool = False
Divide probs by their sum first.

Raises

ValueError
If the lengths differ, a value is not finite, a probability is negative or none is positive, or (without normalize) the probabilities sum to more than 1e-5 away from 1.

Examples

>>> from prospicio.distributions import Discrete
>>> # A margin: 9 less the loss of two claims of 1, 2 or 4.
>>> m = Discrete([7, 6, 5, 4, 3, 1], [0.25, 0.3, 0.09, 0.2, 0.12, 0.04])
>>> round(m.mean(), 12), m.quantile(0.01)

(5.2, 1.0)

>>> round(m.tvar(0.01), 6)

5.242424

Attributes

Name Description
probs Their probabilities, summing to 1.
values The distinct values, ascending.

probs

Their probabilities, summing to 1.

probs: list[float]


values

The distinct values, ascending.

values: list[float]

Methods

Name Description
cdf() P(X <= x).
mean() The mean.
pmf() The probability of exactly x (to 1e-12).
quantile() The lower quantile, the smallest value with F >= p.
quantile_upper() The upper quantile, the smallest value with F > p; None at
skewness() The skewness, or None when the variance is 0.
std_dev() The standard deviation.
survival() P(X > x).
tail() The return-period table, as aggregate’s tail_df: each period
tvar() Tail value at risk at p: the mean of the upper 1 - p of the
variance() The variance.

cdf()

P(X <= x).

Usage

Source

cdf(x)
Parameters
x: float
Returns
float

mean()

The mean.

Usage

Source

mean()
Returns
float

pmf()

The probability of exactly x (to 1e-12).

Usage

Source

pmf(x)
Parameters
x: float
Returns
float

quantile()

The lower quantile, the smallest value with F >= p.

Usage

Source

quantile(p)
Parameters
p: float
In [0, 1].
Returns
float

quantile_upper()

The upper quantile, the smallest value with F > p; None at

Usage

Source

quantile_upper(p)

p = 1.

Parameters
p: float
In [0, 1].
Returns
float or None

skewness()

The skewness, or None when the variance is 0.

Usage

Source

skewness()
Returns
float or None

std_dev()

The standard deviation.

Usage

Source

std_dev()
Returns
float

survival()

P(X > x).

Usage

Source

survival(x)
Parameters
x: float
Returns
float

tail()

The return-period table, as aggregate’s tail_df: each period

Usage

Source

tail(periods=None)

T read from both tails, at P = 1 / T and P = 1 - 1 / T. A payoff (a P&L) is read off the low rows, a loss off the high ones.

Parameters
periods: list of float = None
At least 1; aggregate’s 2, 5, 10, 25, 50, 100, 200, 250, 500, 1000 by default.
Returns
dict
Columns p, period, var, tvar, excess (VaR less the mean) and var_to_mean (None near a zero mean).

tvar()

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

Usage

Source

tvar(p)

distribution, the upper tail even for a payoff.

Parameters
p: float
In [0, 1].
Returns
float

variance()

The variance.

Usage

Source

variance()
Returns
float