# Choosing a method: which prospicio tool for which job


# Use this guide when

You price primary insurance (rating plans, GLMs, loss ratio indications) and now do reinsurance work. This guide is the map of the guide set. For each situation it gives the usual data, the method and why, the calls, the pitfalls and the guide with more detail. It does not teach the methods.

Money is in millions of a synthetic currency. The numbers show how to read the output, not what a market pays. Each code block runs alone, except where it says that it uses an earlier block. A layer is limit xs attachment: "4 xs 6" pays the part of a loss between 6 and 10. Calls take the limit first: `Layer("4x6", 4.0, 6.0)`, `expected_layer_loss(4.0, 6.0)`.


# The decision table

| Situation | Method | prospicio entry point | Why | Guide |
|----|----|----|----|----|
| Primary rates, overall rate indication | Loss ratio or pure premium method, with on-level premium, trend, development and credibility. Class relativities from a GLM before that | [RateHistory](../reference/pricing.RateHistory.md#prospicio.pricing.RateHistory), [LossRatioExperience](../reference/pricing.LossRatioExperience.md#prospicio.pricing.LossRatioExperience), [PurePremiumExperience](../reference/pricing.PurePremiumExperience.md#prospicio.pricing.PurePremiumExperience), [Provisions](../reference/pricing.Provisions.md#prospicio.pricing.Provisions), [LimitedFluctuation](../reference/credibility.LimitedFluctuation.md#prospicio.credibility.LimitedFluctuation). [prospicio.models.Glm](../reference/models.Glm.md#prospicio.models.Glm) for relativities | Standard ratemaking. Premium and losses go to the same rate level and cost level | [Experience and exposure rating](experience-and-exposure-rating.md) |
| Per-risk property excess of loss, you have sums insured | Exposure rating with a curve | [RiskProfile.expected_layer_loss](../reference/pricing.RiskProfile.md#prospicio.pricing.RiskProfile.expected_layer_loss), [Mbbefd](../reference/pricing.Mbbefd.md#prospicio.pricing.Mbbefd) | There are too few large losses to rate a layer, and you know the profile of limits | [Experience and exposure rating](experience-and-exposure-rating.md) |
| Per-risk property or casualty excess of loss, you have large losses | Experience rating: prepare the losses, then fit a severity above a threshold and apply it to the layer, or burn the layer | [LargeLossExperience](../reference/pricing.LargeLossExperience.md#prospicio.pricing.LargeLossExperience), `.prepare`, [PreparedLosses.burning_cost](../reference/pricing.PreparedLosses.md#prospicio.pricing.PreparedLosses.burning_cost). [Pareto.fit](../reference/distributions.Pareto.md#prospicio.distributions.Pareto.fit), [CollectiveModel.layer_mean](../reference/pricing.CollectiveModel.md#prospicio.pricing.CollectiveModel.layer_mean) | The history of the cedant is the best evidence of its tail, when the history is sufficient. First trend the losses to the treaty period and develop them to ultimate | [Experience and exposure rating](experience-and-exposure-rating.md), [Severity and frequency](severity-and-frequency.md) |
| Casualty excess of loss, you have a profile of policy limits and premium | Exposure rating with increased limit factors: the premium of each limit times an expected loss ratio, split into the layer by ILFs | [ilf](../reference/pricing.ilf.md#prospicio.pricing.ilf) in a loop over the limits | There are too few excess losses, and you know the limits written | This guide, section 3 |
| Casualty excess of loss, you have a price for one layer and need it for another | Increased limit factors and Pareto extrapolation, or match a tower | [ilf](../reference/pricing.ilf.md#prospicio.pricing.ilf), [pareto_extrapolation](../reference/pricing.pareto_extrapolation.md#prospicio.pricing.pareto_extrapolation), [match_tower](../reference/pricing.match_tower.md#prospicio.pricing.match_tower) | The layers that you can see give the price of the layers above the data | [Experience and exposure rating](experience-and-exposure-rating.md) |
| Catastrophe excess of loss | Use the output of the cat model: an event loss table, a year loss table, or return period points | [EventLossTable](../reference/aggregate.EventLossTable.md#prospicio.aggregate.EventLossTable) (events with secondary uncertainty), [EventSet.from_years](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.from_years), [EventSet.from_long](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.from_long), [EventSet.grouped](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.grouped), [fit_pml_curve](../reference/pricing.fit_pml_curve.md#prospicio.pricing.fit_pml_curve), [Tower.apply](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) | The model gives frequency and severity. You apply the terms and price the risk | [What a reinsurance price is](reinsurance-price.md) |
| Quota share, surplus | Technical commission from the loss ratio distribution, with its centre at the indicated loss ratio of the cedant (first row) | [Layer.quota_share](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.quota_share), [Layer.surplus](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.surplus), [with_sliding_scale](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_sliding_scale), [Tower.on_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_grid). [Tower.on_annual_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_annual_grid) on a loss-ratio grid. `price(grid, Distortion.tvar(0.99), cost_of_capital=r)` for the margin | The price is the commission. The full loss ratio is at risk, not only large losses | [What a reinsurance price is](reinsurance-price.md) |
| Aggregate stop loss, adverse development or loss portfolio cover | Distribution of the aggregate, then the cover on it. For reserves, a reserve bootstrap | [Layer.stop_loss](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.stop_loss), [Tower.on_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_grid). [OdpBootstrap](../reference/reserving.OdpBootstrap.md#prospicio.reserving.OdpBootstrap) or [MackBootstrap](../reference/reserving.MackBootstrap.md#prospicio.reserving.MackBootstrap), then [Tower.apply_aggregate](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply_aggregate) | The cover pays on the total of the year, so you need the distribution of the total, not one loss | [Aggregate distributions](aggregate-distributions.md) |
| Reserve and its uncertainty, lifetime or one year | Chain ladder, Mack, Bornhuetter-Ferguson. Bootstraps for a distribution | [Triangle](../reference/reserving.Triangle.md#prospicio.reserving.Triangle), [ChainLadder](../reference/reserving.ChainLadder.md#prospicio.reserving.ChainLadder), [Mack](../reference/reserving.Mack.md#prospicio.reserving.Mack), [OdpBootstrap](../reference/reserving.OdpBootstrap.md#prospicio.reserving.OdpBootstrap), [MackBootstrap](../reference/reserving.MackBootstrap.md#prospicio.reserving.MackBootstrap) | Triangles show development. Bootstraps give a distribution that you can combine | [Reserving methods](reserving-methods.md) |
| Capital, risk measures, allocation | Distortion risk measures. Euler allocation | [Distortion](../reference/risk.Distortion.md#prospicio.risk.Distortion), [capital](../reference/risk.capital.md#prospicio.risk.capital), [allocate](../reference/risk.allocate.md#prospicio.risk.allocate) | One coherent family prices and allocates | [Risk loads and distortions](risk-loads-and-distortions.md) |
| A contract in an existing portfolio | Price on the portfolio, allocate by co-measure | [Portfolio.from_independent](../reference/pricing.Portfolio.md#prospicio.pricing.Portfolio.from_independent), [price_portfolio](../reference/pricing.price_portfolio.md#prospicio.pricing.price_portfolio) | Diversification changes what a contract needs | [Risk loads and distortions](risk-loads-and-distortions.md) |

Terms in the table:

- The **cedant** is the insurer that buys the reinsurance.
- An **on-level** premium is past premium at the current rates.
- **ILF** is an increased limit factor (section 3).
- **OEP** is the occurrence exceedance curve of a catastrophe model (section 4).

Two questions select the row:

1.  What do you know about the cedant? A loss history points to experience rating. A list of sums insured points to exposure rating. The output of a catastrophe model points to the use of that output.
2.  On what does the cover pay? One loss (an excess of loss layer), the total of the year (stop loss), a share of all losses (quota share) or an event (catastrophe). The answer selects how you represent losses.


# Three ways to represent losses

Almost all methods below need a model of the losses of the year. Where the three ways overlap, they agree within grid and Monte Carlo error.

| Way | You give | You get | Use when |
|----|----|----|----|
| Grid (exact) | a claim count and a severity | the annual loss as a distribution on a grid of steps, with no simulation error | the cover depends only on amounts: excess of loss, quota share, stop loss, aggregate limits, reinstatements pro rata as to amount |
| Simulation | a claim count and a severity, a risk profile or a year loss table | simulated years of events, with Monte Carlo error | the cover needs event times (reinstatements pro rata as to time) or sums insured (surplus), or you want to join with other sources |
| Formula | a severity and a layer | expected loss, variance | a quick look at one layer under a Pareto or other severity, with no annual terms, reinstatements or commissions |

A compound distribution has no event times, so the grid refuses reinstatements pro rata as to time:


``` python
from prospicio.distributions import Grid, Pareto, Poisson
from prospicio.reinsurance import Layer, Tower

severity, _ = Grid.rounding(Pareto(1.0, 1.8), 0.1, 201)
timed = Layer("5x5", 5.0, 5.0, premium=1.0, reinstatement_rates=[1.0], pro_rata_time=True)
try:
    Tower([timed]).on_grid(Poisson(4.0), severity, 2**12)
except ValueError as e:
    print("refused:", str(e).split(";")[0])
annual_cap = Layer("5x5", 5.0, 5.0, aggregate_limit=10.0)
print("net grid with an annual limit:", Tower([annual_cap]).on_grid(Poisson(4.0), severity, 2**12).net)
```


    refused: invalid data: layer "5x5" has reinstatements pro rata as to time
    net grid with an annual limit: None


Pitfall: a layer with annual terms (an aggregate limit or reinstatements) has no [net](../reference/reinsurance.TowerGrids.md#prospicio.reinsurance.TowerGrids.net) grid. [net](../reference/reinsurance.TowerGrids.md#prospicio.reinsurance.TowerGrids.net) exists when no layer has annual terms, or when the last stage is one aggregate cover such as a stop loss. Otherwise make the net yourself or use simulation ([simulate_events](../reference/aggregate.simulate_events.md#prospicio.aggregate.simulate_events), [RiskProfile.simulate](../reference/pricing.RiskProfile.md#prospicio.pricing.RiskProfile.simulate), [Tower.apply](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply)).


# 1. Primary ratemaking and the overall rate indication

**What it is.** The indicated rate change that makes premium equal to expected losses and expenses. The **loss ratio method** compares the projected loss ratio with the permissible loss ratio. The **pure premium method** calculates a rate from the losses per exposure unit. Both need:

- premium at the **current rate level** (the **on-level factor**, by the parallelogram method)
- losses **developed** to ultimate and **trended** to the policy period
- a **credibility** weight against a complement

**Data you usually have.** Written and earned premium by year, a history of rate changes, losses with development factors, trend selections, and expense and profit provisions.

**When to use it.** For the average rate level of a book that has a rating plan. Not for one treaty, which has no rate history to put on-level.

**The calls.**


``` python
from prospicio.credibility import LimitedFluctuation
from prospicio.pricing import LossRatioExperience, Period, Provisions, RateHistory, credibility_weighted

history = RateHistory([2022.5, 2023.5], [0.05, 0.03])   # +5% from mid 2022, +3% from mid 2023
years = [2021.0, 2022.0, 2023.0]
on_level = [history.rate_level(Period.calendar(y, y + 1.0), term=1.0).on_level_factor for y in years]
experience = LossRatioExperience(
    earned_premium=[100.0, 110.0, 120.0],
    losses=[62.0, 70.0, 66.0],
    on_level_factor=on_level,
    development=[1.00, 1.02, 1.10],
    loss_trend=[1.08, 1.05, 1.025],
    lae_factor=1.08,     # 1 plus the loss adjustment expense not already in the losses
)
provisions = Provisions(variable=0.25, profit=0.05)
indicated = provisions.loss_ratio_change(experience.loss_ratio)
lf = LimitedFluctuation(0.90, 0.05)
z = lf.credibility(900, lf.frequency_standard())    # 900 expected claims
selected = credibility_weighted(indicated, z, 0.02)  # complement: +2%
print("on-level factors", [round(f, 4) for f in on_level])
print(f"projected loss ratio {experience.loss_ratio:.1%}, permissible {provisions.permissible_loss_ratio():.1%}")
print(f"indicated change {indicated:+.1%}; credibility {z:.2f}; selected {selected:+.1%}")
```


    on-level factors [1.0815, 1.0748, 1.0323]
    projected loss ratio 66.7%, permissible 70.0%
    indicated change -4.7%; credibility 0.91; selected -4.1%


The 2021 year must catch up on the full 8.15% of cumulative rate increase, and 2023 only on a small part, so the factors decrease for recent years. Credibility moves the indication toward the complement.

**Pitfalls.**

- `experience.loss_ratio`, `provisions.variable` and [RateLevel.on_level_factor](../reference/pricing.RateLevel.md#prospicio.pricing.RateLevel.on_level_factor) are properties: no parentheses.
- Dates are year fractions (`2022.5` is mid 2022). [year_fraction](../reference/pricing.year_fraction.md#prospicio.pricing.year_fraction) converts a calendar date.
- The calculation assumes uniform writing and earning. For a policy term other than a year, or a risks-attaching treaty, use [Period.policy](../reference/pricing.Period.md#prospicio.pricing.Period.policy), not [Period.calendar](../reference/pricing.Period.md#prospicio.pricing.Period.calendar).
- These classes are for primary ratemaking, with no layer or treaty year. For individual large losses use `LargeLossExperience(ids, accident, amount, threshold=, valuation=, fx=)` and its `.prepare(rate=, to=, development=)` (section 2).

**More detail.** [Experience and exposure rating](experience-and-exposure-rating.md) (pure premium method, credibility), `docs/design/ratemaking.md` (definitions).


# 2. Per-risk property excess of loss

A **per-risk** cover pays on each loss to one risk (a building, a plant), above an attachment and up to a limit. Use two methods together:

- **Exposure rating** prices the layer from the **risk profile** of the cedant (the sum insured in each band). An exposure curve gives the share of the expected loss of a risk below a given fraction of its maximum possible loss (MPL). [RiskProfile](../reference/pricing.RiskProfile.md#prospicio.pricing.RiskProfile) takes the MPL as the sum insured. It needs no loss history.
- **Experience rating** fits the large losses of the cedant and applies the fitted severity to the layer. It shows what occurred, but a high layer may have had only two losses in five years.

**Data you usually have.** A table of bands (sum insured, number of risks, premium) and a list of large losses with dates, possibly with development.

**Which to use.**

| You have | Use | Because |
|----|----|----|
| Profile and no history, or a new account | Exposure | There is nothing else |
| Profile and a thin history | Exposure, checked against experience | Experience on a high layer is mostly noise |
| Long, clean history on a low layer | Experience, with exposure as a check | The history is the cedant's own, and there is sufficient layer data |
| Both, and they do not agree | Blend with credibility, and find why they do not agree | A large difference shows that the curve, the profile or the loss data is wrong |

The example rates the layer 4 xs 6 (the part of each loss between 6 and 10).


``` python
import pandas as pd
from great_tables import GT

from prospicio.distributions import Pareto, Poisson
from prospicio.pricing import CollectiveModel, Mbbefd, RiskProfile
from prospicio.reinsurance import Layer


def profile(c):
    return RiskProfile([1.0, 3.0, 6.0, 12.0], [400, 150, 60, 20], Mbbefd.swiss_re(c),
                       premiums=[8.0, 6.0, 5.0, 4.0], loss_ratio=0.55)


exposure = {c: profile(c).expected_layer_loss(4.0, 6.0) for c in (2.0, 3.0, 4.0)}
exposure_el = exposure[3.0]

large = [1.2, 1.5, 1.1, 2.4, 1.8, 1.3, 3.9, 1.6, 1.05, 2.2, 5.5, 1.4, 1.9, 1.15, 7.8, 1.25, 2.9, 1.7, 1.35, 4.4]
YEARS = 5
fit = Pareto.fit(large, 1.0)                                   # losses above 1, alpha by maximum likelihood
experience_el = CollectiveModel(Poisson(len(large) / YEARS), fit).layer_mean(4.0, 6.0)
burning = Layer("4x6", 4.0, 6.0).ceded(large) / YEARS         # what the layer would have paid
print(f"fitted alpha {fit.alpha:.2f}")

sources = pd.DataFrame({
    "source": ["exposure, Swiss Re c=2", "exposure, Swiss Re c=3", "exposure, Swiss Re c=4",
               "burning cost, 5 years", "fitted Pareto"],
    "loss": [exposure[2.0], exposure[3.0], exposure[4.0], burning, experience_el],
})
(GT(sources, rowname_col="source")
 .tab_header("Expected loss a year of the layer 4 xs 6", "Exposure rating at three curves, then experience rating")
 .cols_label(loss="expected loss")
 .fmt_number("loss", decimals=3))
```


    fitted alpha 1.48


<style>
#qatdzvzhhk table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#qatdzvzhhk thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#qatdzvzhhk p { margin: 0; padding: 0; }
 #qatdzvzhhk .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #qatdzvzhhk .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #qatdzvzhhk .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #qatdzvzhhk .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #qatdzvzhhk .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #qatdzvzhhk .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qatdzvzhhk .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #qatdzvzhhk .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #qatdzvzhhk .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #qatdzvzhhk .gt_column_spanner_outer:first-child { padding-left: 0; }
 #qatdzvzhhk .gt_column_spanner_outer:last-child { padding-right: 0; }
 #qatdzvzhhk .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #qatdzvzhhk .gt_spanner_row { border-bottom-style: hidden; }
 #qatdzvzhhk .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #qatdzvzhhk .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #qatdzvzhhk .gt_from_md> :first-child { margin-top: 0; }
 #qatdzvzhhk .gt_from_md> :last-child { margin-bottom: 0; }
 #qatdzvzhhk .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #qatdzvzhhk .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #qatdzvzhhk .gt_indent_1 { text-indent: 5px; }
 #qatdzvzhhk .gt_indent_2 { text-indent: calc(5px * 2); }
 #qatdzvzhhk .gt_indent_3 { text-indent: calc(5px * 3); }
 #qatdzvzhhk .gt_indent_4 { text-indent: calc(5px * 4); }
 #qatdzvzhhk .gt_indent_5 { text-indent: calc(5px * 5); }
 #qatdzvzhhk .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #qatdzvzhhk .gt_row_group_first td { border-top-width: 2px; }
 #qatdzvzhhk .gt_row_group_first th { border-top-width: 2px; }
 #qatdzvzhhk .gt_striped { color: #333333; background-color: #F4F4F4; }
 #qatdzvzhhk .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qatdzvzhhk .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #qatdzvzhhk .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #qatdzvzhhk .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qatdzvzhhk .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #qatdzvzhhk .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #qatdzvzhhk .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #qatdzvzhhk .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qatdzvzhhk .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #qatdzvzhhk .gt_left { text-align: left; }
 #qatdzvzhhk .gt_center { text-align: center; }
 #qatdzvzhhk .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #qatdzvzhhk .gt_font_normal { font-weight: normal; }
 #qatdzvzhhk .gt_font_bold { font-weight: bold; }
 #qatdzvzhhk .gt_font_italic { font-style: italic; }
 #qatdzvzhhk .gt_super { font-size: 65%; }
 #qatdzvzhhk .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qatdzvzhhk .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #qatdzvzhhk .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qatdzvzhhk .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #qatdzvzhhk .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #qatdzvzhhk .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="2" id="title" class="gt_heading gt_title gt_font_normal">Expected loss a year of the layer 4 xs 6</th>
</tr>
<tr class="gt_heading">
<th colspan="2" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Exposure rating at three curves, then experience rating</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="loss" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">expected loss</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">exposure, Swiss Re c=2</th>
<td class="gt_row gt_right" headers="stub-1 loss">0.482</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">exposure, Swiss Re c=3</th>
<td class="gt_row gt_right" headers="stub-2 loss">0.347</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">exposure, Swiss Re c=4</th>
<td class="gt_row gt_right" headers="stub-3 loss">0.224</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">burning cost, 5 years</th>
<td class="gt_row gt_right" headers="stub-4 loss">0.360</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">fitted Pareto</th>
<td class="gt_row gt_right" headers="stub-5 loss">0.774</td>
</tr>
</tbody>
</table>


The curve alone moves the expected loss by more than a factor of two, so test it. The fitted Pareto is more than twice the exposure rating. The burning cost is near it: the layer paid on one loss above 6 in five years. A layer with this shape needs many more than 20 claims for full credibility. The next block (it uses the one above) weighs the two:


``` python
from prospicio.credibility import LimitedFluctuation

severity_cv = fit.layer_variance(4.0, 6.0) ** 0.5 / fit.layer(4.0, 6.0)    # spread of the payment per large loss
rows = []
for p, k in ((0.90, 0.10), (0.90, 0.05)):                      # two full-credibility standards
    lf = LimitedFluctuation(p, k)
    z = lf.credibility(len(large), lf.pure_premium_standard(severity_cv))
    rows.append((f"({p:.2f}, {k:.2f})", z, z * experience_el + (1 - z) * exposure_el))
standards = pd.DataFrame(rows, columns=["standard", "z", "blend"])
(GT(standards, rowname_col="standard")
 .tab_header("Experience weighted against exposure", "Limited fluctuation standards (probability, tolerance)")
 .cols_label(z="credibility", blend="blended loss")
 .fmt_number("z", decimals=2)
 .fmt_number("blend", decimals=3))
```


<style>
#duzragrwgl table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#duzragrwgl thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#duzragrwgl p { margin: 0; padding: 0; }
 #duzragrwgl .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #duzragrwgl .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #duzragrwgl .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #duzragrwgl .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #duzragrwgl .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #duzragrwgl .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #duzragrwgl .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #duzragrwgl .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #duzragrwgl .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #duzragrwgl .gt_column_spanner_outer:first-child { padding-left: 0; }
 #duzragrwgl .gt_column_spanner_outer:last-child { padding-right: 0; }
 #duzragrwgl .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #duzragrwgl .gt_spanner_row { border-bottom-style: hidden; }
 #duzragrwgl .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #duzragrwgl .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #duzragrwgl .gt_from_md> :first-child { margin-top: 0; }
 #duzragrwgl .gt_from_md> :last-child { margin-bottom: 0; }
 #duzragrwgl .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #duzragrwgl .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #duzragrwgl .gt_indent_1 { text-indent: 5px; }
 #duzragrwgl .gt_indent_2 { text-indent: calc(5px * 2); }
 #duzragrwgl .gt_indent_3 { text-indent: calc(5px * 3); }
 #duzragrwgl .gt_indent_4 { text-indent: calc(5px * 4); }
 #duzragrwgl .gt_indent_5 { text-indent: calc(5px * 5); }
 #duzragrwgl .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #duzragrwgl .gt_row_group_first td { border-top-width: 2px; }
 #duzragrwgl .gt_row_group_first th { border-top-width: 2px; }
 #duzragrwgl .gt_striped { color: #333333; background-color: #F4F4F4; }
 #duzragrwgl .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #duzragrwgl .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #duzragrwgl .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #duzragrwgl .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #duzragrwgl .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #duzragrwgl .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #duzragrwgl .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #duzragrwgl .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #duzragrwgl .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #duzragrwgl .gt_left { text-align: left; }
 #duzragrwgl .gt_center { text-align: center; }
 #duzragrwgl .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #duzragrwgl .gt_font_normal { font-weight: normal; }
 #duzragrwgl .gt_font_bold { font-weight: bold; }
 #duzragrwgl .gt_font_italic { font-style: italic; }
 #duzragrwgl .gt_super { font-size: 65%; }
 #duzragrwgl .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #duzragrwgl .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #duzragrwgl .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #duzragrwgl .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #duzragrwgl .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #duzragrwgl .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Experience weighted against exposure</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Limited fluctuation standards (probability, tolerance)</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="z" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">credibility</th>
<th id="blend" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">blended loss</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">(0.90, 0.10)</th>
<td class="gt_row gt_right" headers="stub-1 z">0.06</td>
<td class="gt_row gt_right" headers="stub-1 blend">0.374</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">(0.90, 0.05)</th>
<td class="gt_row gt_right" headers="stub-2 z">0.03</td>
<td class="gt_row gt_right" headers="stub-2 blend">0.361</td>
</tr>
</tbody>
</table>


A stricter standard (0.05 instead of 0.10) halves the weight. A Bühlmann-type weight is also common. The blend is an illustration, not a rule.

**Pitfalls.**

- The curve is the model. `Mbbefd.swiss_re(c)` is a one-parameter family: c = 1.5, 2, 3, 4 are the Swiss Re curves and 5 is Lloyd's. Select the curve for each occupancy class and show the sensitivity, as above.
- Exposure curves use the fraction of the MPL. For large industrial risks the MPL can be much less than the sum insured, so the sum insured spreads each loss over too large a base. Put the MPL in [sums_insured](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.sums_insured) when you have it. A first-loss scale from a primary rating manual is a different curve on a different base: do not mix them.
- Prepare large losses before you fit. [LargeLossExperience](../reference/pricing.LargeLossExperience.md#prospicio.pricing.LargeLossExperience) does each step:
  - trend by date at a rate (or a factor for each loss)
  - development of known losses by a [DevelopmentPattern](../reference/pricing.DevelopmentPattern.md#prospicio.pricing.DevelopmentPattern) (or a factor for each loss)
  - an `fx` rate to one currency
  - an [IndexClause](../reference/pricing.IndexClause.md#prospicio.pricing.IndexClause) given to `burning_cost(index=, ratios=)`
- After [prepare](../reference/pricing.LargeLossExperience.md#prospicio.pricing.LargeLossExperience.prepare) develops the known losses, give `burning_cost(..., development=)` only the count IBNR (a factor for each year or a [DevelopmentPattern](../reference/pricing.DevelopmentPattern.md#prospicio.pricing.DevelopmentPattern)). An excess factor that includes IBNER counts it twice.
- With a reporting threshold, the method omits losses below [complete_above()](../reference/pricing.PreparedLosses.md#prospicio.pricing.PreparedLosses.complete_above) (the threshold times the largest trend factor), so each year is complete on the same basis. `PreparedLosses.as_if(historical_towers, years, proposed)` shows the history under the program of each year next to the proposed one.
- [Pareto.fit](../reference/distributions.Pareto.md#prospicio.distributions.Pareto.fit) takes a threshold, optional reporting thresholds for each loss, flags for losses capped by a policy limit ([censored](../reference/pricing.ParetoAnchor.md#prospicio.pricing.ParetoAnchor.censored)) and a [truncation](../reference/distributions.Pareto.md#prospicio.distributions.Pareto.truncation). [Pareto.fit_with_standard_error](../reference/distributions.Pareto.md#prospicio.distributions.Pareto.fit_with_standard_error) also gives the standard error of alpha. For the lognormal, gamma, Weibull and Burr, `fit_severity(family, losses, reporting_thresholds=, censored=)` fits the same data by maximum likelihood. `goodness_of_fit` compares the fit with the product-limit estimate.

**More detail.** [Experience and exposure rating](experience-and-exposure-rating.md), [Severity and frequency](severity-and-frequency.md).


# 3. Casualty excess of loss

Casualty covers (general liability, motor liability, professional lines) attach high and pay for many years. The data are few large losses, policy limits, and slow development. Two ideas:

- The **increased limit factor** (ILF) is the ratio of the expected loss at one policy limit to the expected loss at a basic limit.
- **Pareto extrapolation**: if the severity above a threshold is Pareto with a given alpha, one priced layer gives the price of any layer.

**Data you usually have.** A limits profile (premium written by policy limit), the expected loss ratio of the cedant, a severity curve (from a rating bureau or your own) and a short list of large losses that still develop.

| You have | Use | Call |
|----|----|----|
| A limits profile and an expected loss ratio | Exposure rating: the expected loss of each limit, split into the layer by ILFs | [ilf](../reference/pricing.ilf.md#prospicio.pricing.ilf) in a loop (below) |
| A severity curve from a primary rating bureau or your own data | ILF between limits | `ilf(severity, limit, basic_limit)` |
| The expected loss of one layer, and a view on alpha | Move up or down the tower | `pareto_extrapolation(from, to, alpha)` |
| Expected losses for some layers | Match them with a frequency and a severity | [match_tower](../reference/pricing.match_tower.md#prospicio.pricing.match_tower), [fit_references](../reference/pricing.fit_references.md#prospicio.pricing.fit_references) |
| Excess frequencies at several thresholds | Alpha between them | [alpha_between_frequencies](../reference/pricing.alpha_between_frequencies.md#prospicio.pricing.alpha_between_frequencies), [alpha_between_layers](../reference/pricing.alpha_between_layers.md#prospicio.pricing.alpha_between_layers) |
| A deductible to evaluate | Loss elimination ratio | [loss_elimination_ratio](../reference/pricing.loss_elimination_ratio.md#prospicio.pricing.loss_elimination_ratio) |

The example exposure-rates the layer 1.5 xs 0.5 from a profile of three policy limits. Then it moves between layers.


``` python
from prospicio.distributions import Lognormal
from prospicio.pricing import ilf, match_tower, pareto_extrapolation

policy_severity = Lognormal.from_mean_cv(0.05, 4.0)      # losses to a casualty account
print(f"ILF at a limit of 1 against a basic limit of 0.1: {ilf(policy_severity, 1.0, 0.1):.2f}")
```


    ILF at a limit of 1 against a basic limit of 0.1: 1.68


``` python
import pandas as pd
from great_tables import GT

LIMIT, ATTACHMENT, ELR, BASIC = 1.5, 0.5, 0.65, 0.1
PREMIUMS = [30.0, 20.0, 10.0]                                               # premium written at each limit
rows = []
for policy_limit, premium in zip([0.5, 1.0, 2.0], PREMIUMS):
    low, high = min(policy_limit, ATTACHMENT), min(policy_limit, ATTACHMENT + LIMIT)
    in_layer = (ilf(policy_severity, high, BASIC) - ilf(policy_severity, low, BASIC)) / ilf(policy_severity, policy_limit, BASIC)
    rows.append((f"{policy_limit}", premium, in_layer, premium * ELR * in_layer))
layer_el = sum(r[3] for r in rows)
rows.append(("all limits", sum(PREMIUMS), layer_el / (sum(PREMIUMS) * ELR), layer_el))
by_limit = pd.DataFrame(rows, columns=["limit", "premium", "share", "loss"])
(GT(by_limit, rowname_col="limit")
 .tab_header("Exposure rating of the layer 1.5 xs 0.5", "By policy limit; expected loss ratio 0.65")
 .cols_label(share="share of loss in layer", loss="layer loss")
 .fmt_number("premium", decimals=1)
 .fmt_number(["share", "loss"], decimals=3))
```


<style>
#zoifmrtpgs table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#zoifmrtpgs thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#zoifmrtpgs p { margin: 0; padding: 0; }
 #zoifmrtpgs .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #zoifmrtpgs .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #zoifmrtpgs .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #zoifmrtpgs .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #zoifmrtpgs .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #zoifmrtpgs .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #zoifmrtpgs .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #zoifmrtpgs .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #zoifmrtpgs .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #zoifmrtpgs .gt_column_spanner_outer:first-child { padding-left: 0; }
 #zoifmrtpgs .gt_column_spanner_outer:last-child { padding-right: 0; }
 #zoifmrtpgs .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #zoifmrtpgs .gt_spanner_row { border-bottom-style: hidden; }
 #zoifmrtpgs .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #zoifmrtpgs .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #zoifmrtpgs .gt_from_md> :first-child { margin-top: 0; }
 #zoifmrtpgs .gt_from_md> :last-child { margin-bottom: 0; }
 #zoifmrtpgs .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #zoifmrtpgs .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #zoifmrtpgs .gt_indent_1 { text-indent: 5px; }
 #zoifmrtpgs .gt_indent_2 { text-indent: calc(5px * 2); }
 #zoifmrtpgs .gt_indent_3 { text-indent: calc(5px * 3); }
 #zoifmrtpgs .gt_indent_4 { text-indent: calc(5px * 4); }
 #zoifmrtpgs .gt_indent_5 { text-indent: calc(5px * 5); }
 #zoifmrtpgs .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #zoifmrtpgs .gt_row_group_first td { border-top-width: 2px; }
 #zoifmrtpgs .gt_row_group_first th { border-top-width: 2px; }
 #zoifmrtpgs .gt_striped { color: #333333; background-color: #F4F4F4; }
 #zoifmrtpgs .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #zoifmrtpgs .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #zoifmrtpgs .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #zoifmrtpgs .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #zoifmrtpgs .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #zoifmrtpgs .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #zoifmrtpgs .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #zoifmrtpgs .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #zoifmrtpgs .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #zoifmrtpgs .gt_left { text-align: left; }
 #zoifmrtpgs .gt_center { text-align: center; }
 #zoifmrtpgs .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #zoifmrtpgs .gt_font_normal { font-weight: normal; }
 #zoifmrtpgs .gt_font_bold { font-weight: bold; }
 #zoifmrtpgs .gt_font_italic { font-style: italic; }
 #zoifmrtpgs .gt_super { font-size: 65%; }
 #zoifmrtpgs .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #zoifmrtpgs .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #zoifmrtpgs .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #zoifmrtpgs .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #zoifmrtpgs .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #zoifmrtpgs .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">Exposure rating of the layer 1.5 xs 0.5</th>
</tr>
<tr class="gt_heading">
<th colspan="4" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">By policy limit; expected loss ratio 0.65</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="premium" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">premium</th>
<th id="share" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">share of loss in layer</th>
<th id="loss" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">layer loss</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">0.5</th>
<td class="gt_row gt_right" headers="stub-1 premium">30.0</td>
<td class="gt_row gt_right" headers="stub-1 share">0.000</td>
<td class="gt_row gt_right" headers="stub-1 loss">0.000</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">1.0</th>
<td class="gt_row gt_right" headers="stub-2 premium">20.0</td>
<td class="gt_row gt_right" headers="stub-2 share">0.084</td>
<td class="gt_row gt_right" headers="stub-2 loss">1.098</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">2.0</th>
<td class="gt_row gt_right" headers="stub-3 premium">10.0</td>
<td class="gt_row gt_right" headers="stub-3 share">0.129</td>
<td class="gt_row gt_right" headers="stub-3 loss">0.837</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">all limits</th>
<td class="gt_row gt_right" headers="stub-4 premium">60.0</td>
<td class="gt_row gt_right" headers="stub-4 share">0.050</td>
<td class="gt_row gt_right" headers="stub-4 loss">1.934</td>
</tr>
</tbody>
</table>


The policies with a limit of 0.5 put nothing in the layer. The layer loss is the sum of premium times loss ratio times share. Compare it with a burning cost on developed, trended large losses ([PreparedLosses.burning_cost](../reference/pricing.PreparedLosses.md#prospicio.pricing.PreparedLosses.burning_cost), section 2) before you use either.


``` python
for alpha in (1.5, 2.5):
    print(f"alpha {alpha}: layer 2x2 costs {pareto_extrapolation((1.0, 1.0), (2.0, 2.0), alpha):.1%} of layer 1x1")

tower = match_tower([1.0, 2.0, 5.0], [0.30, 0.20, 0.10])     # three layers; the last is unlimited
print(f"matched tower: {tower.frequency:.2f} losses a year above 1, alphas {[round(a, 2) for a in tower.severity.alpha]}")
print(f"2 xs 3 from the matched tower: {tower.layer_loss(2.0, 3.0):.4f}")
```


    alpha 1.5: layer 2x2 costs 70.7% of layer 1x1
    alpha 2.5: layer 2x2 costs 35.4% of layer 1x1
    matched tower: 0.58 losses a year above 1, alphas [1.86, 1.73, 2.39, 2.2]
    2 xs 3 from the matched tower: 0.0890


**Pitfalls.**

- Prepare losses as in section 2 ([LargeLossExperience.prepare](../reference/pricing.LargeLossExperience.md#prospicio.pricing.LargeLossExperience.prepare)). [ExcessPattern](../reference/reserving.ExcessPattern.md#prospicio.reserving.ExcessPattern) gives the development of the excess layer by blending layer factors from the ground-up triangle and a severity with the factors of the layer ([`reserving-excess-layers.md`](reserving-excess-layers.md)).
- Decide how allocated loss adjustment expense (ALAE) goes into the layer: pro rata with the loss, or added to it within the limit. Treat the losses and the severity curve the same way.
- Pareto extrapolation assumes one alpha across the layers. In casualty this is usually false, so [match_tower](../reference/pricing.match_tower.md#prospicio.pricing.match_tower) fits a piecewise Pareto with one alpha for each layer.
- [match_tower](../reference/pricing.match_tower.md#prospicio.pricing.match_tower) and [fit_references](../reference/pricing.fit_references.md#prospicio.pricing.fit_references) refuse inputs that cannot come from a decreasing, convex excess loss function (for example, rates on line that increase up the tower). A match gives its references exactly, so read `tower.diagnostics()`. Its `warnings` show an alpha below 1, or adjacent alphas more than twice apart. `fit_references(..., alpha_bounds=(lo, hi))` keeps the fitted alphas in a range that you set.
- [compound_moments](../reference/aggregate.compound_moments.md#prospicio.aggregate.compound_moments) gives an error when a severity does not have three finite moments (a Pareto with alpha below 3), so its normal or gamma [approximate](../reference/aggregate.CompoundMoments.md#prospicio.aggregate.CompoundMoments.approximate) is not available. Use the grid or simulation for heavy tails.
- Agree with the wording how these change the losses in the layer: ECO and XPL (extra-contractual obligations and losses in excess of policy limits), clash between policies on one occurrence, and claims-made or occurrence triggers.
- The prices in this section are one-period prices. For a long tail, price over the payout with a [PaymentPattern](../reference/pricing.PaymentPattern.md#prospicio.pricing.PaymentPattern) (for the next accident year, `PaymentPattern.from_development(ages_in_years, paid_cdf)`) and `price_over_payout(price, pattern, rate=, cost_of_capital=)`. Discounting decreases the loss ([discount_factor](../reference/pricing.PayoutPrice.md#prospicio.pricing.PayoutPrice.discount_factor) below 1). Capital held until the last payment increases the capital charge ([capital_years](../reference/pricing.PayoutPrice.md#prospicio.pricing.PayoutPrice.capital_years) above 1). The second effect is usually larger, so the payout premium is often above the one-period premium.

**More detail.** [Experience and exposure rating](experience-and-exposure-rating.md), [Severity and frequency](severity-and-frequency.md).


# 4. Catastrophe excess of loss

A **catastrophe** cover pays on the total of an event (a hurricane, an earthquake) across many risks. The cedant or broker gives the output of a vendor model, and you do not model the hazard again. You get one of these:

- a **year loss table**: a simulated list of years, each with its events and loss amounts
- **return period points** on the occurrence exceedance probability (OEP) curve: the event loss that occurs once in 100 years, and so on

**Data you usually have.** The vendor's year loss table, or its OEP and AEP (aggregate exceedance) points for the portfolio, the layers and reinstatement terms of the program, and some historical events.

| You have | Use | Call |
|----|----|----|
| An event loss table (rate, mean, standard deviations and exposure for each event) | Simulate years from it, or read its OEP and PML | `EventLossTable(rate, mean, sd_independent, sd_correlated, exposure)`. `.simulate(n_years, seed)` gives `(EventSet, event ids)`. `.oep(x)`, `.occurrence_pml(p)` |
| A year loss table | Load it as events, apply the terms | `EventSet.from_years(years, sums_insured, seed, times)`, or `EventSet.from_long(years, losses, n_years)` for one row for each loss (years are indices from 0, and `n_years` is the full simulation count, including the years with no loss). Then [Tower.apply](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) |
| Return period points | Fit a frequency and a severity to them, then use the grid or simulation | `fit_pml_curve(return_periods, amounts, tail_alpha, truncation)` |


``` python
import pandas as pd
from great_tables import GT

from prospicio.pricing import fit_pml_curve

RETURN_PERIODS, AMOUNTS = [10, 20, 50, 100, 250], [30.0, 55.0, 100.0, 140.0, 200.0]
oep = fit_pml_curve(RETURN_PERIODS, AMOUNTS, tail_alpha=2.0, truncation=500.0)
fitted = pd.DataFrame({
    "return period": [str(rp) for rp in RETURN_PERIODS],
    "amount": AMOUNTS,
    "fitted": [oep.excess_frequency(a) for a in AMOUNTS],
    "target": [1 / rp for rp in RETURN_PERIODS],
})
(GT(fitted, rowname_col="return period")
 .tab_header("OEP points refitted", "Events a year above each amount")
 .cols_label(amount="amount", fitted="fitted frequency", target="1 / return period")
 .fmt_number("amount", decimals=1)
 .fmt_number(["fitted", "target"], decimals=4))
```


<style>
#bgxbvyisrd table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#bgxbvyisrd thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#bgxbvyisrd p { margin: 0; padding: 0; }
 #bgxbvyisrd .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #bgxbvyisrd .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #bgxbvyisrd .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #bgxbvyisrd .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #bgxbvyisrd .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #bgxbvyisrd .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #bgxbvyisrd .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #bgxbvyisrd .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #bgxbvyisrd .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #bgxbvyisrd .gt_column_spanner_outer:first-child { padding-left: 0; }
 #bgxbvyisrd .gt_column_spanner_outer:last-child { padding-right: 0; }
 #bgxbvyisrd .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #bgxbvyisrd .gt_spanner_row { border-bottom-style: hidden; }
 #bgxbvyisrd .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #bgxbvyisrd .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #bgxbvyisrd .gt_from_md> :first-child { margin-top: 0; }
 #bgxbvyisrd .gt_from_md> :last-child { margin-bottom: 0; }
 #bgxbvyisrd .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #bgxbvyisrd .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #bgxbvyisrd .gt_indent_1 { text-indent: 5px; }
 #bgxbvyisrd .gt_indent_2 { text-indent: calc(5px * 2); }
 #bgxbvyisrd .gt_indent_3 { text-indent: calc(5px * 3); }
 #bgxbvyisrd .gt_indent_4 { text-indent: calc(5px * 4); }
 #bgxbvyisrd .gt_indent_5 { text-indent: calc(5px * 5); }
 #bgxbvyisrd .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #bgxbvyisrd .gt_row_group_first td { border-top-width: 2px; }
 #bgxbvyisrd .gt_row_group_first th { border-top-width: 2px; }
 #bgxbvyisrd .gt_striped { color: #333333; background-color: #F4F4F4; }
 #bgxbvyisrd .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #bgxbvyisrd .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #bgxbvyisrd .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #bgxbvyisrd .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #bgxbvyisrd .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #bgxbvyisrd .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #bgxbvyisrd .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #bgxbvyisrd .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #bgxbvyisrd .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #bgxbvyisrd .gt_left { text-align: left; }
 #bgxbvyisrd .gt_center { text-align: center; }
 #bgxbvyisrd .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #bgxbvyisrd .gt_font_normal { font-weight: normal; }
 #bgxbvyisrd .gt_font_bold { font-weight: bold; }
 #bgxbvyisrd .gt_font_italic { font-style: italic; }
 #bgxbvyisrd .gt_super { font-size: 65%; }
 #bgxbvyisrd .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #bgxbvyisrd .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #bgxbvyisrd .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #bgxbvyisrd .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #bgxbvyisrd .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #bgxbvyisrd .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">OEP points refitted</th>
</tr>
<tr class="gt_heading">
<th colspan="4" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Events a year above each amount</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="amount" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">amount</th>
<th id="fitted" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">fitted frequency</th>
<th id="target" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">1 / return period</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">10</th>
<td class="gt_row gt_right" headers="stub-1 amount">30.0</td>
<td class="gt_row gt_right" headers="stub-1 fitted">0.1000</td>
<td class="gt_row gt_right" headers="stub-1 target">0.1000</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">20</th>
<td class="gt_row gt_right" headers="stub-2 amount">55.0</td>
<td class="gt_row gt_right" headers="stub-2 fitted">0.0500</td>
<td class="gt_row gt_right" headers="stub-2 target">0.0500</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">50</th>
<td class="gt_row gt_right" headers="stub-3 amount">100.0</td>
<td class="gt_row gt_right" headers="stub-3 fitted">0.0200</td>
<td class="gt_row gt_right" headers="stub-3 target">0.0200</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">100</th>
<td class="gt_row gt_right" headers="stub-4 amount">140.0</td>
<td class="gt_row gt_right" headers="stub-4 fitted">0.0100</td>
<td class="gt_row gt_right" headers="stub-4 target">0.0100</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">250</th>
<td class="gt_row gt_right" headers="stub-5 amount">200.0</td>
<td class="gt_row gt_right" headers="stub-5 fitted">0.0040</td>
<td class="gt_row gt_right" headers="stub-5 target">0.0040</td>
</tr>
</tbody>
</table>


The fit reproduces each point. It reads a return period of RP as an exceedance frequency of 1/RP a year. A vendor OEP probability p is different: convert it with -ln(1 - p) first.


``` python
import math

from prospicio.aggregate import simulate_events
from prospicio.distributions import Grid, Poisson
from prospicio.reinsurance import Layer, Tower

print(f"an OEP probability of 0.10 is {-math.log(1 - 0.10):.4f} events a year")
frequency = Poisson(oep.frequency)
grid, _ = Grid.rounding(oep.severity, 1.0, 501)
cat_layers = [Layer("50x50", 50.0, 50.0, reinstatements=1), Layer("100x100", 100.0, 100.0, reinstatements=1)]
exact = Tower(cat_layers).on_grid(frequency, grid, 2**11)
sim = Tower(cat_layers).apply(simulate_events(frequency, oep.severity, 20_000, 1))
ceded = pd.DataFrame(
    [["exact on the grid", *[g.mean() for g in exact.ceded]],
     ["simulated events", *[sim.marginal(("ceded", l.name)).mean() for l in cat_layers]]],
    columns=["method", "50x50", "100x100"])
(GT(ceded, rowname_col="method")
 .tab_header("Expected ceded loss a year", "Two catastrophe layers with one reinstatement")
 .fmt_number(["50x50", "100x100"], decimals=3))
```


    an OEP probability of 0.10 is 0.1054 events a year


<style>
#kagjzdgcmx table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#kagjzdgcmx thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#kagjzdgcmx p { margin: 0; padding: 0; }
 #kagjzdgcmx .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #kagjzdgcmx .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #kagjzdgcmx .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #kagjzdgcmx .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #kagjzdgcmx .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #kagjzdgcmx .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #kagjzdgcmx .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #kagjzdgcmx .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #kagjzdgcmx .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #kagjzdgcmx .gt_column_spanner_outer:first-child { padding-left: 0; }
 #kagjzdgcmx .gt_column_spanner_outer:last-child { padding-right: 0; }
 #kagjzdgcmx .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #kagjzdgcmx .gt_spanner_row { border-bottom-style: hidden; }
 #kagjzdgcmx .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #kagjzdgcmx .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #kagjzdgcmx .gt_from_md> :first-child { margin-top: 0; }
 #kagjzdgcmx .gt_from_md> :last-child { margin-bottom: 0; }
 #kagjzdgcmx .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #kagjzdgcmx .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #kagjzdgcmx .gt_indent_1 { text-indent: 5px; }
 #kagjzdgcmx .gt_indent_2 { text-indent: calc(5px * 2); }
 #kagjzdgcmx .gt_indent_3 { text-indent: calc(5px * 3); }
 #kagjzdgcmx .gt_indent_4 { text-indent: calc(5px * 4); }
 #kagjzdgcmx .gt_indent_5 { text-indent: calc(5px * 5); }
 #kagjzdgcmx .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #kagjzdgcmx .gt_row_group_first td { border-top-width: 2px; }
 #kagjzdgcmx .gt_row_group_first th { border-top-width: 2px; }
 #kagjzdgcmx .gt_striped { color: #333333; background-color: #F4F4F4; }
 #kagjzdgcmx .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #kagjzdgcmx .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #kagjzdgcmx .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #kagjzdgcmx .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #kagjzdgcmx .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #kagjzdgcmx .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #kagjzdgcmx .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #kagjzdgcmx .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #kagjzdgcmx .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #kagjzdgcmx .gt_left { text-align: left; }
 #kagjzdgcmx .gt_center { text-align: center; }
 #kagjzdgcmx .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #kagjzdgcmx .gt_font_normal { font-weight: normal; }
 #kagjzdgcmx .gt_font_bold { font-weight: bold; }
 #kagjzdgcmx .gt_font_italic { font-style: italic; }
 #kagjzdgcmx .gt_super { font-size: 65%; }
 #kagjzdgcmx .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #kagjzdgcmx .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #kagjzdgcmx .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #kagjzdgcmx .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #kagjzdgcmx .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #kagjzdgcmx .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Expected ceded loss a year</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Two catastrophe layers with one reinstatement</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="50x50" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">50x50</th>
<th id="100x100" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">100x100</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">exact on the grid</th>
<td class="gt_row gt_right" headers="stub-1 50x50">1.672</td>
<td class="gt_row gt_right" headers="stub-1 100x100">0.948</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">simulated events</th>
<td class="gt_row gt_right" headers="stub-2 50x50">1.684</td>
<td class="gt_row gt_right" headers="stub-2 100x100">0.947</td>
</tr>
</tbody>
</table>


The two agree within simulation error. With event times ([EventSet.with_uniform_times](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.with_uniform_times), [with_seasonal_times](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.with_seasonal_times)), the simulation also applies reinstatements pro rata as to time.

**Pitfalls.**

- A fitted OEP curve describes events above its lowest point only. Here it models nothing below 30.
- Return period points give the loss of one event, not the total of the year, so the number of events matters for a cover with an annual limit or paid reinstatements. When the vendor's events cluster, a Poisson count fitted to OEP points gives too few years with several events. Use the year loss table (its AEP) when you have it, and the OEP fit only when you do not.
- In an [EventLossTable](../reference/aggregate.EventLossTable.md#prospicio.aggregate.EventLossTable), the secondary uncertainty of each event is a beta on \[0, exposure\] with the mean and standard deviation of the row.
- `EventSet.grouped(window_hours)` groups losses into occurrences under an hours clause (a year is 8,760 hours). It needs each loss's time as a fraction of a year (`from_years(..., times=)`, [with_uniform_times](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.with_uniform_times) or [with_seasonal_times](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.with_seasonal_times)).
- [EventSet.merge](../reference/aggregate.EventSet.md#prospicio.aggregate.EventSet.merge) adds a non-cat set year by year.
- For clash across two lines (one event hits both), use [Clash](../reference/aggregate.Clash.md#prospicio.aggregate.Clash) or [fft_bivariate](../reference/aggregate.fft_bivariate.md#prospicio.aggregate.fft_bivariate) on a joint grid (`prospicio.aggregate`), with a copula between the lines in an event if needed.

**More detail.** [Aggregate distributions](aggregate-distributions.md) (grid and simulation), [What a reinsurance price is](reinsurance-price.md) (the price of a layer).


# 5. Quota share, surplus and other proportional treaties

A **quota share** cedes a constant share of the premium and losses of each policy. A **surplus** treaty cedes, for each risk, the part of the sum insured above the retention line of the cedant, up to a given number of lines, so the ceded share differs by risk. The reinsurer pays the cedant a **ceding commission**, and the commission is the price.

**What sets the price.** The loss ratio of the full book, not only the large losses: you need its annual distribution and the terms that move the commission with it:

- a **sliding scale**: the commission decreases as the loss ratio increases
- a **profit commission**: the reinsurer gives a share of its profit back to the cedant

**Data you usually have.** The subject premium (the premium that the treaty shares), the loss ratios of the cedant by underwriting year with development, its expense ratio, and the commission and brokerage terms offered. For a surplus, also the risk profile by sum insured. The expected loss ratio is the on-level, developed and trended one, as in section 1. The spread around it comes from the claim count and severity, or from the variation of those loss ratios from year to year.

| Situation | Method | Call |
|----|----|----|
| Quota share price | Technical commission: 1 minus the expected ceded loss ratio, expenses, brokerage and margin | [Tower.on_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_grid) for the ceded grid (or [Tower.on_annual_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_annual_grid) on a loss-ratio grid), `price(grid, Distortion.tvar(0.99), cost_of_capital=r)` for the margin |
| Sliding scale or profit commission | Expected commission over the loss ratio distribution | [with_sliding_scale](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_sliding_scale), [with_profit_commission](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_profit_commission), [TowerGrids.expected_ceding_commission](../reference/reinsurance.TowerGrids.md#prospicio.reinsurance.TowerGrids.expected_ceding_commission) or [AnnualGrids.expected_ceding_commission](../reference/reinsurance.AnnualGrids.md#prospicio.reinsurance.AnnualGrids.expected_ceding_commission) |
| Surplus | Simulated events with sums insured | [Layer.surplus](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.surplus), [RiskProfile.simulate](../reference/pricing.RiskProfile.md#prospicio.pricing.RiskProfile.simulate), [Tower.apply](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) |
| Surplus inuring to a per-risk excess of loss | Stages in order | `Tower.inuring([[surplus], [xl]])` |

This example puts a quota share and an aggregate stop loss on one book, which section 6 reuses: 400 claims a year (a spread wider than Poisson), 100 of premium, an expected loss ratio of 60%.


``` python
from prospicio.distributions import Grid, Lognormal, NegativeBinomial
from prospicio.pricing import price
from prospicio.reinsurance import Layer, Tower
from prospicio.risk import Distortion

SUBJECT = 100.0
claims = NegativeBinomial.from_mean_variance(400.0, 600.0)
claim_grid, _ = Grid.rounding(Lognormal.from_mean_cv(0.15, 2.0), 0.01, 2000)

qs = (Layer.quota_share("QS 30%", 0.30).with_premium_rate(1.0, SUBJECT)
      .with_sliding_scale([(0.35, 0.55), (0.30, 0.65), (0.25, 0.75)]))
stop = Layer.stop_loss("SL 20 xs 70", 20.0, 70.0).with_deposit_premium(2.0)
book = Tower([qs, stop]).on_grid(claims, claim_grid, 2**14)
qs_loss, sl_loss = (g.mean() for g in book.ceded)
qs_premium, qs_commission = book.expected_premium[0], book.expected_ceding_commission[0]
print(f"book loss ratio {book.gross.mean() / SUBJECT:.1%}, spread (sd) {book.gross.variance() ** 0.5 / SUBJECT:.1%} of premium")
print(f"QS: ceded premium {qs_premium:.1f}, ceded loss {qs_loss:.2f}, "
      f"expected commission {qs_commission:.2f} ({qs_commission / qs_premium:.1%})")
annual = Tower([qs]).on_annual_grid(book.gross)      # the same terms on the year's total alone, no claim count
print(f"QS on the annual total grid: expected commission {annual.expected_ceding_commission[0]:.2f}")

tvar99 = Distortion.tvar(0.99)
EXPENSES, BROKERAGE = 0.02, 0.015
# Flat commission: the reinsurer pays the ceded loss plus a fixed commission, so only the loss is at risk.
flat = price(book.ceded[0], tvar99, cost_of_capital=0.10)    # assets at 99% TVaR, 10% on capital
technical = 1 - qs_loss / qs_premium - EXPENSES - BROKERAGE - flat.margin / qs_premium
print(f"flat: tail above the mean {flat.assets - qs_loss:.2f}, capital {flat.capital:.2f}; technical commission {technical:.1%}")
# Sliding scale: the reinsurer pays the ceded loss plus a commission that falls as the loss rises.
outgo, _ = book.ceded[0].map(lambda loss: loss + qs.ceding_commission_for(loss))
scale = price(outgo, tvar99, cost_of_capital=0.10)
available = qs_premium * (1 - EXPENSES - BROKERAGE) - outgo.mean()
print(f"scale: tail above the mean {scale.assets - outgo.mean():.2f}, capital {scale.capital:.2f}; "
      f"margin needed {scale.margin:.2f}, margin in the terms {available:.2f}")
```


    book loss ratio 60.0%, spread (sd) 7.0% of premium
    QS: ceded premium 30.0, ceded loss 18.00, expected commission 9.64 (32.1%)
    QS on the annual total grid: expected commission 9.64
    flat: tail above the mean 6.71, capital 6.10; technical commission 34.5%
    scale: tail above the mean 4.57, capital 4.16; margin needed 0.42, margin in the terms 1.32


The third line puts the quota share on the total of the year alone, as when a cedant gives a loss ratio distribution with no claim count. [Tower.on_annual_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_annual_grid) treats that total as one loss. The terms depend only on the total, so the commission is the same. [price](../reference/pricing.price.md#prospicio.pricing.price) sets the assets at the 99% TVaR of each grid and charges 10% on the capital (the assets above the premium).

The two contracts price different risks, so do not compare the scale's expected commission (32.1%) with the flat technical commission (34.5%):

- With a flat commission, only the ceded loss is at risk. A 10% return on its capital allows a commission of 34.5%.
- With the scale, the outgo of the reinsurer is the loss plus a commission that decreases as the loss increases. The scale gives part of the loss ratio spread back to the cedant, so the tail above the mean and the capital fall.

The scale leaves a margin of 1.32 against the 0.42 needed. Its terms price above the target, so you can raise the commission until the two are equal.

A surplus needs events that have sums insured. [RiskProfile.simulate](../reference/pricing.RiskProfile.md#prospicio.pricing.RiskProfile.simulate) makes them from the profile of section 2. The exposure-rated [expected_surplus_loss](../reference/pricing.RiskProfile.md#prospicio.pricing.RiskProfile.expected_surplus_loss) checks the simulation:


``` python
from prospicio.pricing import Mbbefd, RiskProfile
from prospicio.reinsurance import Layer, Tower

profile = RiskProfile([1.0, 3.0, 6.0, 12.0], [400, 150, 60, 20], Mbbefd.swiss_re(3.0),
                      premiums=[8.0, 6.0, 5.0, 4.0], loss_ratio=0.55)
surplus = Layer.surplus("S 9 lines", 1.0, 9.0)                   # retention 1, up to 9 lines
for size in (5.0, 20.0):
    print(f"a risk of {size:.0f} cedes {surplus.ceded_with_sums_insured([1.0], [size]):.0%} of its loss")
simulated = Tower([surplus]).apply(profile.simulate(20_000, 1)).marginal(("ceded", "S 9 lines")).mean()
print(f"ceded loss a year: simulated {simulated:.2f}, exposure rated {profile.expected_surplus_loss(1.0, 9.0):.2f}, "
      f"of a total {profile.expected_loss():.2f}")
```


    a risk of 5 cedes 80% of its loss
    a risk of 20 cedes 45% of its loss
    ceded loss a year: simulated 6.13, exposure rated 6.14, of a total 12.65


The cession goes through the same commission calculation as the quota share. A per-risk excess of loss on the retained part is a second stage (`Tower.inuring([[surplus], [xl]])`).

**Pitfalls.**

- A quota share depends on the loss ratio of the full book. Attritional losses held at their mean give too little capital: give them a spread.
- Set the premium ([with_premium_rate](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_premium_rate), [with_deposit_premium](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_deposit_premium) or [with_rate_on_line](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_rate_on_line)) before [with_sliding_scale](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_sliding_scale) or [with_profit_commission](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_profit_commission), which need it for the loss ratio. A sliding scale cannot combine with swing rating or paid reinstatements.
- For a quota share or stop loss on an annual loss ratio grid (no claim count), use `Tower.on_annual_grid(grid)`: `.ceded`, [expected_ceding_commission](../reference/reinsurance.TowerGrids.md#prospicio.reinsurance.TowerGrids.expected_ceding_commission) and [expected_profit_commission](../reference/reinsurance.TowerGrids.md#prospicio.reinsurance.TowerGrids.expected_profit_commission) are exact. Per-occurrence layers with a severity need [on_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_grid).
- `price(losses, assets, cost_of_capital=r)` takes a grid, simulated losses ([Sampled](../reference/distributions.Sampled.md#prospicio.distributions.Sampled)) or a [PredictiveDistribution](../reference/distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution). [assets](../reference/pricing.Price.md#prospicio.pricing.Price.assets) is a distortion risk measure (here 99% TVaR). The result has `.margin`, `.capital` and `.assets`.

**More detail.** [What a reinsurance price is](reinsurance-price.md), section 4.


# 6. Aggregate stop loss, adverse development and loss portfolio covers

- A **stop loss** (aggregate excess of loss) pays when the total of the year is more than a retention, up to a limit.
- An **adverse development cover** (ADC) does the same on reserves. It pays when the reserve for past years becomes worse than a retention.
- A **loss portfolio transfer** (LPT) moves a block of reserves to the reinsurer for a premium.

All three pay on a total, so the work is to find the distribution of that total.

| The total comes from | Method | Call |
|----|----|----|
| A claim count and a severity | Exact aggregate on the grid | [Tower.on_grid](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.on_grid), or [fft](../reference/aggregate.fft.md#prospicio.aggregate.fft) and [fft_auto](../reference/aggregate.fft_auto.md#prospicio.aggregate.fft_auto) for the distribution alone |
| Simulated events | Apply to each year | [Tower.apply](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) |
| A reserve bootstrap | Apply the cover to the simulated reserve | `Tower.apply_aggregate(boot.reserves)` |

**Data you usually have.** For a stop loss, the same data as for a quota share (section 5). For an ADC or LPT, the reserve triangles of the covered years, the booked reserves, and the payment pattern.

This block uses `book` from section 5, whose stop loss pays on the gross total. Its deposit premium of 2.0 there is a placeholder. The block prices it as section 5 priced the flat quota share.


``` python
sl_grid = book.ceded[1]
sl_price = price(sl_grid, Distortion.tvar(0.99), cost_of_capital=0.10)
print(f"stop loss 20 xs 70: expected loss {sl_loss:.3f}, chance of any recovery {1 - sl_grid.cdf(0.0):.1%}")
print(f"at 99% TVaR assets and 10% on capital: premium {sl_price.premium:.2f} "
      f"(rate on line {sl_price.premium / 20.0:.1%}), capital {sl_price.capital:.2f}")
```


    stop loss 20 xs 70: expected loss 0.339, chance of any recovery 8.2%
    at 99% TVaR assets and 10% on capital: premium 1.42 (rate on line 7.1%), capital 10.79


A stop loss pays rarely, and then a large amount, so most of its premium is the margin on its capital. The capital standard and the cost of capital set the price: state both with the quote. An ADC is the same call on a different total (section 7).

**Pitfalls.**

- The retention and limit apply to the total that the cover sees. In a [Tower](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower) with stages, that total is net of earlier stages ([Tower.inuring](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.inuring)).
- The total must have the correct tail. A normal or gamma approximation of the total (`compound_moments(...).approximate`) gives a heavy tail that is too small. The grid does not.
- For an ADC or LPT, the uncertainty is in the reserve, so use a bootstrap or a Bayesian model, not a point estimate. A bootstrap has only parameter and process error under its model's assumptions (here the chain ladder, with no tail unless you give one). It has no calendar-year inflation shock and no change in claims handling, which usually cause an ADC loss. Treat its result as a minimum, and show the layer under a second method or tail (section 7).
- Time value matters for an ADC or LPT, which have a long tail. The prices here are one-period prices: use `price_over_payout(price(...), pattern, rate=, cost_of_capital=)` and read its effects as in section 3.
- The pattern for a reserve cover is the calendar-year run-off of the reserve from the valuation date. It is not the development of one accident year. Make it from the paid chain ladder (the `cl` of section 7) as follows:
  1.  Origin i, with its latest age at index k_i, pays `ult_i / cdf[j] - ult_i / cdf[j - 1]` at calendar time j - k_i, for each later age index j.
  2.  Add these payments over the origins by calendar time.
  3.  Give the times and the shares of the total to `PaymentPattern(times, shares)`.
- A layer that attaches above the mean reserve pays later, so the duration of that pattern is a lower bound for the layer. For a cover on a future accident year, use `PaymentPattern.from_development(ages_in_years, paid_cdf)` (with `.shifted`).
- [Layer.with_rate_on_line](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_rate_on_line) needs a finite limit for each loss, so it refuses a stop loss. Set its premium with [with_deposit_premium](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_deposit_premium) or [with_premium_rate](../reference/reinsurance.Layer.md#prospicio.reinsurance.Layer.with_premium_rate).

**More detail.** [Aggregate distributions](aggregate-distributions.md), [Reserving methods](reserving-methods.md).


# 7. Reserving a book and its uncertainty

Reserving turns a **triangle** (losses by origin year and development age) into an estimate of the amount still to be paid.

**Data you usually have.** Paid and incurred triangles by origin year, premium or another exposure by origin year, and a prior loss ratio from pricing.

| Question | Method | Call |
|----|----|----|
| The best estimate of the reserve | Chain ladder. Bornhuetter-Ferguson, Cape Cod or expected loss when a year is immature. Clark for a growth curve | [ChainLadder](../reference/reserving.ChainLadder.md#prospicio.reserving.ChainLadder), [BornhuetterFerguson](../reference/reserving.BornhuetterFerguson.md#prospicio.reserving.BornhuetterFerguson), [CapeCod](../reference/reserving.CapeCod.md#prospicio.reserving.CapeCod), [ExpectedLoss](../reference/reserving.ExpectedLoss.md#prospicio.reserving.ExpectedLoss), [ClarkLdf](../reference/reserving.ClarkLdf.md#prospicio.reserving.ClarkLdf) |
| Its uncertainty to ultimate (the **lifetime** view) | Mack's formula, or a bootstrap for a full distribution | [Mack](../reference/reserving.Mack.md#prospicio.reserving.Mack), [OdpBootstrap](../reference/reserving.OdpBootstrap.md#prospicio.reserving.OdpBootstrap), [MackBootstrap](../reference/reserving.MackBootstrap.md#prospicio.reserving.MackBootstrap) |
| Its uncertainty over the next calendar year (the **one-year** view, for solvency capital) | Merz-Wuthrich from Mack, or re-reserving in a bootstrap | `Mack().fit(...).claims_development_result()`, [OdpBootstrap.one_year](../reference/reserving.OdpBootstrap.md#prospicio.reserving.OdpBootstrap.one_year), [MackBootstrap.one_year](../reference/reserving.MackBootstrap.md#prospicio.reserving.MackBootstrap.one_year) |
| A distribution that includes prior information | Bayesian chain ladder | `BayesOdp`, `Meyers` |

The chain ladder reads development only from the triangle. For the latest origin years it multiplies a small number by a large factor. Bornhuetter-Ferguson mixes the chain ladder with a prior expected loss ratio and is more stable there. Use it when you trust the prior and have an exposure measure (premium) in the triangle.


``` python
import csv
from pathlib import Path

from prospicio.reinsurance import Layer, Tower
from prospicio.reserving import BornhuetterFerguson, ChainLadder, Mack, OdpBootstrap, Triangle

rows = list(csv.DictReader(l for l in open(Path("../../validation/data/genins.csv")) if not l.startswith("#")))
tri = Triangle.from_long([int(r["origin"]) for r in rows], [int(r["development"]) for r in rows],
                         {"paid": [float(r["value"]) for r in rows], "premium": [8.0e6] * len(rows)})
cl = ChainLadder().fit(tri, "paid")
mack = Mack().fit(tri, "paid")
cdr = mack.claims_development_result()
print(f"chain ladder reserve {cl.total_reserve / 1e6:.2f}m; Mack standard error {mack.total_standard_error / 1e6:.2f}m "
      f"(next year only: {cdr.total_one_year_standard_error / 1e6:.2f}m)")
bf = BornhuetterFerguson(apriori=0.65).fit(tri, "paid", "premium")
print(f"Bornhuetter-Ferguson reserve {bf.total_reserve / 1e6:.2f}m")
```


    chain ladder reserve 18.68m; Mack standard error 2.44m (next year only: 1.77m)
    Bornhuetter-Ferguson reserve 17.53m


Bornhuetter-Ferguson is more stable in the latest years:


``` python
import pandas as pd
from great_tables import GT

latest = pd.DataFrame({
    "origin": ["latest - 2", "latest - 1", "latest"],
    "cl": [u / 1e6 for u in cl.ultimate[-3:]],
    "bf": [u / 1e6 for u in bf.ultimate[-3:]],
})
(GT(latest, rowname_col="origin")
 .tab_header("Ultimate of the latest three origin years", "Millions")
 .cols_label(cl="chain ladder", bf="Bornhuetter-Ferguson")
 .fmt_number(["cl", "bf"], decimals=2))
```


<style>
#ntxqyxponv table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#ntxqyxponv thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#ntxqyxponv p { margin: 0; padding: 0; }
 #ntxqyxponv .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #ntxqyxponv .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #ntxqyxponv .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #ntxqyxponv .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #ntxqyxponv .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ntxqyxponv .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ntxqyxponv .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ntxqyxponv .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #ntxqyxponv .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #ntxqyxponv .gt_column_spanner_outer:first-child { padding-left: 0; }
 #ntxqyxponv .gt_column_spanner_outer:last-child { padding-right: 0; }
 #ntxqyxponv .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #ntxqyxponv .gt_spanner_row { border-bottom-style: hidden; }
 #ntxqyxponv .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #ntxqyxponv .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #ntxqyxponv .gt_from_md> :first-child { margin-top: 0; }
 #ntxqyxponv .gt_from_md> :last-child { margin-bottom: 0; }
 #ntxqyxponv .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #ntxqyxponv .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #ntxqyxponv .gt_indent_1 { text-indent: 5px; }
 #ntxqyxponv .gt_indent_2 { text-indent: calc(5px * 2); }
 #ntxqyxponv .gt_indent_3 { text-indent: calc(5px * 3); }
 #ntxqyxponv .gt_indent_4 { text-indent: calc(5px * 4); }
 #ntxqyxponv .gt_indent_5 { text-indent: calc(5px * 5); }
 #ntxqyxponv .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #ntxqyxponv .gt_row_group_first td { border-top-width: 2px; }
 #ntxqyxponv .gt_row_group_first th { border-top-width: 2px; }
 #ntxqyxponv .gt_striped { color: #333333; background-color: #F4F4F4; }
 #ntxqyxponv .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ntxqyxponv .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ntxqyxponv .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #ntxqyxponv .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ntxqyxponv .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ntxqyxponv .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #ntxqyxponv .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #ntxqyxponv .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ntxqyxponv .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ntxqyxponv .gt_left { text-align: left; }
 #ntxqyxponv .gt_center { text-align: center; }
 #ntxqyxponv .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #ntxqyxponv .gt_font_normal { font-weight: normal; }
 #ntxqyxponv .gt_font_bold { font-weight: bold; }
 #ntxqyxponv .gt_font_italic { font-style: italic; }
 #ntxqyxponv .gt_super { font-size: 65%; }
 #ntxqyxponv .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ntxqyxponv .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #ntxqyxponv .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ntxqyxponv .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ntxqyxponv .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #ntxqyxponv .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Ultimate of the latest three origin years</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Millions</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="cl" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">chain ladder</th>
<th id="bf" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">Bornhuetter-Ferguson</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">latest - 2</th>
<td class="gt_row gt_right" headers="stub-1 cl">6.78</td>
<td class="gt_row gt_right" headers="stub-1 bf">5.87</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">latest - 1</th>
<td class="gt_row gt_right" headers="stub-2 cl">5.64</td>
<td class="gt_row gt_right" headers="stub-2 bf">5.31</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">latest</th>
<td class="gt_row gt_right" headers="stub-3 cl">4.97</td>
<td class="gt_row gt_right" headers="stub-3 bf">5.18</td>
</tr>
</tbody>
</table>


A bootstrap is a minimum for the uncertainty of an ADC. The triangle cannot show whether a 5% tail is right, and a 5% tail makes the expected recovery almost three times larger (0.65m to 1.82m in the table below). The cost of the layer depends on the model, so show it under more than one:


``` python
adc_layer = Tower([Layer.stop_loss("ADC", 5e6, 20e6)])
rows = []
for tail in (1.0, 1.05):                               # no tail, then a 5% tail past the oldest age
    boot = OdpBootstrap(n_sims=2000, seed=1, tail=tail).fit(tri, "paid")
    total = boot.reserves.total()
    recovery = adc_layer.apply_aggregate(boot.reserves).marginal(("ceded", "ADC")).mean()
    rows.append((f"{tail:.2f}", total.mean() / 1e6, total.quantile(0.995) / 1e6, recovery / 1e6))
boots = pd.DataFrame(rows, columns=["tail", "mean", "q995", "recovery"])
(GT(boots, rowname_col="tail")
 .tab_header("ODP bootstrap of the total reserve", "Millions; the ADC pays 5 xs 20")
 .cols_label(mean="mean", q995="99.5%", recovery="ADC expected recovery")
 .fmt_number(["mean", "q995", "recovery"], decimals=2))
```


<style>
#saeunhvddw table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#saeunhvddw thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#saeunhvddw p { margin: 0; padding: 0; }
 #saeunhvddw .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #saeunhvddw .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #saeunhvddw .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #saeunhvddw .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #saeunhvddw .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #saeunhvddw .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #saeunhvddw .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #saeunhvddw .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #saeunhvddw .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #saeunhvddw .gt_column_spanner_outer:first-child { padding-left: 0; }
 #saeunhvddw .gt_column_spanner_outer:last-child { padding-right: 0; }
 #saeunhvddw .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #saeunhvddw .gt_spanner_row { border-bottom-style: hidden; }
 #saeunhvddw .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #saeunhvddw .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #saeunhvddw .gt_from_md> :first-child { margin-top: 0; }
 #saeunhvddw .gt_from_md> :last-child { margin-bottom: 0; }
 #saeunhvddw .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #saeunhvddw .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #saeunhvddw .gt_indent_1 { text-indent: 5px; }
 #saeunhvddw .gt_indent_2 { text-indent: calc(5px * 2); }
 #saeunhvddw .gt_indent_3 { text-indent: calc(5px * 3); }
 #saeunhvddw .gt_indent_4 { text-indent: calc(5px * 4); }
 #saeunhvddw .gt_indent_5 { text-indent: calc(5px * 5); }
 #saeunhvddw .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #saeunhvddw .gt_row_group_first td { border-top-width: 2px; }
 #saeunhvddw .gt_row_group_first th { border-top-width: 2px; }
 #saeunhvddw .gt_striped { color: #333333; background-color: #F4F4F4; }
 #saeunhvddw .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #saeunhvddw .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #saeunhvddw .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #saeunhvddw .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #saeunhvddw .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #saeunhvddw .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #saeunhvddw .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #saeunhvddw .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #saeunhvddw .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #saeunhvddw .gt_left { text-align: left; }
 #saeunhvddw .gt_center { text-align: center; }
 #saeunhvddw .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #saeunhvddw .gt_font_normal { font-weight: normal; }
 #saeunhvddw .gt_font_bold { font-weight: bold; }
 #saeunhvddw .gt_font_italic { font-style: italic; }
 #saeunhvddw .gt_super { font-size: 65%; }
 #saeunhvddw .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #saeunhvddw .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #saeunhvddw .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #saeunhvddw .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #saeunhvddw .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #saeunhvddw .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">ODP bootstrap of the total reserve</th>
</tr>
<tr class="gt_heading">
<th colspan="4" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Millions; the ADC pays 5 xs 20</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="mean" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">mean</th>
<th id="q995" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">99.5%</th>
<th id="recovery" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">ADC expected recovery</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">1.00</th>
<td class="gt_row gt_right" headers="stub-1 mean">18.80</td>
<td class="gt_row gt_right" headers="stub-1 q995">27.80</td>
<td class="gt_row gt_right" headers="stub-1 recovery">0.65</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">1.05</th>
<td class="gt_row gt_right" headers="stub-2 mean">21.47</td>
<td class="gt_row gt_right" headers="stub-2 q995">30.77</td>
<td class="gt_row gt_right" headers="stub-2 recovery">1.82</td>
</tr>
</tbody>
</table>


The data are GenIns, a public triangle of paid losses in `validation/data`. The premium column is a constant 8.0m a year that only gives Bornhuetter-Ferguson an exposure to scale. Use your own.

**Pitfalls.**

- Development ages are in months (12, 24, …). The library refuses ages of 1, 2, 3, because they are not on the development grid.
- Mack's formula gives a lifetime standard error. The one-year figure is smaller, and it is the right one for a one-year solvency capital: do not mix them. The ODP bootstrap's simulated one-year view differs from Merz-Wuthrich (`knowledge/findings/one-year-bootstrap-vs-merz-wuthrich.md` has the causes). [MackBootstrap](../reference/reserving.MackBootstrap.md#prospicio.reserving.MackBootstrap) agrees with it.
- BF takes its exposure as a triangle column (the latest value for each origin) and [apriori](../reference/reserving.Benktander.md#prospicio.reserving.Benktander.apriori) as one loss ratio for all origins. For a prior that changes by year, give [apriori](../reference/reserving.Benktander.md#prospicio.reserving.Benktander.apriori) as a dict keyed by accident year (or a pandas Series indexed by year). Keys are safer than a list in origin order.
- The bootstraps give a [PredictiveDistribution](../reference/distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution) (each simulation of each origin), which section 8 needs. The mean and quantiles come from `boot.reserves.total()`.
- `cl.ultimate`, `cl.total_reserve` and `boot.reserves` are properties. `mack.claims_development_result()` is a method.

**More detail.** [Reserving methods](reserving-methods.md).


# 8. Capital, risk measures and allocation

Capital is an amount that you select from the distribution of the result of the year. A **distortion risk measure** turns a distribution into one number and gives more weight to the tail. **TVaR** at 99% is the average loss in the worst 1% of years. The company selects the measure and the level.

**Data you usually have.** Simulated or gridded annual results by line or contract (from the sections above, a reserve bootstrap, a cat model), their dependence, and the capital standard and target return of the company.

| You want | Measure or method | Call |
|----|----|----|
| Capital standard, TVaR | Average of the worst `1 - p` of years | `Distortion.tvar(p).measure(dist)` |
| Capital standard, VaR (a Solvency II style 99.5%) | A quantile | `dist.quantile(p)` on a [PredictiveDistribution](../reference/distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution) or grid. `Portfolio.price(..., p=p)` sets the assets at it |
| A price that adds a margin for each unit of capital | Constant cost of capital | `Distortion.ccoc(r)`, `price(losses, assets, cost_of_capital=r)` |
| A price of risk that changes with the tail, fitted to a market quote | Proportional hazard, Wang, dual power | [Distortion.proportional_hazard](../reference/risk.Distortion.md#prospicio.risk.Distortion.proportional_hazard), `.wang`, `.dual_power`. [calibrate](../reference/risk.calibrate.md#prospicio.risk.calibrate) |
| Capital split over lines or contracts | Euler (co-measure), covariance, proportional, Shapley | `capital(pd, distortion, method=...)`, [allocate](../reference/risk.allocate.md#prospicio.risk.allocate) |
| Dependence between lines | Copula or rank correlation | [GaussianCopula](../reference/risk.GaussianCopula.md#prospicio.risk.GaussianCopula), [StudentTCopula](../reference/risk.StudentTCopula.md#prospicio.risk.StudentTCopula), `ArchimedeanCopula("clayton" or "gumbel", ...)`, [iman_conover](../reference/risk.iman_conover.md#prospicio.risk.iman_conover), [simulate](../reference/risk.simulate.md#prospicio.risk.simulate) |


``` python
from prospicio.distributions import Lognormal
from prospicio.risk import Distortion, GaussianCopula, capital, simulate

KEYS = [("reserve",), ("premium",), ("cat",)]
lines = simulate(
    GaussianCopula([[1.0, 0.3, 0.1], [0.3, 1.0, 0.2], [0.1, 0.2, 1.0]]),
    [Lognormal.from_mean_cv(50, 0.15), Lognormal.from_mean_cv(30, 0.25), Lognormal.from_mean_cv(10, 1.0)],
    20_000, 1, keys=KEYS, dims=["risk"],
)
means = [lines.marginal(k).mean() for k in KEYS]
print("expected loss  ", [round(m, 1) for m in means])
tvar99 = Distortion.tvar(0.99)
allocs = {method: capital(lines, tvar99, method=method) for method in ("euler", "covariance", "marginal")}
a = allocs["marginal"]
print(f"TVaR 99% of the total {a.total:.1f}; the lines alone sum to {sum(a.standalone):.1f}")
```


    expected loss   [50.0, 30.0, 10.0]
    TVaR 99% of the total 159.1; the lines alone sum to 196.6


The lines are reserve risk, premium risk and a cat line, each a lognormal joined by a Gaussian copula. The allocations split the TVaR of the total and include the expected loss of each line. Capital in the usual sense is the allocation minus the mean of the line.


``` python
import pandas as pd
from great_tables import GT

rows = []
for method, a in allocs.items():
    rows.append([method, *a.allocated, sum(a.allocated), *[x - m for x, m in zip(a.allocated, means)]])
table = pd.DataFrame(rows, columns=["method", "reserve", "premium", "cat", "sum",
                                    "reserve_above", "premium_above", "cat_above"])
(GT(table, rowname_col="method")
 .tab_header("Allocation of the TVaR 99% of the total", "By method; the right half is the allocation minus the expected loss")
 .tab_spanner("allocated", ["reserve", "premium", "cat", "sum"])
 .tab_spanner("above the mean", ["reserve_above", "premium_above", "cat_above"])
 .cols_label(reserve_above="reserve", premium_above="premium", cat_above="cat")
 .fmt_number(["reserve", "premium", "cat", "sum", "reserve_above", "premium_above", "cat_above"], decimals=1))
```


<style>
#fmnkfzrooi table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#fmnkfzrooi thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#fmnkfzrooi p { margin: 0; padding: 0; }
 #fmnkfzrooi .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #fmnkfzrooi .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #fmnkfzrooi .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #fmnkfzrooi .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #fmnkfzrooi .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fmnkfzrooi .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fmnkfzrooi .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fmnkfzrooi .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #fmnkfzrooi .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #fmnkfzrooi .gt_column_spanner_outer:first-child { padding-left: 0; }
 #fmnkfzrooi .gt_column_spanner_outer:last-child { padding-right: 0; }
 #fmnkfzrooi .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #fmnkfzrooi .gt_spanner_row { border-bottom-style: hidden; }
 #fmnkfzrooi .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #fmnkfzrooi .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #fmnkfzrooi .gt_from_md> :first-child { margin-top: 0; }
 #fmnkfzrooi .gt_from_md> :last-child { margin-bottom: 0; }
 #fmnkfzrooi .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #fmnkfzrooi .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #fmnkfzrooi .gt_indent_1 { text-indent: 5px; }
 #fmnkfzrooi .gt_indent_2 { text-indent: calc(5px * 2); }
 #fmnkfzrooi .gt_indent_3 { text-indent: calc(5px * 3); }
 #fmnkfzrooi .gt_indent_4 { text-indent: calc(5px * 4); }
 #fmnkfzrooi .gt_indent_5 { text-indent: calc(5px * 5); }
 #fmnkfzrooi .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #fmnkfzrooi .gt_row_group_first td { border-top-width: 2px; }
 #fmnkfzrooi .gt_row_group_first th { border-top-width: 2px; }
 #fmnkfzrooi .gt_striped { color: #333333; background-color: #F4F4F4; }
 #fmnkfzrooi .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fmnkfzrooi .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fmnkfzrooi .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #fmnkfzrooi .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fmnkfzrooi .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fmnkfzrooi .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #fmnkfzrooi .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #fmnkfzrooi .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fmnkfzrooi .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fmnkfzrooi .gt_left { text-align: left; }
 #fmnkfzrooi .gt_center { text-align: center; }
 #fmnkfzrooi .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #fmnkfzrooi .gt_font_normal { font-weight: normal; }
 #fmnkfzrooi .gt_font_bold { font-weight: bold; }
 #fmnkfzrooi .gt_font_italic { font-style: italic; }
 #fmnkfzrooi .gt_super { font-size: 65%; }
 #fmnkfzrooi .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fmnkfzrooi .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #fmnkfzrooi .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fmnkfzrooi .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fmnkfzrooi .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #fmnkfzrooi .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="8" id="title" class="gt_heading gt_title gt_font_normal">Allocation of the TVaR 99% of the total</th>
</tr>
<tr class="gt_heading">
<th colspan="8" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">By method; the right half is the allocation minus the expected loss</th>
</tr>
<tr class="gt_col_headings gt_spanner_row">
<th rowspan="2" class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th colspan="4" id="allocated" class="gt_center gt_columns_top_border gt_column_spanner_outer" scope="colgroup">allocated</th>
<th colspan="3" id="above-the-mean" class="gt_center gt_columns_top_border gt_column_spanner_outer" scope="colgroup">above the mean</th>
</tr>
<tr class="gt_col_headings">
<th id="reserve" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">reserve</th>
<th id="premium" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">premium</th>
<th id="cat" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">cat</th>
<th id="sum" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">sum</th>
<th id="reserve_above" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">reserve</th>
<th id="premium_above" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">premium</th>
<th id="cat_above" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">cat</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">euler</th>
<td class="gt_row gt_right" headers="stub-1 allocated reserve">58.6</td>
<td class="gt_row gt_right" headers="stub-1 allocated premium">40.7</td>
<td class="gt_row gt_right" headers="stub-1 allocated cat">59.8</td>
<td class="gt_row gt_right" headers="stub-1 allocated sum">159.1</td>
<td class="gt_row gt_right" headers="stub-1 above-the-mean reserve_above">8.6</td>
<td class="gt_row gt_right" headers="stub-1 above-the-mean premium_above">10.7</td>
<td class="gt_row gt_right" headers="stub-1 above-the-mean cat_above">49.9</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">covariance</th>
<td class="gt_row gt_right" headers="stub-2 allocated reserve">44.8</td>
<td class="gt_row gt_right" headers="stub-2 allocated premium">48.5</td>
<td class="gt_row gt_right" headers="stub-2 allocated cat">65.7</td>
<td class="gt_row gt_right" headers="stub-2 allocated sum">159.1</td>
<td class="gt_row gt_right" headers="stub-2 above-the-mean reserve_above">−5.1</td>
<td class="gt_row gt_right" headers="stub-2 above-the-mean premium_above">18.5</td>
<td class="gt_row gt_right" headers="stub-2 above-the-mean cat_above">55.8</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">marginal</th>
<td class="gt_row gt_right" headers="stub-3 allocated reserve">56.3</td>
<td class="gt_row gt_right" headers="stub-3 allocated premium">38.0</td>
<td class="gt_row gt_right" headers="stub-3 allocated cat">40.4</td>
<td class="gt_row gt_right" headers="stub-3 allocated sum">134.7</td>
<td class="gt_row gt_right" headers="stub-3 above-the-mean reserve_above">6.3</td>
<td class="gt_row gt_right" headers="stub-3 above-the-mean premium_above">8.0</td>
<td class="gt_row gt_right" headers="stub-3 above-the-mean cat_above">30.4</td>
</tr>
</tbody>
</table>


Euler and covariance add to the total but split it differently: covariance gives the stable reserve line less than its mean. Under both, the cat line (expected loss 10) takes most of the capital, because it drives the worst years. The marginal method (the fall of the total without the line) does not add to the total, so it is a diagnostic, not an allocation. The total is much smaller than the lines alone: the diversification benefit.

**Pitfalls.**

- A 99% tail measure from 20,000 simulations uses 200 points, so the allocation to a small line with a heavy tail is noisy. Add simulations until the results are stable.
- A Gaussian copula has no tail dependence. If lines fail together in the worst years, use [StudentTCopula](../reference/risk.StudentTCopula.md#prospicio.risk.StudentTCopula) or [ArchimedeanCopula](../reference/risk.ArchimedeanCopula.md#prospicio.risk.ArchimedeanCopula) (`"gumbel"` joins the large values, `"clayton"` the small ones), or a scenario.
- [capital](../reference/risk.capital.md#prospicio.risk.capital), [price_portfolio](../reference/pricing.price_portfolio.md#prospicio.pricing.price_portfolio) and [allocate](../reference/risk.allocate.md#prospicio.risk.allocate) need components that add to the whole: lines or contracts, not gross, ceded and net together.
- [Tower.apply](../reference/reinsurance.Tower.md#prospicio.reinsurance.Tower.apply) gives a [PredictiveDistribution](../reference/distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution) with all kinds (gross, ceded, net, premiums, commissions). Its total adds them all, so it counts some amounts twice. Take one kind with `select("kind", ["ceded"])` before you join it to a book, as below.
- After [calibrate](../reference/risk.calibrate.md#prospicio.risk.calibrate), read a distortion with the properties `d.family` and `d.parameters` (for example `d.parameters["rho"]` for a proportional hazard).

The double count, and how to prevent it:


``` python
from prospicio.aggregate import simulate_events
from prospicio.distributions import Pareto, Poisson
from prospicio.reinsurance import Layer, Tower

res = Tower([Layer("5x5", 5.0, 5.0)]).apply(simulate_events(Poisson(4.0), Pareto(1.0, 1.8), 2000, 1))
print("components:", res.components())
treaty = res.select("kind", ["ceded"])
print("selected:", treaty.components())
print(f"total of everything {res.total().mean():.2f}; the ceded loss alone {treaty.total().mean():.2f}")
```


    components: [('gross', 'ground_up'), ('ceded', '5x5'), ('net', 'retained')]
    selected: [('ceded', '5x5')]
    total of everything 17.76; the ceded loss alone 0.55


The first total is gross plus ceded plus net, twice the gross loss. Only the second is the treaty, ready to join a book.

**More detail.** [Risk loads and distortions](risk-loads-and-distortions.md).


# 9. Pricing a contract inside an existing portfolio

A reinsurer prices a contract on top of the business that it already has. A contract with losses in other years than the rest of the book needs little additional capital. One with losses in the same years needs much. A portfolio total has a price under a distortion, and **co-measure** allocates it back to the parts by what each contributes in the bad years, so the parts add to the total. This is the **natural allocation**.

**Data you usually have.** The annual loss distribution of the existing book (from the capital model, or made as in sections 2 to 7), the terms and loss model of the new contract, and the capital standard and cost of capital.

| The existing book and the contract are | Method | Call |
|----|----|----|
| Independent, both on grids with the same step | Portfolio from independent units | `Portfolio.from_independent(units, grids)`, then `.price(distortion, p=...)` |
| Dependent, or from simulation | Joint simulation, then price | [PredictiveDistribution](../reference/distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution), [iman_conover](../reference/risk.iman_conover.md#prospicio.risk.iman_conover) or a copula, `price_portfolio(pd, assets, cost_of_capital=r)` |


``` python
import pandas as pd
from great_tables import GT

from prospicio.aggregate import fft
from prospicio.distributions import Grid, Pareto, Poisson
from prospicio.pricing import Portfolio
from prospicio.reinsurance import Layer, Tower
from prospicio.risk import Distortion

STEP, POINTS = 0.1, 2**14
large_losses, _ = Grid.rounding(Pareto(1.0, 1.8), STEP, 201)
contract = Tower([Layer("5x5", 5.0, 5.0, reinstatements=1)]).on_grid(Poisson(4.0), large_losses, POINTS).ceded[0]
rest_of_book, _ = fft(Poisson(3.0), large_losses, POINTS)

ccoc = Distortion.ccoc(0.10)
in_book = Portfolio.from_independent(["book", "contract"], [rest_of_book, contract]).price(ccoc, p=0.99)
alone = Portfolio.from_independent(["contract"], [contract]).price(ccoc, p=0.99).total
units = [(name, unit) for name, unit in zip(in_book.units, in_book.allocated)] + [("contract alone", alone)]
priced = pd.DataFrame([(name, u.loss, u.premium, u.capital, u.assets) for name, u in units],
                      columns=["unit", "loss", "premium", "capital", "assets"])
(GT(priced, rowname_col="unit")
 .tab_header("Pricing the contract", "Natural allocation of the 99% VaR, CCoC 10%")
 .cols_label(loss="expected loss")
 .fmt_number(["loss", "premium", "capital", "assets"], decimals=3))
```


<style>
#gxbhtsaxss table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#gxbhtsaxss thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#gxbhtsaxss p { margin: 0; padding: 0; }
 #gxbhtsaxss .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #gxbhtsaxss .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #gxbhtsaxss .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #gxbhtsaxss .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #gxbhtsaxss .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #gxbhtsaxss .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #gxbhtsaxss .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #gxbhtsaxss .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #gxbhtsaxss .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #gxbhtsaxss .gt_column_spanner_outer:first-child { padding-left: 0; }
 #gxbhtsaxss .gt_column_spanner_outer:last-child { padding-right: 0; }
 #gxbhtsaxss .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #gxbhtsaxss .gt_spanner_row { border-bottom-style: hidden; }
 #gxbhtsaxss .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #gxbhtsaxss .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #gxbhtsaxss .gt_from_md> :first-child { margin-top: 0; }
 #gxbhtsaxss .gt_from_md> :last-child { margin-bottom: 0; }
 #gxbhtsaxss .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #gxbhtsaxss .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #gxbhtsaxss .gt_indent_1 { text-indent: 5px; }
 #gxbhtsaxss .gt_indent_2 { text-indent: calc(5px * 2); }
 #gxbhtsaxss .gt_indent_3 { text-indent: calc(5px * 3); }
 #gxbhtsaxss .gt_indent_4 { text-indent: calc(5px * 4); }
 #gxbhtsaxss .gt_indent_5 { text-indent: calc(5px * 5); }
 #gxbhtsaxss .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #gxbhtsaxss .gt_row_group_first td { border-top-width: 2px; }
 #gxbhtsaxss .gt_row_group_first th { border-top-width: 2px; }
 #gxbhtsaxss .gt_striped { color: #333333; background-color: #F4F4F4; }
 #gxbhtsaxss .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #gxbhtsaxss .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #gxbhtsaxss .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #gxbhtsaxss .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #gxbhtsaxss .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #gxbhtsaxss .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #gxbhtsaxss .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #gxbhtsaxss .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #gxbhtsaxss .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #gxbhtsaxss .gt_left { text-align: left; }
 #gxbhtsaxss .gt_center { text-align: center; }
 #gxbhtsaxss .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #gxbhtsaxss .gt_font_normal { font-weight: normal; }
 #gxbhtsaxss .gt_font_bold { font-weight: bold; }
 #gxbhtsaxss .gt_font_italic { font-style: italic; }
 #gxbhtsaxss .gt_super { font-size: 65%; }
 #gxbhtsaxss .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #gxbhtsaxss .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #gxbhtsaxss .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #gxbhtsaxss .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #gxbhtsaxss .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #gxbhtsaxss .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="5" id="title" class="gt_heading gt_title gt_font_normal">Pricing the contract</th>
</tr>
<tr class="gt_heading">
<th colspan="5" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Natural allocation of the 99% VaR, CCoC 10%</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="loss" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">expected loss</th>
<th id="premium" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">premium</th>
<th id="capital" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">capital</th>
<th id="assets" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">assets</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">book</th>
<td class="gt_row gt_right" headers="stub-1 loss">6.364</td>
<td class="gt_row gt_right" headers="stub-1 premium">8.091</td>
<td class="gt_row gt_right" headers="stub-1 capital">17.266</td>
<td class="gt_row gt_right" headers="stub-1 assets">25.357</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">contract</th>
<td class="gt_row gt_right" headers="stub-2 loss">0.584</td>
<td class="gt_row gt_right" headers="stub-2 premium">0.635</td>
<td class="gt_row gt_right" headers="stub-2 capital">0.508</td>
<td class="gt_row gt_right" headers="stub-2 assets">1.143</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">contract alone</th>
<td class="gt_row gt_right" headers="stub-3 loss">0.565</td>
<td class="gt_row gt_right" headers="stub-3 premium">1.022</td>
<td class="gt_row gt_right" headers="stub-3 capital">4.578</td>
<td class="gt_row gt_right" headers="stub-3 assets">5.600</td>
</tr>
</tbody>
</table>


Both prices use assets at the 99% quantile (VaR) of the total and a 10% cost of capital. In each row, assets are premium plus capital. In the book, the contract is independent of the rest, so the bad years of the rest are not its bad years, and it needs far less capital than alone. Its expected loss alone is a little lower, because limited liability caps the payments at the assets. This is the view of the reinsurer. A cedant sees only the price.

**Pitfalls.**

- Independence is an assumption. Add dependence with a copula or [iman_conover](../reference/risk.iman_conover.md#prospicio.risk.iman_conover) on a [PredictiveDistribution](../reference/distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution) (section 8) and price it with [price_portfolio](../reference/pricing.price_portfolio.md#prospicio.pricing.price_portfolio).
- [Portfolio.from_independent](../reference/pricing.Portfolio.md#prospicio.pricing.Portfolio.from_independent) needs grids with the same step. The same contract costs less in a book that it diversifies.
- The calls give a risk-loaded price (loss plus a margin on allocated capital). `Quote.technical(price, expenses=, brokerage=, fixed=, limit=)` turns a [Price](../reference/pricing.Price.md#prospicio.pricing.Price) into the premium that the cedant pays, with the rate on line, payback, multiple and loss ratio. `Quote.at(premium)` gives the return of the reinsurer at the quoted premium of the broker.
- [Quote.technical](../reference/pricing.Quote.md#prospicio.pricing.Quote.technical) takes a standalone [Price](../reference/pricing.Price.md#prospicio.pricing.Price) from `price(...)` and refuses a unit of the [Portfolio.price](../reference/pricing.Portfolio.md#prospicio.pricing.Portfolio.price) allocation. For a contract priced in the book, calculate (premium + fixed) / (1 - expenses - brokerage) yourself, or price the contract standalone first.

**More detail.** [Risk loads and distortions](risk-loads-and-distortions.md), [What a reinsurance price is](reinsurance-price.md), section 6.


# See also

- [Choosing a method](choosing-a-method.md) (this guide)
- [Risk loads and distortions](risk-loads-and-distortions.md)
- [Experience and exposure rating](experience-and-exposure-rating.md)
- [Aggregate distributions](aggregate-distributions.md)
- [Severity and frequency](severity-and-frequency.md)
- [Reserving methods](reserving-methods.md)
- [What a reinsurance price is](reinsurance-price.md)
- The worked notebooks in [`examples/`](../../examples/README.md), and `knowledge/findings/program-evaluation-api-map.md`, which maps each step of the evaluation of a submission to the Python API.
