Skip to main content

reinsurance.Tower

A reinsurance programme: layers in inuring stages.

Usage

Source

reinsurance.Tower()

Tower(layers) is one stage: every layer sees the gross losses. Tower.inuring(stages) applies stages in order, each seeing the losses net of all earlier stages, event by event.

Parameters

layers: list of Layer
At least one; names must be unique.

Raises

ValueError
If there are no layers or two share a name.

Examples

>>> from prospicio.aggregate import simulate_events
>>> from prospicio.reinsurance import Layer, Tower
>>> from prospicio.distributions import Lognormal, Poisson
>>> events = simulate_events(Poisson(2.0), Lognormal.from_mean_cv(3e6, 1.5), 1_000, 7)
>>> tower = Tower([Layer("5x5", 5e6, 5e6), Layer("15x10", 15e6, 10e6)])
>>> result = tower.apply(events)
>>> [k[0] for k in result.aggregate(["kind"]).components()]

[‘gross’, ‘ceded’, ‘net’]

Attributes

Name Description
cover_basis The cover basis’s name, or None until one is set.
deals Each deal’s name and sections, in the order they were added.
interlocking Whether the tower’s contracts interlock.
layer_names Layer names, in order.
stages Stage of each layer, in order, starting at 0.

cover_basis

The cover basis’s name, or None until one is set.

cover_basis: str | None


deals

Each deal’s name and sections, in the order they were added.

deals: list[tuple[str, list[str]]]


interlocking

Whether the tower’s contracts interlock.

interlocking: bool


layer_names

Layer names, in order.

layer_names: list[str]


stages

Stage of each layer, in order, starting at 0.

stages: list[int]

Methods

Name Description
apply() Applies the tower to every simulated year.
apply_aggregate() Applies the tower to any predictive distribution, each simulation’s
apply_aggregate_term() apply_term on aggregate losses: year t of path j is
apply_annual() Applies the tower to plain annual losses, one per simulation, each
apply_term() Applies the tower over a contract term: years[t] holds year
apply_timeline() apply_term on the contract years a timeline splits into under
ceded() Ceded loss of each layer, in order, for one year’s losses.
ceded_events() Each event’s ceded loss to the named layers, summed over them, as an
deal_ledger() The reinsurer’s P&L ledger of one layer or one deal
deal_ratios() The deal ratios of one layer or one deal (with_deal_scale) in
from_json() A tower whose stages inure in order.
inuring() A tower whose stages inure in order.
on_annual_grid() The tower applied to an annual loss on a grid, each year’s total
on_grid() Gross, ceded and net annual distributions on the grid, by FFT.
to_json() The programme as a versioned JSON document: every stage and layer
with_cover_basis() The tower with its cover basis, which apply_timeline needs:
with_deal_scale() The same tower with a deal’s scales read on the loss ratio of
with_interlocking() The tower with its contracts interlocking or not; off by default.

apply()

Applies the tower to every simulated year.

Usage

Source

apply(events)

The result has dimensions ["kind", "layer"]: ("gross", "ground_up"), ("ceded", name) per layer, ("net", "retained"), then ("reinstatement_premium", name) per layer with paid reinstatements, ("swing_premium", name) per swing-rated layer, ("ceding_commission", name) per layer with a flat or sliding commission and ("profit_commission", name) per layer with a profit commission. aggregate(["kind"]) gives gross, total ceded and net; net is a loss, before premiums and commissions. Take one kind with select("kind", ["ceded"]) before joining it to a book: summing over kind adds gross, ceded and net together.

With labels on the events (EventSet.with_labels) the label dimensions follow kind and layer: gross, each layer’s ceded loss and net come once per combination in events.label_combinations, each the sum over that combination’s events (a layer’s split by event under its allocation), and the other components get "" labels. aggregate(["kind", "layer"]) gives back the unlabelled result.

Parameters
events: EventSet
Returns
PredictiveDistribution

apply_aggregate()

Applies the tower to any predictive distribution, each simulation’s

Usage

Source

apply_aggregate(losses)

total taken as one aggregate loss: an adverse development cover on a reserve bootstrap, a stop-loss or quota share on modelled premium risk. An occurrence layer sees the total as one occurrence, so it acts as an aggregate excess of loss. Components as apply.

