## aggregate.Book


A seller's book, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `pnl` and `xpnl` builders: a gross


Usage


``` python
aggregate.Book()
```


premium, expenses and the labels of its legs, laid out over a source of annual gross losses with the annual covers of a tower.

[ledger()](aggregate.Book.md#prospicio.aggregate.Book.ledger) gives one of three faces:

- `consolidated` (`pnl`): one group, the net position. With a tower it books net premium (gross less ceded premiums) less the net loss less the commission received less expenses, over the net loss; a loss-basis expense books as its rate times each year's gross loss (or the expected one, with `expense_at_expected_loss`).
- `walk` (`xpnl`): the gross book, then one buy group per stage of the tower, with the running net and the covers' total impact.
- `peel-top-down` and `peel-bottom-up` (`xpnl ... peel`): one buy group per layer, with an `All aggregate` subtotal.

Every layer's terms are taken at the annual total. The builders book a fixed premium and a flat ceding commission; a layer with loss-sensitive terms is refused (write its legs with [Leg](aggregate.Leg.md#prospicio.aggregate.Leg)).


## Parameters


`name: str`  
The ledger's name.

`premium: float`  
The gross premium.

`expenses: list of Expense`  

`premium_label: str`  
`Premium` by default.

`loss_label: str`  
`Loss` by default; also the gross book's margin on a walk.

`step_label: str`  
The gross book's step on a walk, `Gross` by default.

`retro: prospicio.reinsurance.LossSensitivePremium`  
Rate the book retrospectively ([aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `retro <collar> premium`): the premium is these terms at the year's gross loss, and [premium](pricing.Price.md#prospicio.pricing.Price.premium) (the collar's basic premium in [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)) is what premium-basis expenses are taken on. A retro book buys no cover here.

`expense_at_expected_loss: bool = ``False`  
Book a loss-basis expense on the consolidated face at the expected gross loss, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s guaranteed-cost builder does, rather than at each year's gross loss (which makes the consolidated margin the walk's net margin year by year).


## Examples

``` python
>>> from prospicio.aggregate import Book, Expense
>>> from prospicio.reinsurance import Layer, Tower
>>> gross = ([2, 3, 4, 5, 6, 8], [0.25, 0.3, 0.09, 0.2, 0.12, 0.04])
>>> cover = Layer.stop_loss("agg 3 xs 5", 3.0, 5.0).with_deposit_premium(1.0)
>>> cover = cover.with_ceding_commission(0.1)
>>> book = Book("Ex3", 10.0, [Expense("premium", 0.1)])
>>> walk = book.ledger(gross, Tower([cover]), "walk")
>>> round(walk.result.mean(), 12), walk.sheet()["step"][-1]
```

(4.54, 'All')


## Attributes

| Name | Description |
|----|----|
| [premium](#premium) | The gross premium. |

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


#### premium


The gross premium.


`premium: float`


## Methods

| Name | Description |
|----|----|
| [ledger()](#ledger) | The ledger over the annual gross losses `source`. |
| [occurrence_ledger()](#occurrence_ledger) | The ledger with occurrence covers over the joint source `joint` |
| [occurrence_peel()](#occurrence_peel) | Several occurrence layers peeled one by one, and the aggregate |

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


#### ledger()


The ledger over the annual gross losses `source`.


Usage


``` python
ledger(source, tower=None, face="consolidated")
```


##### Parameters


`source: Grid or tuple of (list of float, list of float)`  

`tower: prospicio.reinsurance.Tower = None`  
Annual covers; without one, the plain book.

`face: str = ``"consolidated"`  
`consolidated`, `walk`, `peel-top-down` or `peel-bottom-up`.


##### Returns


`Ledger`  


##### Raises


`ValueError`  
A peel without a tower, a layer that needs each event, or one with loss-sensitive terms.


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


#### occurrence_ledger()


The ledger with occurrence covers over the joint source `joint`


Usage


``` python
occurrence_ledger(joint, occurrence, aggregate=None, face="consolidated")
```


of the annual gross loss and the loss the `occurrence` tower cedes ([occurrence_source()](aggregate.occurrence_source.md#prospicio.aggregate.occurrence_source)), then the aggregate covers of [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate) on the net of the occurrence covers, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `xpnl` and `pnl` over its `occ_bivariate`.

The occurrence covers are one group on the walk, named after the first layer; a peel needs exactly one occurrence layer. The consolidated face is over the net loss at each atom. A single occurrence layer may carry annual terms and paid reinstatements on the joint's unlimited annual cession `R`: its recovery `A(R)` and premium `D + h(R)` then vary with the year.


##### Parameters


`joint: tuple of (list of float, list of float, list of float)`  
`(gross, ceded, probs)`.

`occurrence: prospicio.reinsurance.Tower`  
Per-occurrence covers; annual terms and reinstatements on a single layer only.

`aggregate: prospicio.reinsurance.Tower = None`  

`face: str = ``"consolidated"`  


##### Returns


`Ledger`  


##### Raises


`ValueError`  
As [ledger()](aggregate.Book.md#prospicio.aggregate.Book.ledger), annual terms on an occurrence tier of several layers, or a peel through several occurrence layers.


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


#### occurrence_peel()


Several occurrence layers peeled one by one, and the aggregate


Usage


``` python
occurrence_peel(
    frequency,
    severity,
    occurrence,
    aggregate=None,
    face="peel-top-down",
    points=1024
)
```


covers of [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate) behind them, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s stitched peel. The joint source carries only the occurrence tier's total cession, so every row is its own exact marginal: each occurrence layer's recovery, running net and the tier's total the compound of a per-claim map of [severity](aggregate.Clash.md#prospicio.aggregate.Clash.severity) under [frequency](pricing.TowerModel.md#prospicio.pricing.TowerModel.frequency) (by FFT on twice [points](aggregate.GridSize.md#prospicio.aggregate.GridSize.points)), each aggregate layer's a pushforward of the net-of-occurrence aggregate. The mean column foots; the other statistics are each row's own, with no scenario columns; `Impact` is the difference of the grand and gross results' statistics; a loss-basis expense is booked at the expected gross loss.


##### Parameters


`frequency: Poisson, NegativeBinomial, Binomial or a count`  

`severity: Grid`  

`occurrence: prospicio.reinsurance.Tower`  
Occurrence layers with fixed terms.

`aggregate: prospicio.reinsurance.Tower = None`  

`face: str = ``"peel-top-down"`  
`peel-top-down` or `peel-bottom-up`.

`points: int = ``1024`  


##### Returns


`Ledger`  
A stitched ledger ([is_stitched](aggregate.Ledger.md#prospicio.aggregate.Ledger.is_stitched)).


##### Raises


`ValueError`  
A face that is not a peel, a retro book, occurrence layers with annual terms, reinstatements or loss-sensitive terms, aggregate layers with loss-sensitive terms, or a severity grid longer than [points](aggregate.GridSize.md#prospicio.aggregate.GridSize.points).
