distributions.Discrete
A distribution on finitely many values, of either sign and any spacing:
Usage
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 floatprobs: 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 than1e-5away 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
cdf(x)Parameters
x: float
Returns
float
mean()
The mean.
Usage
mean()Returns
float
pmf()
The probability of exactly x (to 1e-12).
Usage
pmf(x)Parameters
x: float
Returns
float
quantile()
The lower quantile, the smallest value with F >= p.
Usage
quantile(p)Parameters
p: float-
In
[0, 1].
Returns
float
quantile_upper()
The upper quantile, the smallest value with F > p; None at
Usage
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
skewness()Returns
float or None
std_dev()
The standard deviation.
Usage
std_dev()Returns
float
survival()
P(X > x).
Usage
survival(x)Parameters
x: float
Returns
float
tail()
The return-period table, as aggregate’s tail_df: each period
Usage
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
tvar()
Tail value at risk at p: the mean of the upper 1 - p of the
Usage
tvar(p)distribution, the upper tail even for a payoff.
Parameters
p: float-
In
[0, 1].
Returns
float
variance()
The variance.
Usage
variance()Returns
float