Parameters
losses: PredictiveDistribution
Returns
PredictiveDistribution

apply_aggregate_term()

apply_term on aggregate losses: year t of path j is

Usage

Source

apply_aggregate_term(years)

simulation j’s total of years[t], as in apply_aggregate.

Parameters
years: list of PredictiveDistribution
Returns
PredictiveDistribution

apply_annual()

Applies the tower to plain annual losses, one per simulation, each

Usage

Source

apply_annual(losses)

taken as one aggregate loss as in apply_aggregate, with no EventSet or PredictiveDistribution to build. A contract stated on the loss ratio is a layer on money amounts: a loss-ratio cap c on subject premium P is Layer.stop_loss(name, c * P, 0.0).with_premium_rate(1.0, P), so the ceded loss ratio is the capped one, and a sliding scale keyed on it is with_sliding_scale. To key the scales on the loss ratio before the cap, state the cap as aggregate_limit and use with_scales_before_annual_terms. A deal of several sections is one layer per section, each scale reading its own section’s loss ratio, and the amounts add; Layer.ceding_commission_for evaluates a scale at any ceded loss. Components as apply.

Parameters
losses: Sequence[float]
Each simulation’s annual loss, finite and non-negative.
Returns
PredictiveDistribution
Raises
ValueError
For no losses, a negative or non-finite loss, a surplus treaty or reinstatements pro rata as to time.
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> cover = (Layer.stop_loss("cover", 120.0, 0.0)
...          .with_premium_rate(1.0, 100.0)
...          .with_sliding_scale([(0.3, 0.5), (0.1, 0.9)]))
>>> res = Tower([cover]).apply_annual([40.0, 70.0, 150.0])
>>> list(res.marginal(["ceded", "cover"]).draws)

[40.0, 70.0, 120.0]

>>> [round(x, 12) for x in res.marginal(["ceding_commission", "cover"]).draws]

[30.0, 20.0, 10.0]


apply_term()

Applies the tower over a contract term: years[t] holds year

Usage

Source

apply_term(years)

t + 1’s simulated losses, and simulation j of every year belongs to the same path.

The result has dimensions ["kind", "layer", "year"]: each of apply’s components once per year, keyed by the year 1..T. Each year’s ceded and net loss and premiums are what apply gives for that year alone; a profit commission or sliding scale that carries deficits or credits forward reads what the path’s earlier years left. EventSet.term_years splits one simulation into the years of a term.

Parameters
years: list of EventSet
One per year, each with the same number of simulations.
Returns
PredictiveDistribution
Examples
>>> from prospicio.aggregate import EventSet
>>> from prospicio.reinsurance import Layer, Tower
>>> qs = (Layer.quota_share("QS", 1.0).with_premium_rate(1.0, 100.0)
...       .with_profit_commission(0.25, 0.1)
...       .with_profit_commission_carry_forward())
>>> years = [EventSet.from_years([[120.0], [40.0]]), EventSet.from_years([[40.0], [40.0]])]
>>> term = Tower([qs]).apply_term(years)
>>> term.select("year", [2]).select("kind", ["profit_commission"]).mean()

8.75


apply_timeline()

apply_term on the contract years a timeline splits into under

Usage

Source

apply_timeline(timeline, exposure)

the tower’s cover basis (with_cover_basis; an error without one).

Parameters
timeline: Timeline
exposure: Exposure
Each underwriting year’s share of each accident month; under losses occurring only its number of years is used.
Returns
PredictiveDistribution
Examples
>>> from prospicio.aggregate import EventSet, Exposure, Timeline
>>> from prospicio.reinsurance import Layer, Tower
>>> events = EventSet.from_years([[100.0]], times=[[13.5 / 24]])
>>> timeline = Timeline(events, 24)
>>> shares = [[0.0] * 24, [0.0] * 24]
>>> shares[0][13], shares[1][13] = 0.25, 0.75
>>> tower = Tower([Layer("XL", 50.0, 20.0)]).with_cover_basis("risks_attaching")
>>> rad = tower.apply_timeline(timeline, Exposure(shares))
>>> [rad.select("year", [y]).select("kind", ["ceded"]).mean() for y in (1, 2)]

