## reinsurance.Panel


The reinsurers on a tower and their signed lines, applied to a tower's


Usage

``` python
reinsurance.Panel()
```


simulated years to draw which reinsurers default (`docs/design/reinsurer-default.md`).

A line is a share of a layer's ceded loss (after the layer's [share](reinsurance.Layer.md#prospicio.reinsurance.Layer.share)), and the lines of a layer the panel names must sum to 1 (to 1e-9), checked when the panel is applied; a layer the panel does not name carries no credit risk.

Reinsurer [r](distributions.NegativeBinomial.md#prospicio.distributions.NegativeBinomial.r)'s exposure in a year is `E = sum over l of s_rl X_l`, with `X_l` layer `l`'s ceded loss and `s_rl` its line; if it defaults, the cedant loses `(1 - R_r) (E - C_r)^+`, with `R_r` its recovery rate and `C_r` its collateral. Defaults follow Vasicek's one-factor model: given the year's factor [z](reserving.CalendarYearTest.md#prospicio.reserving.CalendarYearTest.z), reinsurer [r](distributions.NegativeBinomial.md#prospicio.distributions.NegativeBinomial.r) defaults with probability `Phi((Phi^-1(p_r) - sqrt(rho_r) z) / sqrt(1 - rho_r))`, and `z = -Phi^-1(U)`, where `U` is the year's rank by its driver (the gross loss, or [with_driver()](reinsurance.Panel.md#prospicio.reinsurance.Panel.with_driver)), ties broken at random, so the worst years have the highest probability of default. Each year draws from its own random stream, so the result has the same bits on any number of threads.


## Parameters


`reinsurers: list of Reinsurer`  
At least one, with unique names.


## Raises


`ValueError`  
For no reinsurers or two with the same name.


## Examples

``` python
>>> from prospicio.reinsurance import Layer, Panel, Reinsurer, Tower
>>> years = Tower([Layer("10x10", 10.0, 10.0)]).apply_annual([5.0, 15.0, 30.0])
>>> # Re A certainly defaults and pays back 40% of what it owes.
>>> panel = (Panel([Reinsurer("Re A", 1.0, 0.4), Reinsurer("Re B", 0.0, 0.4)])
...          .with_line("Re A", "10x10", 0.5)
...          .with_line("Re B", "10x10", 0.5))
>>> after = panel.apply(years, seed=7)
>>> list(after.marginal(["credit_loss", "10x10"]).draws)
```

\[0.0, 1.5, 3.0\]

``` python
>>> list(after.marginal(["net_after_default", "retained"]).draws)
```

\[5.0, 11.5, 23.0\]


## Attributes

| Name | Description |
|----|----|
| [reinsurers](#reinsurers) | The panel's reinsurers, in panel order (the order they draw in). |

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


#### reinsurers


The panel's reinsurers, in panel order (the order they draw in).


`reinsurers: list[Reinsurer]`


## Methods

| Name | Description |
|----|----|
| [apply()](#apply) | A tower's one-year result after reinsurer default. |
| [apply_term()](#apply_term) | A term's paths after reinsurer default. |
| [by_reinsurer()](#by_reinsurer) | Each reinsurer's credit loss, exposure and default in each year, |
| [by_reinsurer_term()](#by_reinsurer_term) | Each reinsurer's credit loss, exposure and default in each year of |
| [with_driver()](#with_driver) | The panel ranking the years by `by_year` instead of the gross |
| [with_line()](#with_line) | The panel with reinsurer `reinsurer` writing `line` of layer |

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


#### apply()


A tower's one-year result after reinsurer default.


Usage

``` python
apply(result, seed=0)
```


The result has the input's components, copied bit for bit, then `("credit_loss", l)` for every layer `l` of the input, in the input's order (zero on a layer the panel does not name), then `("recovered", l)`, the layer's ceded loss less its credit loss, and `("net_after_default", "retained")`, the net loss plus the year's credit loss. A reinsurer's credit loss is split over its layers in proportion to its exposure on each. On a labelled result the exposures sum each layer's ceded loss over the label combinations, and the new components get `""` in every label dimension.


##### Parameters


`result: PredictiveDistribution`  
A tower's one-year result ([Tower.apply](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply), [apply_aggregate](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_aggregate) or [apply_annual](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_annual)).

`seed: int = ``0`  
The default draws' seed; their streams are apart from the events' even with the events' seed.


##### Returns


`PredictiveDistribution`  


##### Raises


`ValueError`  
For a result that is no tower's one-year result or one a panel was already applied to, a line on a layer the result does not have, a named layer whose lines do not sum to 1, or a driver of the wrong length.

`OverflowError`  
For a negative seed or a seed of `2**64` or more.


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


#### apply_term()


A term's paths after reinsurer default.


Usage

``` python
apply_term(result, n_years, seed=0)
```


Each row is a path of `n_years` years, and a default is final: a reinsurer that defaults in year [t](distributions.Pareto.md#prospicio.distributions.Pareto.t) of a path is in default in every later year of it. The collateral is held once per reinsurer and path and is used up: in each year in default the collateral still held is set against that year's exposure, and what it covered is gone for the later years. Each path-year's factor comes from its driver ranked among all path-years (the gross loss, or a driver given path-major: year [t](distributions.Pareto.md#prospicio.distributions.Pareto.t) of path `j` at `j * n_years + t`, from 0). Path `j` draws from its own stream, its years in order, so a term of one year draws as [apply()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) does on that year. With a constant probability [p](models.Elpd.md#prospicio.models.Elpd.p) and independent default (correlation 0), a reinsurer is in default by year [t](distributions.Pareto.md#prospicio.distributions.Pareto.t) with probability `1 - (1 - p)**t`. With a correlation above 0 this holds only when the years' drivers are independent and identically distributed: the ranks are taken over all path-years together, so a driver that trends from year to year moves defaults between years.

The result has the input's components, copied bit for bit, then for each year in turn the components [apply()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) adds, with the year (from 1) as the last key.


##### Parameters


`result: PredictiveDistribution`  
A term's paths ([Tower.apply_term](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_term), [apply_aggregate_term](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_aggregate_term) or [apply_timeline](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_timeline)).

`n_years: int`  
The term's years; the result's years must be exactly `1` to `n_years`.

`seed: int = ``0`  
The default draws' seed.


##### Returns


`PredictiveDistribution`  


##### Raises


`ValueError`  
As [apply()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) does, and for a result that is no term's paths of `n_years` years, or a driver without one value per path-year.

`OverflowError`  
For a negative `n_years` or seed, or a seed of `2**64` or more.


##### Examples

``` python
>>> from prospicio.aggregate import EventSet
>>> from prospicio.reinsurance import Layer, Panel, Reinsurer, Tower
>>> # One path of two years, ceding 5 and then 10.
>>> years = [EventSet.from_years([[15.0]]), EventSet.from_years([[25.0]])]
>>> term = Tower([Layer("10x10", 10.0, 10.0)]).apply_term(years)
>>> # Re A certainly defaults, recovers nothing and has collateral of 8:
>>> # year 1 uses 5 of it, year 2 the 3 left.
>>> panel = Panel([Reinsurer("Re A", 1.0, 0.0, collateral=8.0)]).with_line("Re A", "10x10", 1.0)
>>> after = panel.apply_term(term, 2)
>>> [list(after.marginal(["credit_loss", "10x10", t]).draws) for t in (1, 2)]
```

\[\[0.0\], \[7.0\]\]

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


#### by_reinsurer()


Each reinsurer's credit loss, exposure and default in each year,


Usage

``` python
by_reinsurer(result, seed=0)
```


from the same draws as [apply()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) with the same [seed](aggregate.EventSet.md#prospicio.aggregate.EventSet.seed).


##### Parameters


`result: PredictiveDistribution`  
A tower's one-year result.

`seed: int = ``0`  


##### Returns


`PredictiveDistribution`  
Dimensions `["kind", "reinsurer"]`: `("credit_loss", r)` for every reinsurer [r](distributions.NegativeBinomial.md#prospicio.distributions.NegativeBinomial.r) in panel order, then `("exposure", r)`, its exposure after collateral `(E - C)^+`, then `("default", r)`, 1 in a year it defaults and 0 otherwise.


##### Raises


`ValueError`  
As [apply()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) does.

`OverflowError`  
For a negative seed or a seed of `2**64` or more.


##### Examples

``` python
>>> from prospicio.reinsurance import Layer, Panel, Reinsurer, Tower
>>> years = Tower([Layer("10x10", 10.0, 10.0)]).apply_annual([5.0, 15.0, 30.0])
>>> panel = Panel([Reinsurer("Re A", 1.0, 0.4, collateral=2.0)]).with_line("Re A", "10x10", 1.0)
>>> by = panel.by_reinsurer(years)
>>> list(by.marginal(["exposure", "Re A"]).draws)
```

\[0.0, 3.0, 8.0\]

``` python
>>> [round(x, 12) for x in by.marginal(["credit_loss", "Re A"]).draws]
```

\[0.0, 1.8, 4.8\]

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


#### by_reinsurer_term()


Each reinsurer's credit loss, exposure and default in each year of


Usage

``` python
by_reinsurer_term(result, n_years, seed=0)
```


a term's paths, from the same draws as [apply_term()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_term) with the same [seed](aggregate.EventSet.md#prospicio.aggregate.EventSet.seed).


##### Parameters


`result: PredictiveDistribution`  
A term's paths.

`n_years: int`  

`seed: int = ``0`  


##### Returns


`PredictiveDistribution`  
Dimensions `["kind", "reinsurer", "year"]`: the components of [by_reinsurer()](reinsurance.Panel.md#prospicio.reinsurance.Panel.by_reinsurer) for each year in turn, with the year (from

1.  as the last key. `("exposure", r, t)` is the exposure after the collateral still held at the start of year [t](distributions.Pareto.md#prospicio.distributions.Pareto.t), and `("default", r, t)` is 1 in every year from the one the reinsurer defaults in.


##### Raises


`ValueError`  
As [apply_term()](reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_term) does.

`OverflowError`  
For a negative `n_years` or seed, or a seed of `2**64` or more.


##### Examples

``` python
>>> from prospicio.aggregate import EventSet
>>> from prospicio.reinsurance import Layer, Panel, Reinsurer, Tower
>>> years = [EventSet.from_years([[15.0]]), EventSet.from_years([[25.0]])]
>>> term = Tower([Layer("10x10", 10.0, 10.0)]).apply_term(years)
>>> panel = Panel([Reinsurer("Re A", 1.0, 0.0, collateral=8.0)]).with_line("Re A", "10x10", 1.0)
>>> by = panel.by_reinsurer_term(term, 2)
>>> [list(by.marginal(["exposure", "Re A", t]).draws) for t in (1, 2)]
```

\[\[0.0\], \[7.0\]\]

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


#### with_driver()


The panel ranking the years by `by_year` instead of the gross


Usage

``` python
with_driver(by_year)
```


loss (an industry loss, say).


##### Parameters


`by_year: list of float`  
One finite value per simulated year, in the order of the tower's result (over a term, one per path-year, path-major); its length is checked when the panel is applied.


##### Returns


`Panel`  


##### Raises


`ValueError`  
For no values or a value that is not finite.


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


#### with_line()


The panel with reinsurer `reinsurer` writing `line` of layer


Usage

``` python
with_line(reinsurer, layer, line)
```


[layer](distributions.Burr.md#prospicio.distributions.Burr.layer)'s ceded loss.

Whether [layer](distributions.Burr.md#prospicio.distributions.Burr.layer) is in the tower, and whether its lines sum to 1, is checked when the panel is applied, since a panel is built before it meets a tower.


##### Parameters


`reinsurer: str`  
A reinsurer on the panel.

`layer: str`  
A layer's name.

`line: float`  
In `(0, 1]`.


##### Returns


`Panel`  


##### Raises


`ValueError`  
For a reinsurer not on the panel, an empty layer name, a line out of range or a line given twice.
