## distributions.Grid


A distribution on the points `0, step, 2*step, ...`: the discretized


Usage


``` python
distributions.Grid()
```


representation that FFT and Panjer aggregation work on.


## Parameters


`step: float`  
Grid step; must be positive.

`probs: list of float`  
Probabilities at `0, step, ...`; non-negative, summing to 1.


## Raises


`ValueError`  
If the step is not positive or the probabilities are invalid.


## Examples

``` python
>>> from prospicio.distributions import Grid, Lognormal
>>> grid, report = Grid.local_moment(Lognormal(7.0, 0.5), 100.0, 200)
>>> report.tail_mass < 1e-8
```

True


## Attributes

| Name | Description |
|----|----|
| [probs](#probs) | Probabilities at `0, step, 2*step, ...`. |
| [step](#step) | Grid step. |

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


#### probs


Probabilities at `0, step, 2*step, ...`.


`probs: list[float]`


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


#### step


Grid step.


`step: 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). |
| [lev()](#lev) | Limited expected value `E[min(X, limit)]`, exact on the grid. |
| [local_moment()](#local_moment) | Discretizes a severity by local moment matching on the mean. |
| [lower()](#lower) | Discretizes a severity by moving each cell's mass to its left end: a |
| [map()](#map) | The distribution of `f(X)` on the same step. |
| [mean()](#mean) | Mean of the distribution. |
| [quantile()](#quantile) | Smallest grid point [x](pricing.TabulatedCurve.md#prospicio.pricing.TabulatedCurve.x) with `P(X <= x) >= p`. |
| [rounding()](#rounding) | Discretizes a severity by rounding each loss to the nearest point. |
| [stop_loss()](#stop_loss) | Expected excess `E[max(X - retention, 0)]`, exact on the grid. |
| [variance()](#variance) | Variance of the distribution. |

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


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

`attachment: float`  


##### Returns


`float`  


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


#### lev()


Limited expected value `E[min(X, limit)]`, exact on the grid.


Usage


``` python
lev(limit)
```


##### Parameters


`limit: float`  


##### Returns


`float`  


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


#### local_moment()


Discretizes a severity by local moment matching on the mean.


Usage


``` python
local_moment(severity, step, points)
```


##### Parameters


`severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)`  

`step: float`  

`points: int`  


##### Returns


`tuple of (Grid, DiscretizationReport)`  


##### Raises


`ValueError`  
If [step](distributions.Grid.md#prospicio.distributions.Grid.step) is not positive or [points](aggregate.CompoundReport.md#prospicio.aggregate.CompoundReport.points) is 0.


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


#### lower()


Discretizes a severity by moving each cell's mass to its left end: a


Usage


``` python
lower(severity, step, points)
```


stochastic lower bound.


##### Parameters


`severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)`  

`step: float`  

`points: int`  


##### Returns


`tuple of (Grid, DiscretizationReport)`  


##### Raises


`ValueError`  
If [step](distributions.Grid.md#prospicio.distributions.Grid.step) is not positive or [points](aggregate.CompoundReport.md#prospicio.aggregate.CompoundReport.points) is 0.


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


#### map()


The distribution of `f(X)` on the same step.


Usage


``` python
map(f)
```


Each point's mass moves to `f(x)`. A value between two points is split between them so its mean is kept, so the mean is always exact and the whole distribution is exact when every value lands on a point. `f` is a Python callable, evaluated once per point with mass.


##### Parameters


`f: callable`  
Maps a loss to a finite, non-negative value.


##### Returns


`tuple of (Grid, bool)`  
The grid and whether every value landed on a grid point.


##### Raises


`ValueError`  
If `f` returns a negative or non-finite value.


##### Examples

``` python
>>> from prospicio.distributions import Grid
>>> x = Grid(1.0, [0.2, 0.3, 0.3, 0.2])
>>> layer, exact = x.map(lambda v: min(max(v - 1.0, 0.0), 1.0))
>>> layer.probs, exact
```

(\[0.5, 0.5\], True)

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


#### mean()


Mean of the distribution.


Usage


``` python
mean()
```


##### Returns


`float`  


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


#### quantile()


Smallest grid point [x](pricing.TabulatedCurve.md#prospicio.pricing.TabulatedCurve.x) with `P(X <= x) >= p`.


Usage


``` python
quantile(p)
```


##### Parameters


`p: float`  


##### Returns


`float`  


##### Raises


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


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


#### rounding()


Discretizes a severity by rounding each loss to the nearest point.


Usage


``` python
rounding(severity, step, points)
```


##### Parameters


`severity: (Lognormal, Grid, Pareto, PiecewisePareto, LogAffinePareto or GeneralizedPareto)`  

`step: float`  

`points: int`  


##### Returns


`tuple of (Grid, DiscretizationReport)`  


##### Raises


`ValueError`  
If [step](distributions.Grid.md#prospicio.distributions.Grid.step) is not positive or [points](aggregate.CompoundReport.md#prospicio.aggregate.CompoundReport.points) is 0.


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


#### stop_loss()


Expected excess `E[max(X - retention, 0)]`, exact on the grid.


Usage


``` python
stop_loss(retention)
```


##### Parameters


`retention: float`  


##### Returns


`float`  


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


#### variance()


Variance of the distribution.


Usage


``` python
variance()
```


##### Returns


`float`
