## distributions.Discrete


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


Usage

``` python
distributions.Discrete()
```


a row of a P&L (premium less loss less expenses) or any other signed outcome, as the Python package [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.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](aggregate.Clash.md#prospicio.aggregate.Clash.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](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate) exactly; [tvar](risk.PotTail.md#prospicio.risk.PotTail.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](pricing.Portfolio.md#prospicio.pricing.Portfolio.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

``` python
>>> 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)

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

5.242424


## Attributes

| Name | Description |
|----|----|
| [probs](#probs) | Their probabilities, summing to 1. |
| [values](#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()](#cdf) | `P(X <= x)`. |
| [mean()](#mean) | The mean. |
| [pmf()](#pmf) | The probability of exactly [x](distributions.Ogive.md#prospicio.distributions.Ogive.x) (to `1e-12`). |
| [quantile()](#quantile) | The lower quantile, the smallest value with `F >= p`. |
| [quantile_upper()](#quantile_upper) | The upper quantile, the smallest value with `F > p`; None at |
| [skewness()](#skewness) | The skewness, or None when the variance is 0. |
| [std_dev()](#std_dev) | The standard deviation. |
| [survival()](#survival) | `P(X > x)`. |
| [tail()](#tail) | The return-period table, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `tail_df`: each period |
| [tvar()](#tvar) | Tail value at risk at [p](models.Elpd.md#prospicio.models.Elpd.p): the mean of the upper `1 - p` of the |
| [variance()](#variance) | The variance. |

------------------------------------------------------------------------


#### cdf()


`P(X <= x)`.


Usage

``` python
cdf(x)
```


##### Parameters


`x: float`  


##### Returns


`float`  


------------------------------------------------------------------------


#### mean()


The mean.


Usage

``` python
mean()
```


##### Returns


`float`  


------------------------------------------------------------------------


#### pmf()


The probability of exactly [x](distributions.Ogive.md#prospicio.distributions.Ogive.x) (to `1e-12`).


Usage

``` python
pmf(x)
```


##### Parameters


`x: float`  


##### Returns


`float`  


------------------------------------------------------------------------


#### quantile()


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


Usage

``` python
quantile(p)
```


##### Parameters


`p: float`  
In `[0, 1]`.


##### Returns


`float`  


------------------------------------------------------------------------


#### quantile_upper()


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


Usage

``` python
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

``` python
skewness()
```


##### Returns


`float or None`  


------------------------------------------------------------------------


#### std_dev()


The standard deviation.


Usage

``` python
std_dev()
```


##### Returns


`float`  


------------------------------------------------------------------------


#### survival()


`P(X > x)`.


Usage

``` python
survival(x)
```


##### Parameters


`x: float`  


##### Returns


`float`  


------------------------------------------------------------------------


#### tail()


The return-period table, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `tail_df`: each period


Usage

``` python
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](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s 2, 5, 10, 25, 50, 100, 200, 250, 500, 1000 by default.


##### Returns


`dict`  
Columns [p](models.Elpd.md#prospicio.models.Elpd.p), [period](esg.Cycle.md#prospicio.esg.Cycle.period), [var](risk.PotTail.md#prospicio.risk.PotTail.var), [tvar](risk.PotTail.md#prospicio.risk.PotTail.tvar), `excess` (VaR less the mean) and `var_to_mean` (None near a zero mean).


------------------------------------------------------------------------


#### tvar()


Tail value at risk at [p](models.Elpd.md#prospicio.models.Elpd.p): the mean of the upper `1 - p` of the


Usage

``` python
tvar(p)
```


distribution, the upper tail even for a payoff.


##### Parameters


`p: float`  
In `[0, 1]`.


##### Returns


`float`  


------------------------------------------------------------------------


#### variance()


The variance.


Usage

``` python
variance()
```


##### Returns


`float`
