## distributions.Custom


A loss severity defined by your own distribution function: the slow


Usage


``` python
distributions.Custom()
```


path for a distribution the library does not have.

Give the cdf, and the quantile function if you have one (sampling inverts the cdf by bisection otherwise, about a hundred cdf calls per draw). The mean, variance, limited expected values and layer moments are computed by Gauss-Legendre quadrature of the survival function between the distribution's own quantiles, ignoring the probability above the `1 - 1e-12` quantile. A [Custom](distributions.Custom.md#prospicio.distributions.Custom) goes anywhere a severity does (layers, compound distributions, simulated events, copula marginals, mixtures); calculations that meet one run single-threaded, since every value calls back into Python.


## Parameters


`cdf: callable`  
`cdf(x) -> float`: `P(X <= x)` for `x >= 0`, in `[0, 1]` and non-decreasing. Losses are non-negative.

`quantile: callable`  
`quantile(p) -> float`: the smallest [x](pricing.TabulatedCurve.md#prospicio.pricing.TabulatedCurve.x) with `cdf(x) >= p`.

`name: str = ``"custom"`  
Shown in errors and `repr`.


## Raises


`ValueError`  
If a callable raises or returns a value out of range, or the cdf never reaches `1 - 1e-12` at a finite loss. An error in a later call makes that value `nan`; [last_error](distributions.Custom.md#prospicio.distributions.Custom.last_error) says why.


## Examples

``` python
>>> import math
>>> from prospicio.distributions import Custom
>>> d = Custom(lambda x: 1 - math.exp(-x / 100), name="exponential")
>>> round(d.mean(), 6)
```

100.0

``` python
>>> round(d.lev(50), 6) == round(100 * (1 - math.exp(-0.5)), 6)
```

True


## Attributes

| Name | Description |
|----|----|
| [has_quantile](#has_quantile) | Whether a quantile function was given. |
| [last_error](#last_error) | The first error raised by a callable since construction, or `None`. |
| [name](#name) | The name given at construction. |
| [upper](#upper) | The `1 - 1e-12` quantile, where the moment integrals stop. |

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


#### has_quantile


Whether a quantile function was given.


`has_quantile: bool`


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


#### last_error


The first error raised by a callable since construction, or `None`.


`last_error: str | None`


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


#### name


The name given at construction.


`name: str`


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


#### upper


The `1 - 1e-12` quantile, where the moment integrals stop.


`upper: float`


## Methods

| Name | Description |
|----|----|
| [cdf()](#cdf) | Distribution function `P(X <= x)`. |
| [layer()](#layer) | Expected loss to the layer [limit](reinsurance.Layer.md#prospicio.reinsurance.Layer.limit) xs [attachment](reinsurance.Layer.md#prospicio.reinsurance.Layer.attachment). |
| [layer_second_moment()](#layer_second_moment) | Second moment of the loss to the layer [limit](reinsurance.Layer.md#prospicio.reinsurance.Layer.limit) xs |
| [layer_variance()](#layer_variance) | Variance of the loss to the layer [limit](reinsurance.Layer.md#prospicio.reinsurance.Layer.limit) xs [attachment](reinsurance.Layer.md#prospicio.reinsurance.Layer.attachment). |
| [lev()](#lev) | Limited expected value `E[min(X, limit)]`. |
| [mean()](#mean) | Mean of the distribution (`inf` if it does not exist). |
| [quantile()](#quantile) | Quantile: the smallest [x](pricing.TabulatedCurve.md#prospicio.pricing.TabulatedCurve.x) with `P(X <= x) >= p`. |
| [sample()](#sample) | [n](distributions.Binomial.md#prospicio.distributions.Binomial.n) draws from stream `stream` of the generator keyed by |
| [std()](#std) | Standard deviation of the distribution. |
| [stop_loss()](#stop_loss) | Expected excess over a retention, `E[max(X - retention, 0)]`. |
| [survival()](#survival) | Survival function `P(X > x)`, accurate far into the tail. |
| [variance()](#variance) | Variance of the distribution (`inf` if it does not exist). |

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


#### cdf()


Distribution function `P(X <= x)`.


Usage


``` python
cdf(x)
```


##### Parameters


`x: float`  


##### Returns


`float`  


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


#### layer()


Expected loss to the layer [limit](reinsurance.Layer.md#prospicio.reinsurance.Layer.limit) xs [attachment](reinsurance.Layer.md#prospicio.reinsurance.Layer.attachment).


Usage


``` python
layer(limit, attachment)
```


##### Parameters


`limit: float`  
`inf` for an unlimited layer.

`attachment: float`  


##### Returns


`float`  


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


#### layer_second_moment()


Second moment of the loss to the layer [limit](reinsurance.Layer.md#prospicio.reinsurance.Layer.limit) xs


Usage


``` python
layer_second_moment(limit, attachment)
```


[attachment](reinsurance.Layer.md#prospicio.reinsurance.Layer.attachment).


##### Parameters


`limit: float`  

`attachment: float`  


##### Returns


`float`  


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


#### layer_variance()


Variance of the loss to the layer [limit](reinsurance.Layer.md#prospicio.reinsurance.Layer.limit) xs [attachment](reinsurance.Layer.md#prospicio.reinsurance.Layer.attachment).


Usage


``` python
layer_variance(limit, attachment)
```


##### Parameters


`limit: float`  

`attachment: float`  


##### Returns


`float`  


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


#### lev()


Limited expected value `E[min(X, limit)]`.


Usage


``` python
lev(limit)
```


##### Parameters


`limit: float`  


##### Returns


`float`  


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


#### mean()


Mean of the distribution (`inf` if it does not exist).


Usage


``` python
mean()
```


##### Returns


`float`  


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


#### quantile()


Quantile: the smallest [x](pricing.TabulatedCurve.md#prospicio.pricing.TabulatedCurve.x) with `P(X <= x) >= p`.


Usage


``` python
quantile(p)
```


##### Parameters


`p: float`  
Probability in `[0, 1]`.


##### Returns


`float`  


##### Raises


`ValueError`  
If [p](models.Elpd.md#prospicio.models.Elpd.p) is outside `[0, 1]`.


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


#### sample()


[n](distributions.Binomial.md#prospicio.distributions.Binomial.n) draws from stream `stream` of the generator keyed by


Usage


``` python
sample(n, seed, stream=0)
```


[seed](aggregate.EventSet.md#prospicio.aggregate.EventSet.seed).


##### Parameters


`n: int`  

`seed: int`  

`stream: int = ``0`  


##### Returns


`list of float`  


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


#### std()


Standard deviation of the distribution.


Usage


``` python
std()
```


##### Returns


`float`  


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


#### stop_loss()


Expected excess over a retention, `E[max(X - retention, 0)]`.


Usage


``` python
stop_loss(retention)
```


##### Parameters


`retention: float`  


##### Returns


`float`  


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


#### survival()


Survival function `P(X > x)`, accurate far into the tail.


Usage


``` python
survival(x)
```


##### Parameters


`x: float`  


##### Returns


`float`  


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


#### variance()


Variance of the distribution (`inf` if it does not exist).


Usage


``` python
variance()
```


##### Returns


`float`
