Skip to main content

distributions.Sampled

A distribution known only through equally weighted draws.

Usage

Source

distributions.Sampled()

Parameters

draws: list of float
Non-empty, all finite.

Raises

ValueError
If draws is empty or holds a value that is not finite.

Examples

>>> from prospicio.distributions import Sampled
>>> s = Sampled([1.0, 2.0, 3.0, 4.0])
>>> s.tvar(0.5)

3.5

Attributes

Name Description
draws The draws, in simulation order.

draws

The draws, in simulation order.

draws: list[float]

Methods

Name Description
cdf() Empirical distribution function P(X <= x).
mean() Mean of the draws.
quantile() Inverted empirical cdf (R type = 1).
tvar() Tail value at risk at level p: the mean of the worst 1 - p.
var() Value at risk at level p.
variance() Variance of the draws (dividing by n).
window_tvar() Window TVaR: the mean of the draws between the levels p_low and

cdf()

Empirical distribution function P(X <= x).

Usage

Source

cdf(x)
Parameters
x: float
Returns
float

mean()

Mean of the draws.

Usage

Source

mean()
Returns
float

quantile()

Inverted empirical cdf (R type = 1).

Usage

Source

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

tvar()

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

Usage

Source

tvar(p, method="exact")
Parameters
p: float
method: str = "exact"
"exact" (the default: the empirical distribution, mass 1/n per draw), "linear" (the mean of the linear quantile function over [p, 1]) or "whole_years" (the mean of the k largest draws, k = max(1, floor((1 - p) n)), equal to "exact" when (1 - p) n is whole).
Returns
float
Raises
ValueError
If p is outside [0, 1] or method is unknown.
Examples
>>> from prospicio.distributions import Sampled
>>> years = Sampled([float(x) for x in range(1, 11)])
>>> years.var(0.75), years.var(0.75, method="kth_largest")

(8.0, 9.0)

>>> years.tvar(0.75, method="whole_years")

9.5


var()

Value at risk at level p.

Usage

Source

var(p, method="inverted_cdf")
Parameters
p: float
method: str = "inverted_cdf"
"inverted_cdf" (the default, R type = 1), "linear" (numpy’s default, R type = 7) or "kth_largest" (the k-th largest draw, k = max(1, floor((1 - p) n)): with years as draws, the k-th worst year, one draw above "inverted_cdf" unless both are the largest).
Returns
float
Raises
ValueError
If p is outside [0, 1] or method is unknown.

variance()

Variance of the draws (dividing by n).

Usage

Source

variance()
Returns
float

window_tvar()

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

Usage

Source

window_tvar(p_low, p_high, method="exact")

p_high, a band of bad years such as the 98th to 99th percentiles. It equals ((1 - p_low) tvar(p_low) - (1 - p_high) tvar(p_high)) / (p_high - p_low) under "exact" and "linear"; under "whole_years" it is the mean of the draws ranked floor((1 - p_high) n) + 1 to floor((1 - p_low) n) from the top (years 21 to 40 of 2,000 between 0.98 and 0.99), an error when that holds no draw.

Parameters
p_low: float

0 <= p_low < p_high <= 1.

p_high: float

0 <= p_low < p_high <= 1.

method: str = "exact"
As tvar.
Returns
float
Examples
>>> from prospicio.distributions import Sampled
>>> years = Sampled([float(x) for x in range(1, 11)])
>>> years.window_tvar(0.7, 0.9)

8.5

>>> years.window_tvar(0.5, 1.0) == years.tvar(0.5)

True