[5.0, 50.0]


ceded()

Ceded loss of each layer, in order, for one year’s losses.

Usage

Source

ceded(losses)
Parameters
losses: list of float
Returns
list of float

ceded_events()

Each event’s ceded loss to the named layers, summed over them, as an

Usage

Source

ceded_events(events, layers)

event set: the input to an occurrence retro on a reinsurer’s own cessions.

Each layer’s split by event is the one apply‘s labels use (Layer.ceded_by_event: after the layer’s annual terms, at its share, behind any earlier inuring stage), so in every year the set’s losses add to the layers’ ceded total. The events keep their times and labels; events that cede nothing are left out, sums insured are dropped, and a named layer that sees the aggregate part passes its ceded part on as the set’s aggregate part. Join several deals’ sets with EventSet.merge, and group one event’s cessions into one occurrence with EventSet.grouped.

Parameters
events: EventSet
layers: str or list of str
Layer names of this tower.
Returns
EventSet
Examples
>>> from prospicio.aggregate import EventSet
>>> from prospicio.reinsurance import Layer, Tower
>>> e = EventSet.from_years([[20.0, 8.0, 15.0], [4.0]])
>>> t = Tower([Layer("10x5", 10.0, 5.0, aggregate_limit=15.0)])
>>> c = t.ceded_events(e, "10x5")
>>> c.events(0), c.events(1)

([10.0, 3.0, 2.0], [])


deal_ledger()

The reinsurer’s P&L ledger of one layer or one deal

Usage

Source

deal_ledger(source, layer)

(with_deal_scale()) over the annual gross losses source: one group that sells the cover, named layer, with the premium received against the ceded loss, the commissions paid, the brokerage and each deduction, every leg at each atom of the source.

The tower is applied to each atom as one annual loss (apply_annual()), so the amounts are those deal_ratios() divides by the premium. A deal books its sections’ amounts with its own. prospicio.aggregate.Book.ledger() books the same tower as covers bought and leaves brokerage and deductions out.

The rows are Premium, Loss, Ceding commission, Profit commission, Brokerage and each deduction by its label, as the layer has them. NMBF is not a row: deal_ratios() gives it.

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

The annual gross loss.

layer: str
A layer or a deal.
Returns
prospicio.aggregate.Ledger
Raises
ValueError
A joint source, a layer that cannot apply to an annual loss, a booked layer with paid reinstatements, or an unknown layer or deal.
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> cover = (Layer.stop_loss("cover", 120.0, 0.0)
...          .with_premium_rate(1.0, 100.0)
...          .with_ceding_commission(0.2)
...          .with_brokerage(0.025)
...          .with_deduction("tax", 0.03))
>>> ledger = Tower([cover]).deal_ledger(([40.0, 150.0], [0.5, 0.5]), "cover")
>>> ledger.result.values

[-45.5, 34.5]


deal_ratios()

The deal ratios of one layer or one deal (with_deal_scale) in

Usage

Source

deal_ratios(result, layer)

each simulation of a result of this tower (apply, apply_aggregate, apply_annual or apply_term).

Every amount is over the year’s premium for the placed share (the fixed or the swing-rated premium; reinstatement premiums are not in it). With d the deductions: total_deductions = CC + PC + BK + sum(d), combined_ratio = loss_ratio + total_deductions, margin = 1 - combined_ratio and nmbf = margin plus the deductions kept outside it. For a deal, every amount is summed over its sections with the deal’s own commission and brokerage added, over the sections’ premium together; a section’s own ratios leave the deal’s scales out.

Parameters
result: PredictiveDistribution

A result of this tower.

layer: str
The layer’s or the deal’s name.
Returns
PredictiveDistribution
Dimension ["ratio"] (["ratio", "year"] for a term): loss_ratio, loss_ratio_before_terms for a layer whose scales read it, ceding_commission, profit_commission and brokerage where the layer has them, each deduction by its label, total_deductions, combined_ratio, nmbf and margin.
Raises
ValueError
For an unknown layer or deal, a result that is not this tower’s, or a premium that is not positive.
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> cover = (Layer.stop_loss("cover", 120.0, 0.0)
...          .with_premium_rate(1.0, 100.0)
...          .with_sliding_scale([(0.3, 0.5), (0.1, 0.9)])
...          .with_brokerage(0.025)
...          .with_deduction("tax", 0.03)
...          .with_deduction("manager_fee", 0.05, inside_nmbf=False))
>>> tower = Tower([cover])
>>> r = tower.deal_ratios(tower.apply_annual([40.0, 70.0, 150.0]), "cover")
>>> [round(r.marginal([k]).draws[1], 12) for k in ["combined_ratio", "margin", "nmbf"]]

