## aggregate.Ledger


A P&L ledger, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `PnL`: a source (a [Grid](distributions.Grid.md#prospicio.distributions.Grid), or


Usage


``` python
aggregate.Ledger()
```


values and their probabilities) and its groups, with every row (each leg, each side's total, each group's result, running nets, tier and net-of blocks, and with several groups the grand rows and the total impact) a sum of signed legs at each atom, and its exact distribution.

The scenario columns `k01` to `k99` ([aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `κ`) are each row's conditional mean given that the grand result equals its quantile at that level, so each column is one state of the world and foots down the sheet. Rows are in the payoff convention: `k01` is the bad year. The source's probabilities are rescaled to sum to 1.


## Parameters


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

`groups: list of Group`  

`name: str = ``"ledger"`  

`result_name: str = ``"result"`  

`spans: list of tuple of (str, int, int)`  
`(label, lo, hi)`: groups `lo` to `hi - 1` with their own subtotal block, and a net-of block when a later group follows.

`force_tower: bool = ``False`  
Present one group as a tower, with a step level.


## Examples

``` python
>>> from prospicio.aggregate import Group, Ledger, Leg
>>> book = Group("Book", "sell", [Leg("Premium", 10.0)], [Leg("Loss", lambda x: x)])
>>> pnl = Ledger(([2.0, 8.0], [0.5, 0.5]), [book], name="Book")
>>> pnl.result.mean()
```

5.0

``` python
>>> s = pnl.sheet()
>>> s["label"], s["k01"]
```

(\['Premium', 'Loss', 'Total'\], \[10.0, -8.0, 2.0\])


## Attributes

| Name | Description |
|----|----|
| [is_stitched](#is_stitched) | Whether every row is its own marginal ([Book.occurrence_peel()](aggregate.Book.md#prospicio.aggregate.Book.occurrence_peel)): |
| [name](#name) | The ledger's name. |
| [prob_eq_0](#prob_eq_0) | The chance that the result is 0. |
| [result](#result) | The (grand) result's distribution. |
| [rows](#rows) | The rows' labels, in sheet order. |

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


#### is_stitched


Whether every row is its own marginal ([Book.occurrence_peel()](aggregate.Book.md#prospicio.aggregate.Book.occurrence_peel)):


`is_stitched: bool`


the sheet then has no scenario columns.


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


#### name


The ledger's name.


`name: str`


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


#### prob_eq_0


The chance that the result is 0.


`prob_eq_0: float`


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


#### result


The (grand) result's distribution.


`result: Discrete`


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


#### rows


The rows' labels, in sheet order.


`rows: list[str]`


## Methods

| Name | Description |
|----|----|
| [card()](#card) | The card, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `summary_df`: each block's consideration, |
| [legs()](#legs) | The declared legs, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `legs_df`: step, side, label, |
| [marginal()](#marginal) | Each row's own quantiles, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `economic_marginal_df`: |
| [ratios()](#ratios) | The ratio exhibit, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `economic_ratios_df`: for each |
| [row()](#row) | The distribution of the row labelled [label](aggregate.Leg.md#prospicio.aggregate.Leg.label). |
| [sheet()](#sheet) | The sheet, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `economic_df`: every row with its mean, |
| [validation()](#validation) | Each rebucketed leg's exact mean against its grid's, |

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


#### card()


The card, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `summary_df`: each block's consideration,


Usage


``` python
card()
```


obligation and margin (and on a tower each step's running net and the covers' total impact), with `EX`, `SD`, `CV`, `Skew`, `P01`, `Median` and `P99` of each row's own distribution.


##### Returns


`dict`  


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


#### legs()


The declared legs, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `legs_df`: step, side, label,


Usage


``` python
legs()
```


kind, `EX` and `SD`.


##### Returns


`dict`  


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


#### marginal()


Each row's own quantiles, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `economic_marginal_df`:


Usage


``` python
marginal()
```


`P01` to `P99`, which do not add down the sheet.


##### Returns


`dict`  


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


#### ratios()


The ratio exhibit, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `economic_ratios_df`: for each


Usage


``` python
ratios()
```


group, span, net-of block and `All`, premium `P`, loss `L` net of recoveries, expense `E` net of commission and the result [M](distributions.TemperedStable.md#prospicio.distributions.TemperedStable.M) (mean amounts, signed for the block's own view), the result's `SD`, the ratios of means `LR`, `ER`, `CR`, the means of ratios `E_LR`, `E_ER`, `E_CR` (where the premium never vanishes), and `P_share` and `M_share` of the first block. Legs without a kind count as premium on the consideration side and loss on the other.


##### Returns


`dict`  


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


#### row()


The distribution of the row labelled [label](aggregate.Leg.md#prospicio.aggregate.Leg.label).


Usage


``` python
row(label)
```


##### Parameters


`label: str`  


##### Returns


`Discrete`  


##### Raises


`ValueError`  
No such row, or a stitched peel's `Impact` row, a difference of statistics with no distribution of its own.


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


#### sheet()


The sheet, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `economic_df`: every row with its mean,


Usage


``` python
sheet()
```


standard deviation, coefficient of variation, skewness and scenario columns `k01` to `k99`.


##### Returns


`dict`  
Columns [step](esg.Scenarios.md#prospicio.esg.Scenarios.step) (on a tower), `side`, [label](aggregate.Leg.md#prospicio.aggregate.Leg.label), [row](aggregate.Ledger.md#prospicio.aggregate.Ledger.row) (the row's key), `EX`, `SD`, `CV`, `Skew` and the scenarios (none on a stitched peel, [Book.occurrence_peel()](aggregate.Book.md#prospicio.aggregate.Book.occurrence_peel)).


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


#### validation()


Each rebucketed leg's exact mean against its grid's,


Usage


``` python
validation()
```


[aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `validation_df`. Empty when no leg has a [step](esg.Scenarios.md#prospicio.esg.Scenarios.step).


##### Returns


`dict`  
Columns [label](aggregate.Leg.md#prospicio.aggregate.Leg.label), `EX`, `Est`, `abs_err` and `rel_err`.