[1.005, -0.005, 0.045]


from_json()

A tower whose stages inure in order.

Usage

Source

from_json(text)

Each stage’s layers see the losses net of all earlier stages, event by event, with annual terms used up in event order.

Parameters
stages: list of list of Layer
No stage may be empty; names must be unique across stages.
Returns
Tower
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> tower = Tower.inuring([[Layer.quota_share("QS", 0.5)], [Layer("5x5", 5.0, 5.0)]])
>>> tower.ceded([30.0])

[15.0, 5.0] Reads a document written by Tower.to_json.

Parameters
text: str
Returns
Tower
Raises
ValueError
On malformed JSON, another format, a newer format version, or a term a layer refuses.

inuring()

A tower whose stages inure in order.

Usage

Source

inuring(stages)

Each stage’s layers see the losses net of all earlier stages, event by event, with annual terms used up in event order.

Parameters
stages: list of list of Layer
No stage may be empty; names must be unique across stages.
Returns
Tower
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> tower = Tower.inuring([[Layer.quota_share("QS", 0.5)], [Layer("5x5", 5.0, 5.0)]])
>>> tower.ceded([30.0])

[15.0, 5.0]


on_annual_grid()

The tower applied to an annual loss on a grid, each year’s total

Usage

Source

on_annual_grid(annual)

treated as one loss (as apply_aggregate does for draws): a quota share or stop-loss on a loss-ratio or annual-loss distribution, with its expected sliding-scale and profit commission. Inuring stages and annual terms are all allowed, and the net always exists.

Parameters
annual: Grid
The annual loss.
Returns
AnnualGrids
Raises
ValueError
For a surplus treaty or reinstatements pro rata as to time, which need risks or event times.
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> from prospicio.distributions import Grid
>>> probs = [0.0] * 81
>>> for k in (50, 60, 70, 80):
...     probs[k] = 0.25
>>> qs = Layer.quota_share("QS", 0.4).with_deposit_premium(100.0).with_ceding_commission(0.3)
>>> r = Tower([qs]).on_annual_grid(Grid(1.0, probs))
>>> round(r.ceded[0].mean(), 12), round(r.expected_ceding_commission[0], 12)

(26.0, 12.0)


on_grid()

Gross, ceded and net annual distributions on the grid, by FFT.

Usage

Source

on_grid(frequency, severity, points)

Each layer’s per-occurrence recoveries form a severity grid, which is compounded with the same claim count; annual terms and the share then apply to the total. With boundaries on multiples of the step the grids are exact for the discretized problem, with no sampling error. Grids are marginal (use apply on simulated events for joint results). net is given when no layer has annual terms, or when the last stage is a single aggregate cover such as a stop-loss; otherwise it is None.

Parameters
frequency: (Poisson, NegativeBinomial or Binomial)
severity: Grid
points: int
Points in every aggregate grid.
Returns
TowerGrids
Raises
ValueError
If a layer with annual terms inures to a later stage, or points is 0.
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> from prospicio.distributions import Grid, Poisson
>>> sev = Grid(1.0, [0.0, 0.4, 0.3, 0.2, 0.1])
>>> r = Tower([Layer("2x2", 2.0, 2.0)]).on_grid(Poisson(3.0), sev, 200)
>>> round(r.ceded[0].mean(), 12), r.on_points

(1.2, True)


to_json()

The programme as a versioned JSON document: every stage and layer

Usage

Source

to_json()

with all its terms, numbers bit for bit. Tower.from_json reads it back to an equal tower, rebuilding each layer through the same checks; towers also pickle this way.

Returns
str
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> tower = Tower.inuring([[Layer.surplus("S", 1e6, 4.0)], [Layer("xl", 2e6, 1e6)]])
>>> back = Tower.from_json(tower.to_json())
>>> back.to_json() == tower.to_json()

True


with_cover_basis()

The tower with its cover basis, which apply_timeline needs:

Usage

Source

with_cover_basis(basis)

"losses_occurring" (contract years by accident period) or "risks_attaching" (by underwriting period). A tower is one programme, so the basis is one for all its layers.

Parameters
basis: (losses_occurring, risks_attaching) = "losses_occurring"
Returns
Tower

with_deal_scale()

The same tower with a deal’s scales read on the loss ratio of

Usage

Source

with_deal_scale(
    name,
    sections,
    sliding_scale=None,
    brokerage=None,
    brokerage_scale=None,
    carry_deficit=False,
    carry_credit=False,
    carry_years=None,
    brokerage_within_commission_range=False
)

several layers together.

The deal’s commission and brokerage read the sum of its sections’ keys (each section’s ceded loss, or its loss before annual terms with with_scales_before_annual_terms) over the sum of their premiums, are paid on that summed premium, and add to whatever each section pays on its own. Results gain ("ceding_commission", name), ("brokerage", name) and, when a section reads its scales before annual terms, ("loss_before_terms", name); deal_ratios takes the deal’s name. on_annual_grid gives each deal’s expected commission and brokerage, on_grid too when no section has annual terms, and the cedant’s P&L ledger books the deal’s commission.

Parameters
name: str

Not a layer’s or another deal’s name.

sections: list of str

At least two layers, each with a positive fixed premium (no swing rating or paid reinstatements) and in no other deal.

sliding_scale: list of (float, float) = None

(commission, loss_ratio) anchors; the commission must not rise with the loss ratio.

brokerage: float = None

A flat brokerage rate on the deal’s premium.

brokerage_scale: list of (float, float) = None

(rate, loss_ratio) anchors instead of a flat rate.

carry_deficit: bool = False

Carry the deal commission’s deficits or credits between the years of a term, on the deal’s key.

carry_credit: bool = False

Carry the deal commission’s deficits or credits between the years of a term, on the deal’s key.

carry_years: int = None

How many later years a carried amount lasts; None without limit.

brokerage_within_commission_range: bool = False
Hold the brokerage key inside the deal commission’s range.
Returns
Tower
Raises
ValueError
For a deal with no scale, a taken name, an unknown, repeated or unpriced section, or a section of another deal.
Examples
>>> from prospicio.reinsurance import Layer, Tower
>>> a = Layer.stop_loss("A", 50.0, 0.0).with_premium_rate(1.0, 100.0)
>>> b = Layer.stop_loss("B", float("inf"), 50.0).with_premium_rate(1.0, 100.0)
>>> tower = Tower([a, b]).with_deal_scale(
...     "deal", ["A", "B"], sliding_scale=[(0.35, 0.5), (0.15, 0.9)])
>>> result = tower.apply_annual([160.0])
>>> round(result.marginal(["ceding_commission", "deal"]).draws[0], 12)

40.0


with_interlocking()

The tower with its contracts interlocking or not; off by default.

Usage

Source

with_interlocking(on=True)

Under risks attaching an event that several underwriting years write falls to each by its share. With interlocking each contract’s limit is cut, for that event, by the year’s share of the event’s loss across the programme’s underwriting years in the term; the retention is not cut, and each year’s annual terms apply to its recoveries. Under losses occurring it changes nothing.

Parameters
on: bool = True
Returns
Tower
Examples
>>> from prospicio.aggregate import EventSet, Exposure, Timeline
>>> from prospicio.reinsurance import Layer, Tower
>>> events = EventSet.from_years([[100.0]], times=[[13.5 / 24]])
>>> shares = [[0.0] * 24, [0.0] * 24]
>>> shares[0][13], shares[1][13] = 0.25, 0.75
>>> tower = (Tower([Layer("XL", 50.0, 20.0)]).with_cover_basis("risks_attaching")
...          .with_interlocking())
>>> rad = tower.apply_timeline(Timeline(events, 24), Exposure(shares))
>>> [rad.select("year", [y]).select("kind", ["ceded"]).mean() for y in (1, 2)]

[5.0, 37.5]