Skip to main content

Pricing reinsurance with prospicio, beside aggregate

This notebook prices six reinsurance contracts with prospicio. It puts each result beside the value that Stephen Mildenhall’s Python package aggregate (1.0.1) gives for the same contract. The reader is a reinsurance pricing actuary who knows aggregate. Each section states the contract and the DecL line that builds it in aggregate. Then it shows the prospicio code, prints the result and compares it with the result of aggregate.

Section Contract Source in aggregate’s examples
1 A gross book and a five-layer occurrence tower Reinsurance Functions (ReTester)
2 Ceded and net of a two-layer program, and an 80% share net of and po clauses
3 An annual aggregate limit, then paid reinstatements Bear and Nemlick Treaty 2
4 Aggregate stop loss, and an aggregate deductible ReTester stop loss, Treaty 1
5 Retro and swing premium, profit commission, sliding scale Treaties 4, 5 and 6
6 Risk-adjusted premium (loss plus cost of capital) with distortions calibrate_distortions

To run the notebook:

  1. Clone the repository.
  2. Install the released package with pip install prospicio matplotlib jupyter (or uv pip install). PyPI has prebuilt wheels, so you do not need a Rust toolchain.
  3. Open this notebook from any folder in the repository.

To run it on unreleased changes, build from source with cd python && maturin develop, which needs Rust. The notebook does not need aggregate. The reference values are in validation/reference/re_pricing_aggregate.csv, which validation/scripts/aggregate_re_pricing.py writes with aggregate 1.0.1. The notebook does not simulate, so it has no simulation count.

Same grid. Both packages round the severity to buckets of size bs and put the mass above a policy limit on the limit. Both compound with an FFT on 2**16 points and do not normalise (aggregate’s normalize=False). Where a comparison depends on the grid, prospicio gets the bucket size that aggregate used. Thus the contract terms act on the same discretized severity in both packages. A layer boundary on a grid point is exact, and a boundary between grid points splits linearly between the two adjacent buckets. So the means agree far inside the tolerances below.

Tolerances. We set them after a first run, from the differences that the last section explains. The summary at the end prints the worst difference in each class beside its tolerance.

Quantity Tolerance Reason
Means, probabilities, premiums, commissions, prices 1e-6 relative Same grid
Standard deviation and CV 1e-6 relative Same grid
Standard deviation and CV of a share placed off the grid (sections 2 and 4) 1e-5 relative aggregate re-buckets the ceded amounts
Skewness, against the skewness of aggregate’s density 2e-5 relative FFT rounding noise at the top of the grid enters the third moment (last section)
Quantiles The same grid point A quantile is a point of the shared grid, and at none of those compared is the cdf within 6.7e-8 of a tie
Quantiles of a share placed off the grid Within one bucket aggregate re-buckets the ceded amounts
A stop loss far in the tail (the loss above 2,800 in section 3) 1e-5 relative prospicio lumps the cut tail on the last point

Some rows hold by construction, not by agreement. The summary marks them * as consistency checks and counts them apart from the independent comparisons:

import csv
import math
from pathlib import Path
from statistics import NormalDist

from prospicio.aggregate import fft, recommend_grid
from prospicio.distributions import Burr, Grid, Lognormal, Mixture, Poisson, claim_count
from prospicio.reinsurance import Layer, LossSensitivePremium, Tower
from prospicio.risk import Distortion, calibrate

POINTS = 2**16  # aggregate's log2 = 16 in every example

# The repository's reference folder, from wherever the notebook runs inside the repository.
REFERENCE = next((p / "validation" / "reference" for p in [Path.cwd(), *Path.cwd().parents]
                  if (p / "validation" / "reference").is_dir()), None)
if REFERENCE is None:
    raise FileNotFoundError(
        f"validation/reference not found in {Path.cwd()} or above it: this notebook reads aggregate's numbers "
        "from the repository, so open it from inside a clone of the repository")
with open(REFERENCE / "re_pricing_aggregate.csv") as f:
    AGG = {(r["example"], r["quantity"]): float(r["value"]) for r in csv.DictReader(f)}
print(f"{len(AGG)} reference values from aggregate 1.0.1 in {REFERENCE.parent.name}/{REFERENCE.name}/re_pricing_aggregate.csv")


def money(x):
    return f"{x:,.2f}"


def moments(grid):
    # Mean, standard deviation, CV and skewness of a Grid. Grid has no skewness method,
    # so the third central moment is the one statistic summed here by hand.
    h, p = grid.step, grid.probs
    mean, sd = grid.mean(), math.sqrt(grid.variance())
    m3 = sum((i * h - mean) ** 3 * q for i, q in enumerate(p))
    return mean, sd, sd / mean, m3 / sd**3


def prob_at_least(grid, x):
    # P(X >= x) on a grid whose points may not include x: the cdf half a step below x.
    return 1.0 - grid.cdf(x - grid.step / 2)


def discretize(severity, bs, limit):
    # Round the severity to buckets of size bs, with the policy limit as the last point.
    # Grid.rounding puts all mass beyond its last point there: aggregate's `limit xs 0`.
    grid, _ = Grid.rounding(severity, bs, round(limit / bs) + 1)
    return grid


def mixed_poisson(n, mixing_cv):
    # Gamma-mixed Poisson (aggregate's `mixed gamma cv`): a negative binomial with Var/E = 1 + cv^2 n.
    return claim_count(n, 1 + mixing_cv**2 * n)


def exposure_book(subject, rate, shapes, scale, limit):
    # aggregate's `exposure at rate`, severity `scale * pareto shape - scale` (a Lomax) limited to `limit`.
    # The expected loss of class i is subject * rate; its claim count is solved from it.
    # All classes share one mixing variable, so they are one mixed Poisson over a severity mixture.
    lomax = [Burr(a, 1.0, scale) for a in shapes]
    counts = [s * r / v.lev(limit) for s, r, v in zip(subject, rate, lomax)]
    n = sum(counts)
    return counts, n, Mixture([(c / n, v) for c, v in zip(counts, lomax)])


# Tolerance by class, as (tolerance, unit); see the table above.
TOLERANCES = {
    "mean": (1e-6, "rel"),  # means, probabilities, premiums, commissions, prices
    "sd": (1e-6, "rel"),  # standard deviation and CV
    "share sd": (1e-5, "rel"),  # the same for a share placed off the grid
    "skew": (2e-5, "rel"),  # against the skewness of aggregate's density
    "quantile": (0, "buckets"),  # the same grid point
    "share quantile": (1, "buckets"),  # a share placed off the grid
    "tail": (1e-5, "rel"),  # a stop loss far in the tail
}

COMPARISONS = []  # every comparison, for the summary at the end
SHOWN = []  # those to print at the next report()


def _record(section, name, agg, pro, diff, cls, show, check):
    tol, unit = TOLERANCES[cls]
    row = dict(section=section, name=name, aggregate=agg, prospicio=pro, diff=diff, cls=cls,
               unit=unit, tol=tol, ok=bool(diff <= tol), check=check)
    COMPARISONS.append(row)
    if show:
        SHOWN.append(row)


def compare(section, name, example, quantity, value, cls="mean", show=True, check=False):
    # Relative difference from aggregate's number, which the CSV holds under (example, quantity).
    # check=True marks a consistency check: a row that holds by construction, not by agreement.
    agg = AGG[(example, quantity)]
    diff = abs(value - agg) / abs(agg) if agg else abs(value)
    _record(section, name, agg, value, diff, cls, show, check)


def compare_quantile(section, name, example, quantity, value, bs, cls="quantile", show=True):
    # Difference of a quantile in buckets.
    agg = AGG[(example, quantity)]
    _record(section, name, agg, value, abs(value - agg) / bs, cls, show, False)


def compare_distribution(section, name, example, prefix, grid, bs, share=False,
                         shown=("mean", "sd", "cv", "skew", "q0.5", "q0.9", "q0.99", "q0.999")):
    # share=True: a share placed off the grid, which aggregate re-buckets.
    # Skewness is compared with the skewness of aggregate's density (`_skew_central`); the skew
    # aggregate quotes (`_skew`) also counts the density's rounding deficit (see the last section).
    mean, sd, cv, skew = moments(grid)
    sd_cls = "share sd" if share else "sd"
    for stat, quantity, value, cls in [("mean", "mean", mean, "mean"), ("sd", "sd", sd, sd_cls),
                                       ("cv", "cv", cv, sd_cls), ("skew", "skew_central", skew, "skew")]:
        compare(section, f"{name} {stat}", example, f"{prefix}_{quantity}", value, cls, stat in shown)
    for p in (0.5, 0.9, 0.99, 0.999):
        compare_quantile(section, f"{name} q{p}", example, f"{prefix}_q{p}", grid.quantile(p), bs,
                         "share quantile" if share else "quantile", f"q{p}" in shown)


def report():
    # Print the comparisons made since the last report; * marks a consistency check.
    print(f"{'quantity':40s} {'aggregate':>14s} {'prospicio':>14s} {'difference':>12s}  pass")
    for r in SHOWN:
        diff = f"{r['diff']:.1e}" if r["unit"] == "rel" else f"{r['diff']:.2f} bkt"
        name = r["name"] + (" *" if r["check"] else "")
        print(f"{name:40s} {r['aggregate']:14.8g} {r['prospicio']:14.8g} {diff:>12s}  "
              f"{'yes' if r['ok'] else 'NO'}")
    SHOWN.clear()
544 reference values from aggregate 1.0.1 in validation/reference/re_pricing_aggregate.csv

1. A gross book and an occurrence tower

The contract. A book of ground-up claims with a Poisson count of 10 claims a year. Each claim is lognormal with mean 100 and CV 5, and the policy limits it to 5,000. A tower of five layers, each at 100% and per occurrence, with no annual terms. The layers are 250 xs 0, 250 xs 250, 500 xs 500, 1,000 xs 1,000 and 3,000 xs 2,000. The tower covers the full policy limit, so the layers add to the gross loss.

In aggregate this is

agg Re.T 10 claims 5000 xs 0 sev lognorm 100 cv 5
    occurrence ceded to 250 xs 0 and 250 xs 250 and 500 xs 500 and 1000 xs 1000 and 3000 xs 2000 poisson

with normalize=False. aggregate picks the bucket bs = 4. The bucket does not divide 250, where 250 xs 0 detaches and 250 xs 250 attaches. Thus both packages split those two layers linearly between the two adjacent buckets. The split keeps each layer consistent with the discretized severity, so the five layers still add to the gross loss on the grid. The other boundaries (500, 1,000, 2,000 and 5,000) are grid points.

In prospicio. discretize rounds the severity to the grid. fft compounds it into the gross annual loss. Tower.on_grid gives the annual ceded loss of each layer from the same severity grid and claim count.

S1 = "1 tower"
BS1 = 4.0
claims = Poisson(10.0)
severity = Lognormal.from_mean_cv(100.0, 5.0)
sev_grid = discretize(severity, BS1, 5000.0)
gross, gross_report = fft(claims, sev_grid, POINTS)

print(f"mean claim: exact {severity.lev(5000.0):.4f}, on the grid {sev_grid.mean():.4f}")
print(f"annual gross: exact {10 * severity.lev(5000.0):.4f}, on the grid {gross.mean():.4f}")
size = recommend_grid(claims, severity)
print(f"recommend_grid on the unlimited lognormal: step {size.step:g}; aggregate, which sees the 5,000 limit, "
      f"used {AGG[('tower_gross', 'bs')]:g}")
print(f"aliasing error {gross_report.aliasing_error:.1e}, mass beyond the grid {gross_report.tail_mass:.1e}")

compare(S1, "mean claim, exact", "tower_gross", "sev_mean_exact", severity.lev(5000.0))
compare(S1, "mean claim, grid", "tower_gross", "sev_mean_grid", sev_grid.mean())
compare(S1, "annual gross mean, exact", "tower_gross", "gross_mean_exact", 10 * severity.lev(5000.0))
compare_distribution(S1, "gross", "tower_gross", "gross", gross, BS1)
report()
mean claim: exact 95.0575, on the grid 95.0161
annual gross: exact 950.5755, on the grid 950.1608
recommend_grid on the unlimited lognormal: step 2; aggregate, which sees the 5,000 limit, used 4
aliasing error 8.7e-19, mass beyond the grid 5.4e-15
quantity                                      aggregate      prospicio   difference  pass
mean claim, exact                             95.057547      95.057547      2.2e-15  yes
mean claim, grid                              95.016081      95.016081      2.2e-15  yes
annual gross mean, exact                      950.57547      950.57547      2.2e-15  yes
gross mean                                    950.16081      950.16081      3.0e-12  yes
gross sd                                      1016.6156      1016.6156      2.2e-10  yes
gross cv                                      1.0699406      1.0699406      2.2e-10  yes
gross skew                                    2.8645302      2.8645303      3.5e-08  yes
gross q0.5                                          632            632     0.00 bkt  yes
gross q0.9                                         2024           2024     0.00 bkt  yes
gross q0.99                                        5440           5440     0.00 bkt  yes
gross q0.999                                       7412           7412     0.00 bkt  yes

The gross loss agrees with aggregate to rounding. The mean on the grid (950.16) is 0.044% below the exact mean (950.58) because rounding to buckets of 4 moves each claim a small amount. aggregate has the same difference, so the table compares grid with grid. The exact row checks the closed form (LEV) on both sides.

Choosing the bucket. Each section gives the bucket by hand only to match the grids of aggregate. In your own work, use fft_auto: it calls recommend_grid and compounds on the grid that it picks. These two functions get the unlimited lognormal, not the policy limit. On this book they pick 2 where aggregate, which sees the 5,000 limit, picks 4. The finer step is safer. Its discretisation moves the grid values away from the values of aggregate.

Now the tower. TOWER lists limit and attachment. tower_grids.ceded holds the annual ceded distribution of each layer.

TOWER = [(250.0, 0.0), (250.0, 250.0), (500.0, 500.0), (1000.0, 1000.0), (3000.0, 2000.0)]
tower = Tower([Layer(f"{lim:g} xs {att:g}", lim, att) for lim, att in TOWER])
tower_grids = tower.on_grid(claims, sev_grid, POINTS)

print(f"{'layer':>13s} {'mean':>9s} {'cv':>7s} {'loss on line':>13s} {'P(claim reaches)':>17s} "
      f"{'mean | reaches':>15s}")
for (lim, att), layer_grid in zip(TOWER, tower_grids.ceded):
    name = f"{lim:g} xs {att:g}"
    tag = f"layer_{lim:g}x{att:g}"  # the reference file's name
    ex = "tower_gross"
    compare_distribution(S1, f"layer {name}", ex, f"{tag}_ceded", layer_grid, BS1, shown=("mean",))
    compare(S1, f"layer {name} mean, exact", ex, f"{tag}_ceded_mean_exact", 10 * severity.layer(lim, att),
            show=False)
    reaches = 1.0 - sev_grid.cdf(att)
    cond = sev_grid.layer(lim, att) / reaches
    compare(S1, f"layer {name} loss on line", ex, f"{tag}_loss_on_line", layer_grid.mean() / lim, show=False)
    compare(S1, f"layer {name} P(claim reaches layer)", ex, f"{tag}_pr_attach_grid", reaches, show=False)
    compare(S1, f"layer {name} P(claim exhausts layer)", ex, f"{tag}_pr_detach_grid",
            prob_at_least(sev_grid, att + lim), show=False)
    compare(S1, f"layer {name} mean given it reaches", ex, f"{tag}_cond_sev_mean", cond, show=False)
    print(f"{name:>13s} {layer_grid.mean():9.3f} {moments(layer_grid)[2]:7.3f} {layer_grid.mean() / lim:13.4f} "
          f"{reaches:17.4f} {cond:15.3f}")

print(f"claims below half a bucket, which round to 0: {severity.cdf(BS1 / 2):.4f}; exact mean claim in 250 xs 0: "
      f"{severity.layer(250.0, 0.0):.3f}")
total = sum(c.mean() for c in tower_grids.ceded)
compare(S1, "sum of layers equals gross", "tower_gross", "tower_ceded_total_mean", total)
print(f"layers add up to {total:.4f}, gross is {gross.mean():.4f}; on grid points: {tower_grids.on_points}")
report()
        layer      mean      cv  loss on line  P(claim reaches)  mean | reaches
     250 xs 0   544.170   0.538        2.1767            0.8970          60.664


   250 xs 250   133.053   1.279        0.5322            0.0792         167.893
   500 xs 500   114.811   1.924        0.2296            0.0362         317.000


 1000 xs 1000    87.092   3.084        0.0871            0.0147         594.252
 3000 xs 2000    71.035   5.599        0.0237            0.0052        1367.998
claims below half a bucket, which round to 0: 0.1030; exact mean claim in 250 xs 0: 54.459
layers add up to 950.1608, gross is 950.1608; on grid points: False
quantity                                      aggregate      prospicio   difference  pass
layer 250 xs 0 mean                           544.16971      544.16971      2.1e-16  yes
layer 250 xs 250 mean                         133.05295      133.05295      1.3e-12  yes
layer 500 xs 500 mean                         114.81139      114.81139      3.3e-12  yes
layer 1000 xs 1000 mean                       87.091755      87.091755      4.1e-15  yes
layer 3000 xs 2000 mean                       71.035004      71.035004      1.5e-11  yes
sum of layers equals gross                    950.16081      950.16081      2.3e-12  yes

For each layer, the mean, standard deviation, skewness, quantiles, loss on line, attachment and exhaustion probabilities and conditional severity match aggregate’s single-layer builds. The table above shows the means, and the summary at the end shows the others. The “mean | reaches” column is conditional on the claim reaching the layer, as in aggregate’s reins_stats_df. The loss on line is the unconditional annual mean divided by the limit.

The first row shows that a tenth of the claims do not reach a layer that attaches at 0. The grid causes this: the lognormal puts 10.3% of claims below 2, half a bucket, and rounding moves them to 0, where they cede nothing. The 60.7 in the last column is therefore the mean over the 89.7% of claims that survive rounding; over all claims the exact mean claim in the layer is 54.5. aggregate reports the same 89.7% and 60.7.

Tower.on_grid says on_points is False because the bucket of 4 does not divide 250. The layers still agree with aggregate, which splits them the same way. The flag warns that the split smears the shape of those two layers by up to a bucket. The split does not change their means.

2. Ceded and net of a program, and a share

The contract. The same book, with a program of two layers: 500 xs 500 and 1,000 xs 1,000, both at 100% and per occurrence. The reinsurer pays the loss in those layers, and the cedant keeps the remainder. A second placement is an 80% share of 1,000 xs 1,000.

In aggregate:

agg Re.T 10 claims 5000 xs 0 sev lognorm 100 cv 5 occurrence net of 500 xs 500 and 1000 xs 1000 poisson
agg Re.T 10 claims 5000 xs 0 sev lognorm 100 cv 5 occurrence ceded to 80% po 1000 xs 1000 poisson

In prospicio. Tower.on_grid gives the net annual loss and the ceded loss of each layer. The two layers are contiguous. Thus the annual loss ceded to the program equals that of the single layer 1,500 xs 500, which Tower.on_grid also gives. For a program with a gap, map the severity grid through the layers and compound it. The cell does this too and checks that the two results agree.

The share is Layer(share=0.8). Its ceded grid has the step 0.8 * 4 = 3.2, so the share adds no rounding (the severity is still rounded to 4). aggregate re-buckets the share onto the grid of 4.

S2 = "2 program"
PROGRAM = [(500.0, 500.0), (1000.0, 1000.0)]
program = Tower([Layer(f"{lim:g} xs {att:g}", lim, att) for lim, att in PROGRAM])
program_grids = program.on_grid(claims, sev_grid, POINTS)
net = program_grids.net

# The two layers are contiguous, so the whole program is the single layer 1,500 xs 500.
program_ceded = Tower([Layer("1500 xs 500", 1500.0, 500.0)]).on_grid(claims, sev_grid, POINTS).ceded[0]
# The way a program with a gap is built: map the severity through its layers, then compound.
ceded_severity, _ = sev_grid.map(
    lambda x: sum(min(max(x - att, 0.0), lim) for lim, att in PROGRAM))
mapped, _ = fft(claims, ceded_severity, POINTS)
print(f"single layer against the mapped severity: largest difference in probability "
      f"{max(abs(a - b) for a, b in zip(program_ceded.probs, mapped.probs)):.1e}\n")

exact_ceded = 10 * sum(severity.layer(lim, att) for lim, att in PROGRAM)
print(f"{'':8s} {'mean':>10s} {'exact mean':>11s} {'sd':>9s} {'cv':>7s} {'99% quantile':>13s}")
for label, grid, exact in [("gross", gross, 10 * severity.lev(5000.0)), ("ceded", program_ceded, exact_ceded),
                           ("net", net, 10 * severity.lev(5000.0) - exact_ceded)]:
    mean, sd, cv, _ = moments(grid)
    print(f"{label:8s} {mean:10.3f} {exact:11.3f} {sd:9.1f} {cv:7.3f} {grid.quantile(0.99):13.1f}")

compare_distribution(S2, "gross", "tower_program", "gross", gross, BS1, shown=("mean", "q0.99"))
compare_distribution(S2, "ceded", "tower_program", "ceded", program_ceded, BS1)
compare_distribution(S2, "net", "tower_program", "net", net, BS1)
compare(S2, "ceded mean, exact", "tower_program", "ceded_mean_exact", exact_ceded)
compare(S2, "net mean, exact", "tower_program", "net_mean_exact", 10 * severity.lev(5000.0) - exact_ceded)
compare(S2, "net mean claim, grid", "tower_program", "net_sev_mean", sev_grid.mean() - ceded_severity.mean())
for (lim, att), layer_grid in zip(PROGRAM, program_grids.ceded):
    tag = f"layer_{lim:g}x{att:g}"
    compare_distribution(S2, f"layer {lim:g} xs {att:g}", "tower_program", f"{tag}_ceded", layer_grid, BS1,
                         shown=("mean", "cv"))
report()
single layer against the mapped severity: largest difference in probability 2.2e-16



               mean  exact mean        sd      cv  99% quantile
gross       950.161     950.575    1016.6   1.070        5440.0
ceded       201.903     201.904     456.1   2.259        1824.0
net         748.258     748.672     640.7   0.856        3836.0


quantity                                      aggregate      prospicio   difference  pass
gross mean                                    950.16081      950.16081      3.0e-12  yes
gross q0.99                                        5440           5440     0.00 bkt  yes
ceded mean                                    201.90315      201.90315      2.8e-13  yes
ceded sd                                      456.13135      456.13135      3.7e-11  yes
ceded cv                                      2.2591592      2.2591592      3.6e-11  yes
ceded skew                                    2.7608619       2.760862      1.5e-08  yes
ceded q0.5                                            0              0     0.00 bkt  yes
ceded q0.9                                          816            816     0.00 bkt  yes
ceded q0.99                                        1824           1824     0.00 bkt  yes
ceded q0.999                                       3000           3000     0.00 bkt  yes
net mean                                      748.25767      748.25767      2.4e-12  yes
net sd                                        640.65856      640.65856      5.7e-10  yes
net cv                                       0.85620046     0.85620046      5.7e-10  yes
net skew                                       2.940129      2.9401295      1.6e-07  yes
net q0.5                                            616            616     0.00 bkt  yes
net q0.9                                           1360           1360     0.00 bkt  yes
net q0.99                                          3836           3836     0.00 bkt  yes
net q0.999                                         4948           4948     0.00 bkt  yes
ceded mean, exact                             201.90371      201.90371      2.1e-15  yes
net mean, exact                               748.67176      748.67176      3.3e-15  yes
net mean claim, grid                          74.825767      74.825767      2.5e-15  yes
layer 500 xs 500 mean                         114.81139      114.81139      3.3e-12  yes
layer 500 xs 500 cv                           1.9241064      1.9241064      1.0e-09  yes
layer 1000 xs 1000 mean                       87.091755      87.091755      4.1e-15  yes
layer 1000 xs 1000 cv                         3.0844704      3.0844704      1.7e-15  yes

Gross, ceded and net all match, including the net view that aggregate holds in reins_density_df. Ceded and net add up in the mean (950.16 = 201.90 + 748.26) but not in the standard deviation: 456.1 + 640.7 = 1,096.8 is more than the gross 1,016.6. Ceded and net come from the same claims, so they move together, but not in lockstep. For example, a year of many small claims is all net. Thus the gross spread is less than the sum of the two. A reinsurer does not see this diversification from inside its own layer.

Now the 80% share of 1,000 xs 1,000.

share_layer = Layer("80% of 1000 xs 1000", 1000.0, 1000.0, share=0.8)
share_grids = Tower([share_layer]).on_grid(claims, sev_grid, POINTS)
share_ceded = share_grids.ceded[0]
print(f"step of the ceded grid {share_ceded.step:g}, mean {share_ceded.mean():.4f}, "
      f"exact {0.8 * 10 * severity.layer(1000.0, 1000.0):.4f}")

compare_distribution(S2, "80% of 1000 xs 1000", "tower_program", "share80_1000x1000_ceded", share_ceded, BS1,
                     share=True)
compare(S2, "80% of 1000 xs 1000 mean, exact", "tower_program", "share80_1000x1000_ceded_mean_exact",
        0.8 * 10 * severity.layer(1000.0, 1000.0), show=False)
report()
step of the ceded grid 3.2, mean 69.6734, exact 69.6735
quantity                                      aggregate      prospicio   difference  pass
80% of 1000 xs 1000 mean                      69.673404      69.673404      2.9e-13  yes
80% of 1000 xs 1000 sd                        214.90612      214.90555      2.6e-06  yes
80% of 1000 xs 1000 cv                        3.0844785      3.0844704      2.6e-06  yes
80% of 1000 xs 1000 skew                      3.3986838      3.3986889      1.5e-06  yes
80% of 1000 xs 1000 q0.5                              0              0     0.00 bkt  yes
80% of 1000 xs 1000 q0.9                            212          211.2     0.20 bkt  yes
80% of 1000 xs 1000 q0.99                           800            800     0.00 bkt  yes
80% of 1000 xs 1000 q0.999                         1600           1600     0.00 bkt  yes

The mean agrees to rounding. The standard deviation differs by 2.6e-6, the skewness by 1.5e-6, and the 90% quantile by 0.8, a fifth of a bucket. The cause is the re-bucketing in aggregate. It spreads each ceded amount between its buckets of 4 over the two adjacent buckets, which adds a little variance. prospicio keeps the ceded grid at step 3.2. Thus the standard deviation and quantiles of a share off the grid have their own tolerances (1e-5 and one bucket).

The gross, ceded and net annual distributions of the program:

import matplotlib.pyplot as plt

xs = [i * 40.0 for i in range(201)]
fig, ax = plt.subplots(figsize=(7, 3.8))
for label, grid in [("gross", gross), ("net of the program", net), ("ceded to the program", program_ceded)]:
    ax.plot(xs, [1.0 - grid.cdf(x) for x in xs], label=label)
ax.set_yscale("log")
ax.set_ylim(1e-4, 1.2)
ax.set_xlabel("annual loss (currency units)")
ax.set_ylabel("probability of exceeding")
ax.set_title("Exceedance curves, 10 claims, 500 xs 500 and 1,000 xs 1,000")
ax.legend()
fig.tight_layout()
plt.show()

png

3. An annual aggregate limit and reinstatements

The contract. Bear and Nemlick’s Treaty 2: three classes of business, each with subject premium 2,000, and expected layer loss 10%, 14% and 21% of it. The layer is 700 xs 300 of a single-parameter Pareto with shape 1.5, 1.3 and 1.1. This is a Lomax of that shape, with scale 300, limited to 700. The claim count is gamma-mixed Poisson with mixing CV 0.07, and all classes share one mixing variable. The treaty has an annual aggregate limit of 2,800: the original 700 plus three reinstatements.

agg Re.BN2 [2000 2000 2000] exposure at [.1 .14 .21] rate 700 xs 0
    sev 300 * pareto [1.5 1.3 1.1] - 300 mixed gamma 0.07              (bs = 1/8)
agg Re.BN2 ... aggregate ceded to 2800 xs 0

exposure at rate fixes the expected loss of each class, and aggregate solves the claim count from it. exposure_book does the same with Burr(shape, 1, scale) (the Lomax) and its limited expected value. The three counts check that step. With one shared mixing variable, the three classes are one mixed Poisson over a mixture of the three severities. Thus one fft gives the gross annual loss.

Reinstatements. The two schedules are designed:

  • A: three reinstatements at 100%.
  • B: the first reinstatement free, the second at 50% and the third at 100%.

Both are pro rata as to amount, as in aggregate. In a year with layer loss L, the k-th reinstatement restores the k-th 700 of used limit. Its premium is deposit x rate_k x min(max(L - (k - 1) 700, 0), 700) / 700, summed over k = 1, 2, 3. aggregate computes it with its ReinstatementTerms on the annual layer loss.

The deposit of 1,200 (a rate on line of 171%) is a designed input to the comparison. It is not a price, and it does not come from the loss cost. The reinstatement premium is proportional to the deposit. Thus a price comes from the deposit that gives a target loss ratio. The cell after the comparison solves for that deposit for each schedule.

S3 = "3 limit and reinstatements"
BS3 = 1 / 8
counts3, n3, mix3 = exposure_book([2000.0] * 3, [0.10, 0.14, 0.21], [1.5, 1.3, 1.1], 300.0, 700.0)
freq3 = mixed_poisson(n3, 0.07)
sev3 = discretize(mix3, BS3, 700.0)
gross3, report3 = fft(freq3, sev3, POINTS)
print(f"expected claims by class {[round(c, 4) for c in counts3]}, total {n3:.4f}")
print(f"frequency {freq3}")
print(f"mass beyond the grid {report3.tail_mass:.1e}")

for i, c in enumerate(counts3, 1):
    compare(S3, f"class {i} expected claims", "agg_limit_reinst", f"class{i}_expected_count", c)
compare(S3, "expected claims", "agg_limit_reinst", "claim_count_mean", n3)
compare(S3, "gross mean, exact", "agg_limit_reinst", "gross_mean_exact", n3 * mix3.lev(700.0))
exact_cv3 = math.sqrt(n3 * mix3.layer_second_moment(700.0, 0.0) + 0.07**2 * (n3 * mix3.lev(700.0)) ** 2) \
    / (n3 * mix3.lev(700.0))
compare(S3, "gross CV, exact", "agg_limit_reinst", "gross_cv_exact", exact_cv3)
compare_distribution(S3, "gross", "agg_limit_reinst", "gross", gross3, BS3)
report()
expected claims by class [0.737, 0.9236, 1.2342], total 2.8949
frequency NegativeBinomial(r=204.08163265306163, beta=0.014184778968906908)
mass beyond the grid 5.7e-10
quantity                                      aggregate      prospicio   difference  pass
class 1 expected claims                      0.73701074     0.73701074      6.0e-16  yes
class 2 expected claims                      0.92362085     0.92362085      1.3e-15  yes
class 3 expected claims                       1.2342213      1.2342213      9.0e-16  yes
expected claims                               2.8948529      2.8948529      3.1e-16  yes
gross mean, exact                                   900            900      1.3e-16  yes
gross CV, exact                               0.7696938      0.7696938      1.4e-16  yes
gross mean                                    899.99999      899.99999      6.3e-14  yes
gross sd                                      692.72442      692.72442      1.4e-13  yes
gross cv                                     0.76969381     0.76969381      2.0e-13  yes
gross skew                                   0.90206833     0.90206889      6.1e-07  yes
gross q0.5                                       785.75         785.75     0.00 bkt  yes
gross q0.9                                         1843           1843     0.00 bkt  yes
gross q0.99                                    2917.125       2917.125     0.00 bkt  yes
gross q0.999                                    3816.25        3816.25     0.00 bkt  yes
limit_layer = Layer("2800 aggregate limit", 700.0, 0.0, aggregate_limit=2800.0)
limited = Tower([limit_layer]).on_grid(freq3, sev3, POINTS).ceded[0]
beyond = gross3.stop_loss(2800.0)
print(f"mean recovery {money(limited.mean())}, P(limit used up) {prob_at_least(gross3, 2800.0):.5f}, "
      f"loss above the limit {beyond:.4f}")

compare_distribution(S3, "recovery under 2800", "agg_limit_reinst", "agglimit2800_ceded", limited, BS3,
                     shown=("mean", "sd", "q0.99"))
compare(S3, "P(limit used up)", "agg_limit_reinst", "agglimit2800_pr_hit", prob_at_least(gross3, 2800.0))
compare(S3, "loss above the limit", "agg_limit_reinst", "agglimit2800_mean_loss_beyond", beyond, "tail")
report()
mean recovery 894.68, P(limit used up) 0.01370, loss above the limit 5.3193
quantity                                      aggregate      prospicio   difference  pass
recovery under 2800 mean                      894.68068      894.68068      3.4e-09  yes
recovery under 2800 sd                        674.94584      674.94582      3.1e-08  yes
recovery under 2800 q0.99                          2800           2800     0.00 bkt  yes
P(limit used up)                            0.013700601    0.013700601      4.1e-08  yes
loss above the limit                          5.3193114      5.3193144      5.7e-07  yes
DEPOSIT, LIMIT3, TARGET_LR = 1200.0, 700.0, 0.65
per_deposit = {}
for tag, rates in [("A", [1.0, 1.0, 1.0]), ("B", [0.0, 0.5, 1.0])]:
    layer = Layer(f"schedule {tag}", LIMIT3, 0.0, reinstatement_rates=rates).with_deposit_premium(DEPOSIT)
    grids = Tower([layer]).on_grid(freq3, sev3, POINTS)
    reinstatement = grids.expected_reinstatement_premium[0]
    recovery = grids.ceded[0].mean()
    total = layer.premium + reinstatement
    per_deposit[tag] = (reinstatement / layer.premium, recovery)
    print(f"schedule {tag} {rates}: deposit {money(layer.premium)} (rate on line {layer.premium / LIMIT3:.0%}), "
          f"expected reinstatement premium {money(reinstatement)}, total {money(total)}")
    print(f"    expected recovery {money(recovery)}, loss ratio {recovery / total:.1%}, "
          f"margin {money(total - recovery)}")
    compare(S3, f"{tag}: expected reinstatement premium", "agg_limit_reinst", f"reinst{tag}_premium_mean",
            reinstatement)
    compare(S3, f"{tag}: total premium", "agg_limit_reinst", f"reinst{tag}_total_premium_mean", total)
    compare(S3, f"{tag}: recovery", "agg_limit_reinst", f"reinst{tag}_recovery_mean", recovery)
    compare(S3, f"{tag}: P(any loss to the layer)", "agg_limit_reinst", f"reinst{tag}_pr_any_reinstatement",
            1.0 - gross3.probs[0])
    compare(S3, f"{tag}: maximum premium", "agg_limit_reinst", f"reinst{tag}_max_premium",
            layer.premium * sum(rates), show=False, check=True)
report()

# The deposit that prices each schedule at the target loss ratio. The total premium is the deposit
# times (1 + k), where k is the expected reinstatement premium per unit of deposit.
print()
for tag, (k, recovery) in per_deposit.items():
    deposit = recovery / TARGET_LR / (1 + k)
    print(f"schedule {tag}: a deposit of {money(deposit)} (rate on line {deposit / LIMIT3:.0%}) prices it at a "
          f"{TARGET_LR:.0%} loss ratio, total {money(deposit * (1 + k))}, {k / (1 + k):.0%} of it from reinstatements")
schedule A [1.0, 1.0, 1.0]: deposit 1,200.00 (rate on line 171%), expected reinstatement premium 1,495.57, total 2,695.57
    expected recovery 894.68, loss ratio 33.2%, margin 1,800.89
schedule B [0.0, 0.5, 1.0]: deposit 1,200.00 (rate on line 171%), expected reinstatement premium 371.58, total 1,571.58
    expected recovery 894.68, loss ratio 56.9%, margin 676.90
quantity                                      aggregate      prospicio   difference  pass
A: expected reinstatement premium             1495.5693      1495.5693      1.4e-09  yes
A: total premium                              2695.5693      2695.5693      7.5e-10  yes
A: recovery                                   894.68068      894.68068      1.8e-09  yes
A: P(any loss to the layer)                  0.94351392     0.94351392      6.0e-10  yes
B: expected reinstatement premium             371.58102      371.58102      2.7e-09  yes
B: total premium                               1571.581       1571.581      6.5e-10  yes
B: recovery                                   894.68068      894.68068      1.8e-09  yes
B: P(any loss to the layer)                  0.94351392     0.94351392      6.0e-10  yes

schedule A: a deposit of 612.75 (rate on line 88%) prices it at a 65% loss ratio, total 1,376.43, 55% of it from reinstatements
schedule B: a deposit of 1,050.99 (rate on line 150%) prices it at a 65% loss ratio, total 1,376.43, 24% of it from reinstatements

The expected reinstatement premium and the recovery agree to 1e-8 or better. The recovery under schedule A or B is the same 894.68, because both schedules have the same annual limit of 2,800. It is the mean of the aggregate-limit layer above. aggregate’s probability of a reinstatement is the probability of any loss to the layer, P(L > 0). Under schedule B the first reinstatement is free, so a reinstatement premium is due only when L is more than 700.

At the designed deposit, schedule A collects 2,695.57 against an expected recovery of 894.68 (a 33% loss ratio) and B collects 1,571.58 (57%). Priced to the same 65% loss ratio, both collect 1,376.43 in expectation, but A needs the smaller deposit. A charges for each reinstatement, so more of its premium comes after losses and less comes at the start. The schedule moves premium between the deposit and the loss-contingent part. It does not change the expected total.

The stop loss at 2,800 (the loss above the limit) has the one looser tolerance in this section, because it reads the far tail. prospicio keeps the 6e-10 of probability beyond the grid’s top on its last point, and aggregate removes it. That shifts the result by 6e-7 relative, inside its tolerance of 1e-5.

The gross annual loss and the recovery under the limit. The steps at multiples of 700 are probability mass from claims at the 700 limit:

import matplotlib.pyplot as plt

xs = [i * 10.0 for i in range(421)]
fig, ax = plt.subplots(figsize=(7, 3.8))
ax.plot(xs, [1.0 - gross3.cdf(x) for x in xs], label="gross annual layer loss")
ax.plot(xs, [1.0 - limited.cdf(x) for x in xs], color="C3", label="recovery under the 2,800 limit")
ax.axvline(2800.0, color="grey", ls="--", lw=1)
ax.set_yscale("log")
ax.set_ylim(1e-4, 1.2)
ax.set_xlabel("annual loss (currency units)")
ax.set_ylabel("probability of exceeding")
ax.set_title("Treaty 2: the limit cuts the tail at 2,800")
ax.legend()
fig.tight_layout()
plt.show()

png

4. Aggregate stop loss and aggregate deductible

Stop loss. On the book of section 1, four covers on the annual total. They are 250 xs 750, 1,500 xs 1,000, the two together (750 to 2,500) and a 50% share of 1,500 xs 1,000. Layer.stop_loss(name, limit, retention) builds the first three covers at 100%. For the 50% share, the cell uses the Layer constructor with share=0.5, no per-occurrence limit, and the retention and limit as annual terms. The book has no premium, so the covers are in amounts. The market usually quotes a stop loss in loss ratio points of subject premium, and the amount is the points times the premium. On a subject premium of 1,000 (an expected loss ratio of 95%), 250 xs 750 is 25% xs 75%.

agg Re.T 10 claims 5000 xs 0 sev lognorm 100 cv 5 poisson aggregate ceded to 250 xs 750
agg Re.T ...                                    poisson aggregate ceded to 50% po 1500 xs 1000

Aggregate deductible. Bear and Nemlick’s Treaty 1: the 160 xs 40 layer of a single-parameter Pareto with shape 0.9 and 0.95 on two classes. The subject premiums are 9,000 and 3,000, with expected layer loss 4% and 3% of them, 450 in total. The count is gamma-mixed Poisson, with the mixing CV ((1.036 - 1) / 5.154)**0.5 that gives the CV in the text. The reinsurer pays above an annual aggregate deductible of 360 (3% of 12,000), aggregate net of 360 xs 0 in aggregate.

The guide’s table gives the subject premiums as 3,000 and 6,000. Its code uses 9,000 and 3,000 at 4% and 3%, which gives the 450 (3.75% of 12,000) in its Treaty 4 text. The notebook uses the values of the code.

S4 = "4 stop loss"


def annual_cover(layer):
    # The annual ceded and net of one aggregate cover on the book of section 1.
    return Tower([layer]).on_grid(claims, sev_grid, POINTS)


for lim, att in [(250.0, 750.0), (1500.0, 1000.0)]:
    name = f"{lim:g} xs {att:g}"
    cover = annual_cover(Layer.stop_loss(name, lim, att))
    tag = f"asl_{lim:g}x{att:g}"
    compare_distribution(S4, name, "stop_loss", f"{tag}_ceded", cover.ceded[0], BS1,
                         shown=("mean", "cv", "q0.9"))
    compare(S4, f"{name} P(attach)", "stop_loss", f"{tag}_pr_attach", 1.0 - gross.cdf(att))
    compare(S4, f"{name} P(exhaust)", "stop_loss", f"{tag}_pr_exhaust", prob_at_least(gross, att + lim))
    compare(S4, f"{name} loss on line", "stop_loss", f"{tag}_loss_on_line", cover.ceded[0].mean() / lim)

both = annual_cover(Layer.stop_loss("750 to 2500", 1750.0, 750.0))
# Layer.stop_loss takes no share: a share of a stop loss is a layer with no per-occurrence limit
# and the retention and limit as annual terms.
half = annual_cover(Layer("50% of 1500 xs 1000", math.inf, 0.0, share=0.5, aggregate_deductible=1000.0,
                          aggregate_limit=1500.0))
compare_distribution(S4, "both layers, ceded", "stop_loss", "asl_both_ceded", both.ceded[0], BS1,
                     shown=("mean", "cv"))
compare_distribution(S4, "both layers, net", "stop_loss", "asl_both_net", both.net, BS1,
                     shown=("mean", "cv", "q0.9"))
compare_distribution(S4, "50% of 1500 xs 1000", "stop_loss", "asl_50pct_1500x1000_ceded", half.ceded[0], BS1,
                     share=True, shown=("mean", "cv"))
print(f"750 to 2,500: ceded {both.ceded[0].mean():.3f} + net {both.net.mean():.3f} = {gross.mean():.3f}")
report()
750 to 2,500: ceded 310.061 + net 640.100 = 950.161
quantity                                      aggregate      prospicio   difference  pass
250 xs 750 mean                               89.806004      89.806004      1.9e-14  yes
250 xs 750 cv                                 1.2760283      1.2760283      1.4e-14  yes
250 xs 750 q0.9                                     252            252     0.00 bkt  yes
250 xs 750 P(attach)                         0.42378674     0.42378674      1.1e-13  yes
250 xs 750 P(exhaust)                        0.30365425     0.30365425      1.6e-13  yes
250 xs 750 loss on line                      0.35922402     0.35922402      1.8e-14  yes
1500 xs 1000 mean                              220.2549       220.2549      3.9e-14  yes
1500 xs 1000 cv                               2.0322163      2.0322163      1.6e-14  yes
1500 xs 1000 q0.9                                  1024           1024     0.00 bkt  yes
1500 xs 1000 P(attach)                       0.30208796     0.30208796      1.6e-13  yes
1500 xs 1000 P(exhaust)                     0.067240438    0.067240438      7.0e-13  yes
1500 xs 1000 loss on line                     0.1468366      0.1468366      3.9e-14  yes
both layers, ceded mean                        310.0609       310.0609      3.2e-14  yes
both layers, ceded cv                         1.7188985      1.7188985      1.2e-14  yes
both layers, net mean                         640.09991      640.09991      2.2e-12  yes
both layers, net cv                          0.91040967     0.91040967      5.4e-10  yes
both layers, net q0.9                               752            752     0.00 bkt  yes
50% of 1500 xs 1000 mean                      110.12745      110.12745      3.9e-14  yes
50% of 1500 xs 1000 cv                        2.0322313      2.0322163      7.4e-06  yes

The stop-loss covers agree on every statistic. The 50% share differs off the grid for the same reason as the 80% share in section 2.

The aggregate deductible:

S4B = "4 aggregate deductible"
BS4 = 0.0625
MIX_CV4 = ((1.036 - 1) / 5.154) ** 0.5
counts4, n4, mix4 = exposure_book([9000.0, 3000.0], [0.04, 0.03], [0.9, 0.95], 40.0, 160.0)
sev4 = discretize(mix4, BS4, 160.0)
aad = Layer("AAD 360", math.inf, 0.0, aggregate_deductible=360.0)

gross4, _ = fft(mixed_poisson(n4, MIX_CV4), sev4, POINTS)
after_aad = Tower([aad]).on_grid(mixed_poisson(n4, MIX_CV4), sev4, POINTS).ceded[0]
gross4_poisson, _ = fft(Poisson(n4), sev4, POINTS)
after_aad_poisson = Tower([aad]).on_grid(Poisson(n4), sev4, POINTS).ceded[0]

absorbed = gross4.lev(360.0)
print(f"expected claims {n4:.4f}, gross CV {moments(gross4)[2]:.4f} (the text quotes 0.528)")
print(f"expected loss {money(gross4.mean())}; after the deductible {money(after_aad.mean())}; "
      f"absorbed by the deductible {money(absorbed)}")
print(f"loss elimination ratio (the cedant's credit) {absorbed / gross4.mean():.4f}; excess ratio (the reinsurer's "
      f"share, aggregate's insurance charge) {after_aad.mean() / gross4.mean():.4f}")
print(f"with Poisson counts the loss after the deductible falls to {money(after_aad_poisson.mean())}")

for i, c in enumerate(counts4, 1):
    compare(S4B, f"class {i} expected claims", "stop_loss_aad", f"class{i}_expected_count", c, show=False)
compare(S4B, "gross mean, exact", "stop_loss_aad", "gross_mean_exact", n4 * mix4.lev(160.0))
exact_cv4 = math.sqrt(n4 * mix4.layer_second_moment(160.0, 0.0) + MIX_CV4**2 * (n4 * mix4.lev(160.0)) ** 2) \
    / (n4 * mix4.lev(160.0))
compare(S4B, "gross CV, exact", "stop_loss_aad", "gross_cv_exact", exact_cv4)
compare_distribution(S4B, "gross", "stop_loss_aad", "gross", gross4, BS4, shown=("mean", "cv", "q0.99"))
compare_distribution(S4B, "after the deductible", "stop_loss_aad", "after_aad", after_aad, BS4)
compare(S4B, "value of the deductible", "stop_loss_aad", "aad_value", absorbed)
compare(S4B, "excess ratio (insurance charge)", "stop_loss_aad", "aad_insurance_charge",
        after_aad.mean() / gross4.mean())
compare_distribution(S4B, "Poisson, after the deductible", "stop_loss_aad", "poisson_after_aad",
                     after_aad_poisson, BS4, shown=("mean", "cv"))
compare(S4B, "Poisson gross mean", "stop_loss_aad", "poisson_gross_mean", gross4_poisson.mean(), show=False)
report()
expected claims 6.4966, gross CV 0.5285 (the text quotes 0.528)
expected loss 450.00; after the deductible 142.76; absorbed by the deductible 307.24
loss elimination ratio (the cedant's credit) 0.6828; excess ratio (the reinsurer's share, aggregate's insurance charge) 0.3172
with Poisson counts the loss after the deductible falls to 141.80
quantity                                      aggregate      prospicio   difference  pass
gross mean, exact                                   450            450      0.0e+00  yes
gross CV, exact                              0.52849748     0.52849748      2.1e-16  yes
gross mean                                    449.99998      449.99998      2.2e-12  yes
gross cv                                     0.52849751     0.52849751      2.0e-11  yes
gross q0.99                                    1103.625       1103.625     0.00 bkt  yes
after the deductible mean                     142.75897      142.75897      9.9e-13  yes
after the deductible sd                       183.77961      183.77961      7.1e-12  yes
after the deductible cv                        1.287342       1.287342      6.1e-12  yes
after the deductible skew                     1.5338445      1.5338445      1.6e-10  yes
after the deductible q0.5                       64.1875        64.1875     0.00 bkt  yes
after the deductible q0.9                           409            409     0.00 bkt  yes
after the deductible q0.99                      743.625        743.625     0.00 bkt  yes
after the deductible q0.999                   1016.8125      1016.8125     0.00 bkt  yes
value of the deductible                       307.24101      307.24101      3.5e-14  yes
excess ratio (insurance charge)              0.31724216     0.31724216      4.6e-12  yes
Poisson, after the deductible mean            141.79948      141.79948      9.5e-13  yes
Poisson, after the deductible cv              1.2794188      1.2794188      6.0e-12  yes

aggregate net of 360 xs 0 removes the first 360 of the loss each year (the cedant’s deductible). Thus its density is the reinsurer’s loss above 360, and Layer(aggregate_deductible=360) gives that side too. The value of the deductible to the cedant is E[min(X, 360)], Grid.lev(360): 307.24, a loss elimination ratio of 68.3% of the 450 expected loss. The other 31.7%, the excess ratio, goes to the reinsurer. aggregate calls that ratio the insurance charge: the Table M charge at an entry ratio of 360 / 450 = 0.8.

5. Retro and swing premium, profit commission and sliding scale

Four contracts with a price that depends on the loss. In aggregate, each is a map phi of the annual loss, from aggregate.contract_terms, applied to the density. In prospicio they are terms of the Layer, and Tower.on_grid averages them over the annual distribution (expected_premium, expected_profit_commission, expected_ceding_commission).

Retro rating (Treaty 4). The Treaty 1 book with Poisson counts, and the full 160 xs 40 layer at 100%. The subject premium is 12,000, the loss conversion factor 100/75, the minimum rate 3% (360) and the maximum rate 10% (1,200). The premium is clip(lcf x loss, 360, 1200). The terms are rates on subject premium, and the loss is an amount. The map uses amounts, so the cell multiplies each rate by 12,000. This is a swing premium with no basic premium, with_swing_rating(0, lcf, 360, 1200). LossSensitivePremium is the same map as a stand-alone object.

Swing rating (designed). The same loss, with premium clip(300 + 1.25 loss, 360, 1200), at 100% and at a 40% placed share. The terms are for 100%. prospicio scales the basic premium, the minimum and the maximum by the share, as aggregate’s underwriter does. It does not scale the loss conversion factor.

Profit commission (Treaty 5). Three independent years of the Treaty 2 book with Poisson counts, so the sum is a compound Poisson with three times the claim count. The reinsurer takes 80% of the layer for a ceded premium of 4,500 (25% of 18,000). The profit commission is 25% of the remainder after a 20% allowance and the losses, 0.25 max(0, 1 - 0.2 - LR), with the loss ratio on the ceded premium. This is the one-period form: the commission is settled once on the three-year total, with no deficit carried forward from a bad year. The years are independent, so the cell drops the mixing variable of Treaty 2. A deficit carry-forward, or a mixing variable shared by the years, would make the commission more variable. It would also change the difference between its mean and its value at the expected loss ratio.

Sliding scale (Treaty 6). A 900 xs 100 layer of a Pareto with shape 1.05 on 25,000 of subject premium, with ceded premium 5,000. The expected loss is 2,500 and the gamma mixing CV is 0.095. The commission is 40% at or below a 35% loss ratio, 25% at 55% and 20% at 65%. It is linear between these points and flat outside them.

S5 = "5 retro and swing"
BS5 = 0.0625
counts5, n5, mix5 = exposure_book([9000.0, 3000.0], [0.04, 0.03], [0.9, 0.95], 40.0, 160.0)
sev5 = discretize(mix5, BS5, 160.0)
LCF = 100 / 75

retro = Layer("retro", math.inf, 0.0).with_swing_rating(0.0, LCF, 360.0, 1200.0)
retro_grids = Tower([retro]).on_grid(Poisson(n5), sev5, POINTS)
layer_loss = retro_grids.ceded[0]

# The same premium from the stand-alone map, averaged by hand over the annual distribution.
terms = LossSensitivePremium(0.0, LCF, 360.0, 1200.0)
points = [i * layer_loss.step for i in range(len(layer_loss.probs))]
by_hand = sum(p * q for p, q in zip(terms.premium(points), layer_loss.probs))
at_min = sum(q for x, q in zip(points, layer_loss.probs) if LCF * x <= 360.0)
at_max = sum(q for x, q in zip(points, layer_loss.probs) if LCF * x >= 1200.0)

print(f"expected layer loss {money(layer_loss.mean())}, expected retro premium "
      f"{money(retro_grids.expected_premium[0])} ({retro_grids.expected_premium[0] / 12000:.3%} of 12,000)")
print(f"P(minimum premium) {at_min:.4f}, P(maximum premium) {at_max:.4f}")

compare_distribution(S5, "layer loss", "variable_retro", "ceded_loss", layer_loss, BS5,
                     shown=("mean", "cv", "q0.99"))
compare(S5, "retro premium", "variable_retro", "retro_premium_mean", retro_grids.expected_premium[0])
compare(S5, "retro premium, LossSensitivePremium", "variable_retro", "retro_premium_mean_via_terms", by_hand)
compare(S5, "retro rate on subject premium", "variable_retro", "retro_rate_mean",
        retro_grids.expected_premium[0] / 12000.0)
compare(S5, "P(minimum premium)", "variable_retro", "pr_min_binds", at_min)
compare(S5, "P(maximum premium)", "variable_retro", "pr_max_binds", at_max)

for share, tag in [(1.0, "share100"), (0.4, "share40")]:
    swing = Layer("swing", math.inf, 0.0, share=share).with_swing_rating(300.0, 1.25, 360.0, 1200.0)
    premium = Tower([swing]).on_grid(Poisson(n5), sev5, POINTS).expected_premium[0]
    print(f"swing premium at {share:.0%} placed: {money(premium)}")
    compare(S5, f"swing premium, {share:.0%} placed", "variable_swing", f"{tag}_premium_mean", premium)
report()
expected layer loss 450.00, expected retro premium 624.51 (5.204% of 12,000)
P(minimum premium) 0.2397, P(maximum premium) 0.0418
swing premium at 100% placed: 838.32


swing premium at 40% placed: 335.33
quantity                                      aggregate      prospicio   difference  pass
layer loss mean                               449.99998      449.99998      3.3e-13  yes
layer loss cv                                0.52184744     0.52184744      3.5e-12  yes
layer loss q0.99                                 1092.5         1092.5     0.00 bkt  yes
retro premium                                 624.50973      624.50973      4.6e-13  yes
retro premium, LossSensitivePremium           624.50973      624.50973      6.9e-14  yes
retro rate on subject premium               0.052042478    0.052042478      4.6e-13  yes
P(minimum premium)                           0.23965083     0.23965083      1.7e-15  yes
P(maximum premium)                          0.041823745    0.041823745      8.6e-13  yes
swing premium, 100% placed                    838.31936      838.31936      3.4e-13  yes
swing premium, 40% placed                     335.32774      335.32774      3.5e-13  yes
S5B = "5 profit commission"
BS5B = 0.25
counts5b, n5b, mix5b = exposure_book([2000.0] * 3, [0.10, 0.14, 0.21], [1.5, 1.3, 1.1], 300.0, 700.0)
sev5b = discretize(mix5b, BS5B, 700.0)
three_years = Poisson(3 * n5b)  # three independent years of Poisson counts

PREMIUM5B = 0.25 * 18000.0
pc_layer = (Layer("treaty 5", 700.0, 0.0, share=0.8, premium=PREMIUM5B)
            .with_profit_commission(0.25, allowance=0.2))
pc_grids = Tower([pc_layer]).on_grid(three_years, sev5b, POINTS)
total_loss, _ = fft(three_years, sev5b, POINTS)
lr = pc_grids.ceded[0].mean() / PREMIUM5B
commission = pc_grids.expected_profit_commission[0]

print(f"three years: expected loss {money(total_loss.mean())}, CV {moments(total_loss)[2]:.4f}")
print(f"ceded loss ratio {lr:.4f}; expected profit commission {money(commission)} = "
      f"{commission / PREMIUM5B:.3%} of the ceded premium")
print(f"at the expected loss ratio alone it would be {pc_layer.profit_commission_for(pc_grids.ceded[0].mean()) / PREMIUM5B:.3%}")

compare_distribution(S5B, "three-year loss", "variable_pc", "three_year_loss", total_loss, BS5B,
                     shown=("mean", "cv", "q0.99"))
compare(S5B, "ceded loss ratio", "variable_pc", "ceded_lr_mean", lr)
compare(S5B, "profit commission", "variable_pc", "pc_amount_mean", commission)
compare(S5B, "profit commission rate", "variable_pc", "pc_rate_mean", commission / PREMIUM5B)
compare(S5B, "rate at the expected loss ratio", "variable_pc", "pc_at_expected_lr",
        pc_layer.profit_commission_for(pc_grids.ceded[0].mean()) / PREMIUM5B)
compare(S5B, "P(profit commission > 0)", "variable_pc", "pr_pc_positive",
        sum(q for i, q in enumerate(pc_grids.ceded[0].probs)
            if i * pc_grids.ceded[0].step / PREMIUM5B < 1 - 0.2))
report()
three years: expected loss 2,700.00, CV 0.4425
ceded loss ratio 0.4800; expected profit commission 370.72 = 8.238% of the ceded premium
at the expected loss ratio alone it would be 8.000%


quantity                                      aggregate      prospicio   difference  pass
three-year loss mean                          2699.9999      2699.9999      1.8e-12  yes
three-year loss cv                           0.44254137     0.44254137      1.6e-11  yes
three-year loss q0.99                           5900.25        5900.25     0.00 bkt  yes
ceded loss ratio                             0.47999998     0.47999998      3.4e-13  yes
profit commission                             370.72496      370.72496      1.4e-15  yes
profit commission rate                      0.082383324    0.082383324      1.3e-15  yes
rate at the expected loss ratio             0.080000004    0.080000004      5.1e-13  yes
P(profit commission > 0)                     0.92275596     0.92275596      1.2e-15  yes
S5C = "5 sliding scale"
BS5C = 0.5
counts5c, n5c, mix5c = exposure_book([25000.0], [0.10], [1.05], 100.0, 900.0)
sev5c = discretize(mix5c, BS5C, 900.0)
frequency5c = mixed_poisson(n5c, 0.095)

PREMIUM5C = 25000.0 * 0.20
ANCHORS = [(0.40, 0.35), (0.25, 0.55), (0.20, 0.65)]  # (commission, loss ratio)
slide = Layer("treaty 6", 900.0, 0.0, premium=PREMIUM5C).with_sliding_scale(ANCHORS)
slide_grids = Tower([slide]).on_grid(frequency5c, sev5c, POINTS)
slide_loss = slide_grids.ceded[0]
slide_commission = slide_grids.expected_ceding_commission[0]
at_expected = slide.ceding_commission_for(slide_loss.mean()) / PREMIUM5C
lr_probs = [(i * slide_loss.step / PREMIUM5C, q) for i, q in enumerate(slide_loss.probs)]

print(f"expected claims {n5c:.4f}; expected ceded loss {money(slide_loss.mean())}, loss ratio "
      f"{slide_loss.mean() / PREMIUM5C:.3f}")
print(f"expected commission {money(slide_commission)} = {slide_commission / PREMIUM5C:.2%} of premium")
print(f"commission at the expected loss ratio {at_expected:.2%}")


# The gap between the two comes from where the scale leaves its middle segment (slope -0.75),
# extended in a straight line: capped at 40% below a 35% loss ratio, flatter above 55%.
def scale(r):
    return slide.ceding_commission_for(r * PREMIUM5C) / PREMIUM5C


def middle(r):
    return 0.40 - 0.75 * (r - 0.35)


below = sum(q * (scale(x) - middle(x)) for x, q in lr_probs if x < 0.35)
above = sum(q * (scale(x) - middle(x)) for x, q in lr_probs if x > 0.55)
print(f"against the middle segment extended, years below a 35% loss ratio take {-below:.2%} off the expected "
      f"commission and years above 55% add {above:.2%}")

compare(S5C, "expected claims", "variable_slide", "claim_count_mean", n5c, show=False)
compare_distribution(S5C, "ceded loss", "variable_slide", "ceded_loss", slide_loss, BS5C,
                     shown=("mean", "cv", "q0.99"))
compare(S5C, "ceded loss ratio", "variable_slide", "ceded_lr_mean", slide_loss.mean() / PREMIUM5C)
compare(S5C, "expected commission", "variable_slide", "slide_commission_amount_mean", slide_commission)
compare(S5C, "expected commission rate", "variable_slide", "slide_commission_rate_mean",
        slide_commission / PREMIUM5C)
compare(S5C, "rate at the expected loss ratio", "variable_slide", "slide_commission_at_expected_lr", at_expected)
compare(S5C, "P(loss ratio <= 35%)", "variable_slide", "pr_lr_below_35", sum(q for x, q in lr_probs if x <= 0.35))
compare(S5C, "P(loss ratio >= 65%)", "variable_slide", "pr_lr_above_65", sum(q for x, q in lr_probs if x >= 0.65))
report()
expected claims 11.4944; expected ceded loss 2,500.00, loss ratio 0.500
expected commission 1,517.10 = 30.34% of premium
commission at the expected loss ratio 28.75%
against the middle segment extended, years below a 35% loss ratio take 2.53% off the expected commission and years above 55% add 4.12%
quantity                                      aggregate      prospicio   difference  pass
ceded loss mean                               2499.9988      2499.9988      3.5e-13  yes
ceded loss cv                                0.48516014     0.48516014      8.1e-12  yes
ceded loss q0.99                                   5855           5855     0.00 bkt  yes
ceded loss ratio                             0.49999975     0.49999975      3.5e-13  yes
expected commission                           1517.1043      1517.1043      9.2e-14  yes
expected commission rate                     0.30342085     0.30342085      9.2e-14  yes
rate at the expected loss ratio              0.28750019     0.28750019      4.6e-13  yes
P(loss ratio <= 35%)                         0.29507999     0.29507999      8.1e-15  yes
P(loss ratio >= 65%)                         0.24854466     0.24854466      1.1e-13  yes

All four agree. Three notes:

  • A variable premium or commission is a function of the full annual distribution, not of the expected loss. The average of a non-linear map differs from the map at the average. The profit commission, 0.25 max(0, 0.8 - LR), is convex in the loss ratio, so its average (8.24% of premium) is above its value at the expected loss ratio (8.00%), as Jensen’s inequality requires. The sliding scale is not convex: it bends down at 35% (where it stops at 40%) and up at 55% and 65%. Its average (30.3%) is above its value at the expected loss ratio (28.8%) only because this loss ratio is skewed to the right. The years above 55%, where the scale is flat, add more than the 29.5% of years below 35% take off. The cell above splits the difference.

    For a book with a different spread, the difference could have the other sign. The expected_* results average the terms over the distribution. A price from the expected loss alone does not include this effect.

  • aggregate’s documentation for the sliding scale builds the schedule in code with a slope of 0.25 on the first segment. Its text says 0.75. That code gives a commission of 35.7%, not 30.3%. The table compares the terms in the text, which with_sliding_scale takes.

  • aggregate’s profit commission does not deduct a ceding commission. with_profit_commission does the same, and its allowance covers any commission that the contract takes before profit.

The commission scale and the loss ratio it applies to:

import matplotlib.pyplot as plt

lrs = [i / 200 for i in range(0, 161)]
fig, ax = plt.subplots(figsize=(7, 3.8))
dx = slide_loss.step / PREMIUM5C
upto = int(0.8 / dx) + 1  # grid points up to a loss ratio of 80%
ax.fill_between([x for x, _ in lr_probs[:upto]], [q / dx for _, q in lr_probs[:upto]], color="C0", alpha=0.35,
                label="density of the loss ratio")
ax.set_xlim(0, 0.8)
ax.set_xlabel("ceded loss ratio (loss / 5,000 ceded premium)")
ax.set_ylabel("probability density")
ax2 = ax.twinx()
ax2.plot(lrs, [slide.ceding_commission_for(x * PREMIUM5C) / PREMIUM5C for x in lrs], color="C3", label="commission")
ax2.set_ylabel("commission (fraction of ceded premium)")
ax2.set_ylim(0, 0.5)
ax.set_title("Treaty 6: sliding-scale commission and the loss ratio")
fig.legend(loc="upper right", bbox_to_anchor=(0.88, 0.85))
fig.tight_layout()
plt.show()

png

6. Risk-adjusted premium with distortions

The contract. The program of section 2, priced as a risk in two views. One view is the reinsurer’s ceded loss (the annual loss to 500 xs 500 and 1,000 xs 1,000). The other view is the cedant’s gross annual loss. The capital standard sets assets a at the 99% quantile of the view. The cost of capital is 10%, so the CCoC premium P solves P = L + 0.10 (a - P) with L = E[min(X, a)]. This premium is a risk-adjusted loss cost: the expected loss plus the cost of the capital it holds. It excludes expenses, brokerage, ceding commission and investment income. The cell calibrates the proportional hazard, Wang, dual power and TVaR distortions so that each prices min(X, a) at P. It also prices a second set of distortions with fixed parameters at the same assets.

aggregate does this with Aggregate.calibrate_distortions(0.10, p=0.99, reins_view=...). These examples are designed, because the pricing pages of aggregate have no worked example for this book.

In prospicio. CCoC is a distortion, g(s) = (r + s) / (1 + r) for s > 0. Thus Distortion.ccoc(0.10).measure of min(X, a) is the premium, and Grid.lev(a) is L. prospicio.risk.calibrate(family, dist, premium, assets=a) finds the parameter that prices min(X, a) at the premium. Distortion.measure prices a grid. aggregate takes a as the lower 99% quantile on the grid, and Grid.quantile does the same, so F(a) is a little above 99%.

Distortion.family and Distortion.parameters read the calibrated family and parameter from the object, so the cell compares each parameter with the parameter of aggregate. calibrate takes the short name of a family (ph, dual), which is the first column of the table. Distortion.family returns the constructor name (proportional_hazard, dual_power), which labels the calibrated distortion. The cell also compares the distortion function g(s) at two survival probabilities, with aggregate’s parameter in aggregate’s formula. This checks that the two packages define each family the same way, which the parameter alone does not show.

Reading the table. “price of min(X, a)” is the premium of each calibrated distortion at the capital standard, so it equals P by construction. “unlimited” is the same distortion applied to X with no cap: the premium if the assets did not limit the reinsurer’s liability. The difference between the two is the load that the distortion puts on the tail above the 99% standard. CCoC shows n/a. Its jump at s = 0 charges the cost of capital on the largest possible loss, so the cap is part of its definition.

S6 = "6 risk pricing"
normal = NormalDist()
AGG_G = {  # g(s) from the parameter aggregate calibrated
    "ccoc": lambda r, s: min(1.0, (r + s) / (1 + r)),
    "ph": lambda rho, s: s**rho,
    "wang": lambda lam, s: normal.cdf(normal.inv_cdf(s) + lam),
    "dual": lambda b, s: 1.0 - (1.0 - s) ** b,
    "tvar": lambda p, s: min(1.0, s / (1.0 - p)),
}
COC, CAPITAL_P = 0.10, 0.99
OCCURRENCE_LIMIT = 1500.0  # the program's limit per occurrence: 500 xs 500 and 1,000 xs 1,000
FIXED = [("ph0.7", Distortion.proportional_hazard(0.7)), ("wang0.4", Distortion.wang(0.4)),
         ("dual1.8", Distortion.dual_power(1.8)), ("tvar0.3", Distortion.tvar(0.3)),
         ("ccoc0.1", Distortion.ccoc(0.1))]
priced = {}

for view, example, x in [("ceded", "risk_pricing_ceded", program_ceded), ("gross", "risk_pricing_gross", gross)]:
    s = f"6 {view} view"
    assets = x.quantile(CAPITAL_P)
    capped, _ = x.map(lambda v: min(v, assets))
    loss = x.lev(assets)  # E[min(X, a)]
    premium = Distortion.ccoc(COC).measure(capped)  # (L + r a) / (1 + r)
    capital = assets - premium
    compare(s, "assets, the 99% quantile", example, "cal_a", assets)
    compare(s, "F(assets)", example, "cal_F(a)", x.cdf(assets))
    compare(s, "expected loss E[min(X, a)]", example, "cal_L", loss)
    compare(s, "CCoC premium", example, "cal_P", premium)
    # a - P, and (P - L) / (a - P) = r: they follow from the rows above.
    compare(s, "capital", example, "cal_Q", capital, check=True)
    compare(s, "return on capital", example, "cal_ROE", (premium - loss) / capital, check=True)
    report()

    print(f"{view}: assets {money(assets)}, expected loss {money(loss)}, premium {money(premium)}, "
          f"capital {money(capital)}")
    rate_on_line = f", rate on line {premium / OCCURRENCE_LIMIT:.1%}" if view == "ceded" else ""
    print(f"    loss ratio {loss / premium:.1%}, margin {money(premium - loss)} ({COC:.0%} of the capital)"
          f"{rate_on_line}")
    print(f"{'family':>8s} {'calibrated':<34s} {'g(0.05)':>9s} {'price of min(X, a)':>19s} {'unlimited':>11s}")
    for family in ["ccoc", "ph", "wang", "dual", "tvar"]:
        d = calibrate(family, x, premium, assets=assets)
        parameter = AGG[(example, f"param_{family}")]
        for sv in (0.05, 0.5):
            agg_g = AGG_G[family](parameter, sv)
            # The calibrated CCoC is the cost of capital the premium was built from: a consistency check.
            _record(s, f"{family}: g({sv}) at aggregate's parameter", agg_g, d.g(sv),
                    abs(d.g(sv) - agg_g) / agg_g, "mean", False, family == "ccoc")
        # The calibrated parameter, read off the distortion, against the one aggregate calibrated.
        [(key, value)] = d.parameters.items()  # each of these families has one parameter
        compare(s, f"{family}: parameter {key}", example, f"param_{family}", value, check=family == "ccoc")
        # Calibrated to the premium, so its price of min(X, a) is the premium: a consistency check.
        compare(s, f"{family}: price of min(X, a)", example, f"price_ask_{family}", d.measure(capped), check=True)
        if family != "ccoc":
            compare(s, f"{family}: unlimited price", example, f"unlimited_price_ask_{family}", d.measure(x),
                    show=False)
        priced[(view, family)] = d
        unlimited = f"{d.measure(x):11.4f}" if family != "ccoc" else f"{'n/a':>11s}"
        label = f"{d.family}(" + ", ".join(f"{k}={v:.6f}" for k, v in d.parameters.items()) + ")"
        print(f"{family:>8s} {label:<34s} {d.g(0.05):9.5f} {d.measure(capped):19.6f} {unlimited}")
    for name, d in FIXED:
        compare(s, f"fixed {name}: price of min(X, a)", example, f"fixed_price_ask_{name}", d.measure(capped),
                show=False, check=name.startswith("ccoc"))
    report()
quantity                                      aggregate      prospicio   difference  pass
assets, the 99% quantile                           1824           1824      0.0e+00  yes
F(assets)                                    0.99003732     0.99003732      4.0e-15  yes
expected loss E[min(X, a)]                     196.4172       196.4172      1.2e-13  yes
CCoC premium                                  344.37927      344.37927      6.5e-14  yes
capital *                                     1479.6207      1479.6207      1.5e-14  yes
return on capital *                                 0.1            0.1      4.7e-15  yes
ceded: assets 1,824.00, expected loss 196.42, premium 344.38, capital 1,479.62
    loss ratio 57.0%, margin 147.96 (10% of the capital), rate on line 23.0%
  family calibrated                           g(0.05)  price of min(X, a)   unlimited
    ccoc ccoc(r=0.100000)                     0.13636          344.379269         n/a
      ph proportional_hazard(rho=0.725171)    0.11390          344.379269    369.8526
    wang wang(lambda=0.388188)                0.10444          344.379269    360.4499
    dual dual_power(beta=1.885608)            0.09219          344.379269    354.6992
    tvar tvar(p=0.429649)                     0.08767          344.379269    353.9978
quantity                                      aggregate      prospicio   difference  pass
ccoc: parameter r *                                 0.1            0.1      6.9e-16  yes
ccoc: price of min(X, a) *                    344.37927      344.37927      1.7e-16  yes
ph: parameter rho                            0.72517146     0.72517146      1.3e-09  yes
ph: price of min(X, a) *                      344.37927      344.37927      2.0e-09  yes
wang: parameter lambda                       0.38818757     0.38818757      1.4e-12  yes
wang: price of min(X, a) *                    344.37927      344.37927      7.0e-13  yes
dual: parameter beta                          1.8856082      1.8856082      6.5e-14  yes
dual: price of min(X, a) *                    344.37927      344.37927      5.5e-14  yes
tvar: parameter p                            0.42964861     0.42964861      1.4e-09  yes
tvar: price of min(X, a) *                    344.37927      344.37927      1.0e-09  yes
quantity                                      aggregate      prospicio   difference  pass
assets, the 99% quantile                           5440           5440      0.0e+00  yes
F(assets)                                    0.99001495     0.99001495      2.2e-16  yes
expected loss E[min(X, a)]                     941.8839       941.8839      3.3e-14  yes
CCoC premium                                  1350.8035      1350.8035      2.3e-14  yes
capital *                                     4089.1965      4089.1965      7.6e-15  yes
return on capital *                                 0.1            0.1      8.6e-15  yes
gross: assets 5,440.00, expected loss 941.88, premium 1,350.80, capital 4,089.20
    loss ratio 69.7%, margin 408.92 (10% of the capital)
  family calibrated                           g(0.05)  price of min(X, a)   unlimited
    ccoc ccoc(r=0.100000)                     0.13636         1350.803545         n/a
      ph proportional_hazard(rho=0.698670)    0.12331         1350.803545   1400.8786
    wang wang(lambda=0.420286)                0.11037         1350.803545   1378.2250
    dual dual_power(beta=1.892345)            0.09250         1350.803545   1366.4344
    tvar tvar(p=0.381412)                     0.08083         1350.803545   1364.1839
quantity                                      aggregate      prospicio   difference  pass
ccoc: parameter r *                                 0.1            0.1      3.1e-15  yes
ccoc: price of min(X, a) *                    1350.8035      1350.8035      1.7e-13  yes
ph: parameter rho                            0.69866992     0.69866992      2.1e-14  yes
ph: price of min(X, a) *                      1350.8035      1350.8035      3.0e-13  yes
wang: parameter lambda                       0.42028567     0.42028567      2.4e-13  yes
wang: price of min(X, a) *                    1350.8035      1350.8035      2.4e-13  yes
dual: parameter beta                          1.8923451      1.8923451      7.2e-15  yes
dual: price of min(X, a) *                    1350.8035      1350.8035      3.2e-13  yes
tvar: parameter p                             0.3814116      0.3814116      8.0e-09  yes
tvar: price of min(X, a) *                    1350.8035      1350.8035      3.2e-09  yes

The CCoC premium agrees to rounding, and so do the calibrated distortions. Their parameters, read with Distortion.parameters, agree, and so does g(s) at aggregate’s parameter. The independent comparisons in this section are the parameter and g rows, the unlimited prices and the fixed-parameter prices. The other rows hold by construction and count as consistency checks:

  • each calibrated price of min(X, a) is the premium of its calibration,
  • the capital is a - P,
  • the return on capital is the 10% in the premium,
  • the calibrated and fixed CCoC give that 10%.

aggregate stops its Newton iteration at a premium error (4.3e-6 for the gross view’s TVaR), and prospicio bisects to rounding. Thus some calibrated parameters differ at the 1e-9 level, not to rounding. TVaR shows this most clearly. Its premium changes by more than a thousand per unit of its parameter, so that error moves the parameter and g only at the 1e-9 level.

The TVaR parameter differs by 8.0e-9 on the gross view and 1.4e-9 on the ceded view, and its g rows by 4.9e-9 and 1.0e-9. The proportional hazard on the ceded view is at the same level, for the same reason: its parameter differs by 1.3e-9 and its g(0.05) by 2.8e-9. All of these are inside the 1e-6 of the other families. The error also shows in aggregate’s price of min(X, a) for these distortions, which is off the target premium in the ninth digit. The price from prospicio is on the target.

Summary of every comparison

The table below lists each quantity that this notebook compares. It shows the value of aggregate from the reference file and the value of prospicio. It also shows the difference (relative, or in buckets for quantiles) and whether the difference is inside the tolerance for its type. First, the totals by section.

from collections import OrderedDict

independent = [r for r in COMPARISONS if not r["check"]]
checks = [r for r in COMPARISONS if r["check"]]

by_section = OrderedDict()
for r in independent:
    by_section.setdefault(r["section"], []).append(r)
print("independent comparisons by section")
print(f"{'section':32s} {'compared':>9s} {'passed':>7s}  worst relative difference")
for section, rows in by_section.items():
    worst = max((r for r in rows if r["unit"] == "rel"), key=lambda r: r["diff"])
    print(f"{section:32s} {len(rows):9d} {sum(r['ok'] for r in rows):7d}  {worst['diff']:.1e} ({worst['name']})")

print("\nindependent comparisons by tolerance class")
print(f"{'class':16s} {'tolerance':>12s} {'rows':>5s} {'worst':>12s}  where")
for cls, (tol, unit) in TOLERANCES.items():
    rows = [r for r in independent if r["cls"] == cls]
    worst = max(rows, key=lambda r: r["diff"])
    fmt = (lambda v: f"{v:.1e}") if unit == "rel" else (lambda v: f"{v:g} bkt")
    print(f"{cls:16s} {fmt(tol):>12s} {len(rows):5d} {fmt(worst['diff']):>12s}  {worst['section']}: {worst['name']}")

failed = [r for r in COMPARISONS if not r["ok"]]
print(f"\n{sum(r['ok'] for r in COMPARISONS)} of {len(COMPARISONS)} comparisons are inside their tolerance: "
      f"{len(independent)} independent comparisons and {len(checks)} consistency checks that hold by construction"
      + ("" if not failed else f"; outside: {[r['name'] for r in failed]}"))
independent comparisons by section
section                           compared  passed  worst relative difference
1 tower                                 77      77  1.8e-06 (layer 250 xs 250 skew)
2 program                               52      52  2.6e-06 (80% of 1000 xs 1000 sd)
3 limit and reinstatements              32      32  6.1e-07 (gross skew)
4 stop loss                             46      46  9.5e-06 (50% of 1500 xs 1000 skew)
4 aggregate deductible                  31      31  8.4e-10 (gross skew)
5 retro and swing                       15      15  2.0e-10 (layer loss skew)
5 profit commission                     13      13  7.3e-10 (three-year loss skew)
5 sliding scale                         15      15  6.5e-10 (ceded loss skew)
6 ceded view                            24      24  2.8e-09 (ph: g(0.05) at aggregate's parameter)
6 gross view                            24      24  1.6e-08 (ph: unlimited price)

independent comparisons by tolerance class
class               tolerance  rows        worst  where
mean                  1.0e-06   153      4.1e-08  3 limit and reinstatements: P(limit used up)
sd                    1.0e-06    46      3.1e-08  3 limit and reinstatements: recovery under 2800 sd
share sd              1.0e-05     4      7.4e-06  4 stop loss: 50% of 1500 xs 1000 cv
skew                  2.0e-05    25      9.5e-06  4 stop loss: 50% of 1500 xs 1000 skew
quantile                0 bkt    92        0 bkt  1 tower: gross q0.5
share quantile          1 bkt     8      0.5 bkt  4 stop loss: 50% of 1500 xs 1000 q0.99
tail                  1.0e-05     1      5.7e-07  3 limit and reinstatements: loss above the limit

353 of 353 comparisons are inside their tolerance: 329 independent comparisons and 24 consistency checks that hold by construction
print(f"{'quantity':52s} {'aggregate':>15s} {'prospicio':>15s} {'difference':>11s} {'tolerance':>10s}  pass")
last = None
for r in COMPARISONS:
    if r["section"] != last:
        print(f"-- {r['section']}")
        last = r["section"]
    diff = f"{r['diff']:.1e}" if r["unit"] == "rel" else f"{r['diff']:.2f} bkt"
    tol = f"{r['tol']:.0e}" if r["unit"] == "rel" else f"{r['tol']} bkt"
    name = r["name"] + (" *" if r["check"] else "")
    print(f"{name:52s} {r['aggregate']:15.9g} {r['prospicio']:15.9g} {diff:>11s} {tol:>10s}  "
          f"{'yes' if r['ok'] else 'NO'}")
quantity                                                   aggregate       prospicio  difference  tolerance  pass
-- 1 tower
mean claim, exact                                         95.0575471      95.0575471     2.2e-15      1e-06  yes
mean claim, grid                                          95.0160815      95.0160815     2.2e-15      1e-06  yes
annual gross mean, exact                                  950.575471      950.575471     2.2e-15      1e-06  yes
gross mean                                                950.160815      950.160815     3.0e-12      1e-06  yes
gross sd                                                  1016.61564      1016.61564     2.2e-10      1e-06  yes
gross cv                                                  1.06994061      1.06994061     2.2e-10      1e-06  yes
gross skew                                                2.86453019      2.86453029     3.5e-08      2e-05  yes
gross q0.5                                                       632             632    0.00 bkt      0 bkt  yes
gross q0.9                                                      2024            2024    0.00 bkt      0 bkt  yes
gross q0.99                                                     5440            5440    0.00 bkt      0 bkt  yes
gross q0.999                                                    7412            7412    0.00 bkt      0 bkt  yes
layer 250 xs 0 mean                                       544.169708      544.169708     2.1e-16      1e-06  yes
layer 250 xs 0 sd                                         292.749408      292.749408     7.8e-16      1e-06  yes
layer 250 xs 0 cv                                        0.537974466     0.537974466     6.2e-16      1e-06  yes
layer 250 xs 0 skew                                      0.710964593     0.710964593     1.3e-13      2e-05  yes
layer 250 xs 0 q0.5                                              508             508    0.00 bkt      0 bkt  yes
layer 250 xs 0 q0.9                                              940             940    0.00 bkt      0 bkt  yes
layer 250 xs 0 q0.99                                            1364            1364    0.00 bkt      0 bkt  yes
layer 250 xs 0 q0.999                                           1716            1716    0.00 bkt      0 bkt  yes
layer 250 xs 0 mean, exact                                544.588728      544.588728     2.1e-16      1e-06  yes
layer 250 xs 0 loss on line                               2.17667883      2.17667883     2.0e-16      1e-06  yes
layer 250 xs 0 P(claim reaches layer)                    0.897027061     0.897027061     3.7e-16      1e-06  yes
layer 250 xs 0 P(claim exhausts layer)                  0.0792484907    0.0792484907     2.6e-15      1e-06  yes
layer 250 xs 0 mean given it reaches                      60.6636891      60.6636891     2.8e-15      1e-06  yes
layer 250 xs 250 mean                                     133.052954      133.052954     1.3e-12      1e-06  yes
layer 250 xs 250 sd                                       170.238397      170.238397     7.9e-10      1e-06  yes
layer 250 xs 250 cv                                       1.27947852      1.27947852     7.9e-10      1e-06  yes
layer 250 xs 250 skew                                     1.37423613      1.37423855     1.8e-06      2e-05  yes
layer 250 xs 250 q0.5                                             36              36    0.00 bkt      0 bkt  yes
layer 250 xs 250 q0.9                                            356             356    0.00 bkt      0 bkt  yes
layer 250 xs 250 q0.99                                           692             692    0.00 bkt      0 bkt  yes
layer 250 xs 250 q0.999                                          952             952    0.00 bkt      0 bkt  yes
layer 250 xs 250 mean, exact                              133.048003      133.048003     3.0e-15      1e-06  yes
layer 250 xs 250 loss on line                            0.532211816     0.532211816     1.3e-12      1e-06  yes
layer 250 xs 250 P(claim reaches layer)                 0.0792484907    0.0792484907     2.6e-15      1e-06  yes
layer 250 xs 250 P(claim exhausts layer)                0.0365716904    0.0365716904     9.5e-16      1e-06  yes
layer 250 xs 250 mean given it reaches                     167.89336       167.89336     2.2e-15      1e-06  yes
layer 500 xs 500 mean                                     114.811395      114.811395     3.3e-12      1e-06  yes
layer 500 xs 500 sd                                       220.909338      220.909338     1.0e-09      1e-06  yes
layer 500 xs 500 cv                                       1.92410639      1.92410639     1.0e-09      1e-06  yes
layer 500 xs 500 skew                                     2.09263087      2.09263327     1.1e-06      2e-05  yes
layer 500 xs 500 q0.5                                              0               0    0.00 bkt      0 bkt  yes
layer 500 xs 500 q0.9                                            500             500    0.00 bkt      0 bkt  yes
layer 500 xs 500 q0.99                                          1000            1000    0.00 bkt      0 bkt  yes
layer 500 xs 500 q0.999                                         1324            1324    0.00 bkt      0 bkt  yes
layer 500 xs 500 mean, exact                              114.811846      114.811846     3.1e-15      1e-06  yes
layer 500 xs 500 loss on line                            0.229622789     0.229622789     3.3e-12      1e-06  yes
layer 500 xs 500 P(claim reaches layer)                 0.0362180768    0.0362180768     1.7e-15      1e-06  yes
layer 500 xs 500 P(claim exhausts layer)                0.0147381505    0.0147381505     5.9e-16      1e-06  yes
layer 500 xs 500 mean given it reaches                    317.000251      317.000251     2.3e-15      1e-06  yes
layer 1000 xs 1000 mean                                   87.0917548      87.0917548     4.1e-15      1e-06  yes
layer 1000 xs 1000 sd                                      268.63194       268.63194     2.3e-15      1e-06  yes
layer 1000 xs 1000 cv                                      3.0844704       3.0844704     1.7e-15      1e-06  yes
layer 1000 xs 1000 skew                                   3.39868892      3.39868892     2.0e-14      2e-05  yes
layer 1000 xs 1000 q0.5                                            0               0    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 q0.9                                          264             264    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 q0.99                                        1000            1000    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 q0.999                                       2000            2000    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 mean, exact                            87.0918646      87.0918646     9.0e-15      1e-06  yes
layer 1000 xs 1000 loss on line                         0.0870917548    0.0870917548     4.0e-15      1e-06  yes
layer 1000 xs 1000 P(claim reaches layer)               0.0146556884    0.0146556884     3.8e-15      1e-06  yes
layer 1000 xs 1000 P(claim exhausts layer)             0.00520921908   0.00520921908     7.0e-15      1e-06  yes
layer 1000 xs 1000 mean given it reaches                  594.252229      594.252229     2.5e-15      1e-06  yes
layer 3000 xs 2000 mean                                   71.0350036      71.0350036     1.5e-11      1e-06  yes
layer 3000 xs 2000 sd                                      397.74982       397.74982     8.9e-10      1e-06  yes
layer 3000 xs 2000 cv                                     5.59934962      5.59934962     8.8e-10      1e-06  yes
layer 3000 xs 2000 skew                                   6.53530883      6.53530999     1.8e-07      2e-05  yes
layer 3000 xs 2000 q0.5                                            0               0    0.00 bkt      0 bkt  yes
layer 3000 xs 2000 q0.9                                            0               0    0.00 bkt      0 bkt  yes
layer 3000 xs 2000 q0.99                                        3000            3000    0.00 bkt      0 bkt  yes
layer 3000 xs 2000 q0.999                                       3000            3000    0.00 bkt      0 bkt  yes
layer 3000 xs 2000 mean, exact                            71.0350286      71.0350286     3.0e-14      1e-06  yes
layer 3000 xs 2000 loss on line                         0.0236783345    0.0236783345     1.5e-11      1e-06  yes
layer 3000 xs 2000 P(claim reaches layer)              0.00519262547   0.00519262547     5.2e-15      1e-06  yes
layer 3000 xs 2000 P(claim exhausts layer)             0.00107176323   0.00107176323     4.0e-15      1e-06  yes
layer 3000 xs 2000 mean given it reaches                  1367.99783      1367.99783     3.8e-15      1e-06  yes
sum of layers equals gross                                950.160815      950.160815     2.3e-12      1e-06  yes
-- 2 program
gross mean                                                950.160815      950.160815     3.0e-12      1e-06  yes
gross sd                                                  1016.61564      1016.61564     2.2e-10      1e-06  yes
gross cv                                                  1.06994061      1.06994061     2.2e-10      1e-06  yes
gross skew                                                2.86453019      2.86453029     3.5e-08      2e-05  yes
gross q0.5                                                       632             632    0.00 bkt      0 bkt  yes
gross q0.9                                                      2024            2024    0.00 bkt      0 bkt  yes
gross q0.99                                                     5440            5440    0.00 bkt      0 bkt  yes
gross q0.999                                                    7412            7412    0.00 bkt      0 bkt  yes
ceded mean                                                201.903149      201.903149     2.8e-13      1e-06  yes
ceded sd                                                  456.131351      456.131351     3.7e-11      1e-06  yes
ceded cv                                                  2.25915917      2.25915917     3.6e-11      1e-06  yes
ceded skew                                                2.76086191      2.76086196     1.5e-08      2e-05  yes
ceded q0.5                                                         0               0    0.00 bkt      0 bkt  yes
ceded q0.9                                                       816             816    0.00 bkt      0 bkt  yes
ceded q0.99                                                     1824            1824    0.00 bkt      0 bkt  yes
ceded q0.999                                                    3000            3000    0.00 bkt      0 bkt  yes
net mean                                                  748.257665      748.257665     2.4e-12      1e-06  yes
net sd                                                    640.658558      640.658558     5.7e-10      1e-06  yes
net cv                                                    0.85620046     0.856200461     5.7e-10      1e-06  yes
net skew                                                  2.94012904      2.94012951     1.6e-07      2e-05  yes
net q0.5                                                         616             616    0.00 bkt      0 bkt  yes
net q0.9                                                        1360            1360    0.00 bkt      0 bkt  yes
net q0.99                                                       3836            3836    0.00 bkt      0 bkt  yes
net q0.999                                                      4948            4948    0.00 bkt      0 bkt  yes
ceded mean, exact                                         201.903711      201.903711     2.1e-15      1e-06  yes
net mean, exact                                            748.67176       748.67176     3.3e-15      1e-06  yes
net mean claim, grid                                      74.8257665      74.8257665     2.5e-15      1e-06  yes
layer 500 xs 500 mean                                     114.811395      114.811395     3.3e-12      1e-06  yes
layer 500 xs 500 sd                                       220.909338      220.909338     1.0e-09      1e-06  yes
layer 500 xs 500 cv                                       1.92410639      1.92410639     1.0e-09      1e-06  yes
layer 500 xs 500 skew                                     2.09263087      2.09263327     1.1e-06      2e-05  yes
layer 500 xs 500 q0.5                                              0               0    0.00 bkt      0 bkt  yes
layer 500 xs 500 q0.9                                            500             500    0.00 bkt      0 bkt  yes
layer 500 xs 500 q0.99                                          1000            1000    0.00 bkt      0 bkt  yes
layer 500 xs 500 q0.999                                         1324            1324    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 mean                                   87.0917548      87.0917548     4.1e-15      1e-06  yes
layer 1000 xs 1000 sd                                      268.63194       268.63194     2.3e-15      1e-06  yes
layer 1000 xs 1000 cv                                      3.0844704       3.0844704     1.7e-15      1e-06  yes
layer 1000 xs 1000 skew                                   3.39868892      3.39868892     2.0e-14      2e-05  yes
layer 1000 xs 1000 q0.5                                            0               0    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 q0.9                                          264             264    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 q0.99                                        1000            1000    0.00 bkt      0 bkt  yes
layer 1000 xs 1000 q0.999                                       2000            2000    0.00 bkt      0 bkt  yes
80% of 1000 xs 1000 mean                                  69.6734038      69.6734038     2.9e-13      1e-06  yes
80% of 1000 xs 1000 sd                                    214.906117      214.905552     2.6e-06      1e-05  yes
80% of 1000 xs 1000 cv                                    3.08447852       3.0844704     2.6e-06      1e-05  yes
80% of 1000 xs 1000 skew                                   3.3986838      3.39868892     1.5e-06      2e-05  yes
80% of 1000 xs 1000 q0.5                                           0               0    0.00 bkt      1 bkt  yes
80% of 1000 xs 1000 q0.9                                         212           211.2    0.20 bkt      1 bkt  yes
80% of 1000 xs 1000 q0.99                                        800             800    0.00 bkt      1 bkt  yes
80% of 1000 xs 1000 q0.999                                      1600            1600    0.00 bkt      1 bkt  yes
80% of 1000 xs 1000 mean, exact                           69.6734916      69.6734916     9.0e-15      1e-06  yes
-- 3 limit and reinstatements
class 1 expected claims                                  0.737010742     0.737010742     6.0e-16      1e-06  yes
class 2 expected claims                                   0.92362085      0.92362085     1.3e-15      1e-06  yes
class 3 expected claims                                   1.23422126      1.23422126     9.0e-16      1e-06  yes
expected claims                                           2.89485285      2.89485285     3.1e-16      1e-06  yes
gross mean, exact                                                900             900     1.3e-16      1e-06  yes
gross CV, exact                                          0.769693799     0.769693799     1.4e-16      1e-06  yes
gross mean                                                899.999992      899.999992     6.3e-14      1e-06  yes
gross sd                                                   692.72442       692.72442     1.4e-13      1e-06  yes
gross cv                                                 0.769693806     0.769693806     2.0e-13      1e-06  yes
gross skew                                               0.902068335     0.902068889     6.1e-07      2e-05  yes
gross q0.5                                                    785.75          785.75    0.00 bkt      0 bkt  yes
gross q0.9                                                      1843            1843    0.00 bkt      0 bkt  yes
gross q0.99                                                 2917.125        2917.125    0.00 bkt      0 bkt  yes
gross q0.999                                                 3816.25         3816.25    0.00 bkt      0 bkt  yes
recovery under 2800 mean                                  894.680681      894.680678     3.4e-09      1e-06  yes
recovery under 2800 sd                                    674.945841      674.945821     3.1e-08      1e-06  yes
recovery under 2800 cv                                   0.754398587     0.754398566     2.7e-08      1e-06  yes
recovery under 2800 skew                                 0.721428616     0.721428617     1.1e-09      2e-05  yes
recovery under 2800 q0.5                                      785.75          785.75    0.00 bkt      0 bkt  yes
recovery under 2800 q0.9                                        1843            1843    0.00 bkt      0 bkt  yes
recovery under 2800 q0.99                                       2800            2800    0.00 bkt      0 bkt  yes
recovery under 2800 q0.999                                      2800            2800    0.00 bkt      0 bkt  yes
P(limit used up)                                        0.0137006006    0.0137006011     4.1e-08      1e-06  yes
loss above the limit                                      5.31931137      5.31931442     5.7e-07      1e-05  yes
A: expected reinstatement premium                         1495.56926      1495.56926     1.4e-09      1e-06  yes
A: total premium                                          2695.56926      2695.56926     7.5e-10      1e-06  yes
A: recovery                                               894.680676      894.680678     1.8e-09      1e-06  yes
A: P(any loss to the layer)                              0.943513922     0.943513923     6.0e-10      1e-06  yes
A: maximum premium *                                            3600            3600     0.0e+00      1e-06  yes
B: expected reinstatement premium                         371.581024      371.581025     2.7e-09      1e-06  yes
B: total premium                                          1571.58102      1571.58102     6.5e-10      1e-06  yes
B: recovery                                               894.680676      894.680678     1.8e-09      1e-06  yes
B: P(any loss to the layer)                              0.943513922     0.943513923     6.0e-10      1e-06  yes
B: maximum premium *                                            1800            1800     0.0e+00      1e-06  yes
-- 4 stop loss
250 xs 750 mean                                           89.8060044      89.8060044     1.9e-14      1e-06  yes
250 xs 750 sd                                             114.595006      114.595006     5.2e-15      1e-06  yes
250 xs 750 cv                                             1.27602834      1.27602834     1.4e-14      1e-06  yes
250 xs 750 skew                                          0.589473355     0.589473355     6.1e-14      2e-05  yes
250 xs 750 q0.5                                                    0               0    0.00 bkt      0 bkt  yes
250 xs 750 q0.9                                                  252             252    0.00 bkt      0 bkt  yes
250 xs 750 q0.99                                                 252             252    0.00 bkt      0 bkt  yes
250 xs 750 q0.999                                                252             252    0.00 bkt      0 bkt  yes
250 xs 750 P(attach)                                     0.423786745     0.423786745     1.1e-13      1e-06  yes
250 xs 750 P(exhaust)                                    0.303654247     0.303654247     1.6e-13      1e-06  yes
250 xs 750 loss on line                                  0.359224017     0.359224017     1.8e-14      1e-06  yes
1500 xs 1000 mean                                         220.254897      220.254897     3.9e-14      1e-06  yes
1500 xs 1000 sd                                           447.605595      447.605595     2.3e-14      1e-06  yes
1500 xs 1000 cv                                           2.03221631      2.03221631     1.6e-14      1e-06  yes
1500 xs 1000 skew                                         2.02236699      2.02236699     3.3e-14      2e-05  yes
1500 xs 1000 q0.5                                                  0               0    0.00 bkt      0 bkt  yes
1500 xs 1000 q0.9                                               1024            1024    0.00 bkt      0 bkt  yes
1500 xs 1000 q0.99                                              1500            1500    0.00 bkt      0 bkt  yes
1500 xs 1000 q0.999                                             1500            1500    0.00 bkt      0 bkt  yes
1500 xs 1000 P(attach)                                   0.302087959     0.302087959     1.6e-13      1e-06  yes
1500 xs 1000 P(exhaust)                                 0.0672404384    0.0672404384     7.0e-13      1e-06  yes
1500 xs 1000 loss on line                                0.146836598     0.146836598     3.9e-14      1e-06  yes
both layers, ceded mean                                   310.060902      310.060902     3.2e-14      1e-06  yes
both layers, ceded sd                                     532.963233      532.963233     2.0e-14      1e-06  yes
both layers, ceded cv                                     1.71889855      1.71889855     1.2e-14      1e-06  yes
both layers, ceded skew                                   1.74057348      1.74057348     3.0e-14      2e-05  yes
both layers, ceded q0.5                                            0               0    0.00 bkt      0 bkt  yes
both layers, ceded q0.9                                         1272            1272    0.00 bkt      0 bkt  yes
both layers, ceded q0.99                                        1752            1752    0.00 bkt      0 bkt  yes
both layers, ceded q0.999                                       1752            1752    0.00 bkt      0 bkt  yes
both layers, net mean                                     640.099913      640.099913     2.2e-12      1e-06  yes
both layers, net sd                                       582.753147      582.753148     5.4e-10      1e-06  yes
both layers, net cv                                      0.910409665     0.910409666     5.4e-10      1e-06  yes
both layers, net skew                                     4.80690861      4.80690909     9.9e-08      2e-05  yes
both layers, net q0.5                                            632             632    0.00 bkt      0 bkt  yes
both layers, net q0.9                                            752             752    0.00 bkt      0 bkt  yes
both layers, net q0.99                                          3692            3692    0.00 bkt      0 bkt  yes
both layers, net q0.999                                         5664            5664    0.00 bkt      0 bkt  yes
50% of 1500 xs 1000 mean                                  110.127449      110.127449     3.9e-14      1e-06  yes
50% of 1500 xs 1000 sd                                    223.804451      223.802797     7.4e-06      1e-05  yes
50% of 1500 xs 1000 cv                                    2.03223132      2.03221631     7.4e-06      1e-05  yes
50% of 1500 xs 1000 skew                                  2.02238626      2.02236699     9.5e-06      2e-05  yes
50% of 1500 xs 1000 q0.5                                           0               0    0.00 bkt      1 bkt  yes
50% of 1500 xs 1000 q0.9                                         512             512    0.00 bkt      1 bkt  yes
50% of 1500 xs 1000 q0.99                                        752             750    0.50 bkt      1 bkt  yes
50% of 1500 xs 1000 q0.999                                       752             750    0.50 bkt      1 bkt  yes
-- 4 aggregate deductible
class 1 expected claims                                   5.15407999      5.15407999     1.7e-16      1e-06  yes
class 2 expected claims                                   1.34250795      1.34250795     4.8e-15      1e-06  yes
gross mean, exact                                                450             450     0.0e+00      1e-06  yes
gross CV, exact                                          0.528497476     0.528497476     2.1e-16      1e-06  yes
gross mean                                                449.999977      449.999977     2.2e-12      1e-06  yes
gross sd                                                  237.823868      237.823868     2.2e-11      1e-06  yes
gross cv                                                 0.528497511     0.528497511     2.0e-11      1e-06  yes
gross skew                                                0.62441101     0.624411011     8.4e-10      2e-05  yes
gross q0.5                                                  424.1875        424.1875    0.00 bkt      0 bkt  yes
gross q0.9                                                       769             769    0.00 bkt      0 bkt  yes
gross q0.99                                                 1103.625        1103.625    0.00 bkt      0 bkt  yes
gross q0.999                                               1376.8125       1376.8125    0.00 bkt      0 bkt  yes
after the deductible mean                                 142.758967      142.758967     9.9e-13      1e-06  yes
after the deductible sd                                   183.779608      183.779608     7.1e-12      1e-06  yes
after the deductible cv                                   1.28734196      1.28734196     6.1e-12      1e-06  yes
after the deductible skew                                 1.53384449      1.53384449     1.6e-10      2e-05  yes
after the deductible q0.5                                    64.1875         64.1875    0.00 bkt      0 bkt  yes
after the deductible q0.9                                        409             409    0.00 bkt      0 bkt  yes
after the deductible q0.99                                   743.625         743.625    0.00 bkt      0 bkt  yes
after the deductible q0.999                                1016.8125       1016.8125    0.00 bkt      0 bkt  yes
value of the deductible                                    307.24101       307.24101     3.5e-14      1e-06  yes
excess ratio (insurance charge)                          0.317242165     0.317242165     4.6e-12      1e-06  yes
Poisson, after the deductible mean                        141.799478      141.799478     9.5e-13      1e-06  yes
Poisson, after the deductible sd                          181.420921      181.420921     6.9e-12      1e-06  yes
Poisson, after the deductible cv                          1.27941883      1.27941883     6.0e-12      1e-06  yes
Poisson, after the deductible skew                        1.51528126      1.51528126     1.6e-10      2e-05  yes
Poisson, after the deductible q0.5                            65.125          65.125    0.00 bkt      0 bkt  yes
Poisson, after the deductible q0.9                          404.8125        404.8125    0.00 bkt      0 bkt  yes
Poisson, after the deductible q0.99                            732.5           732.5    0.00 bkt      0 bkt  yes
Poisson, after the deductible q0.999                        998.8125        998.8125    0.00 bkt      0 bkt  yes
Poisson gross mean                                        449.999977      449.999977     2.8e-13      1e-06  yes
-- 5 retro and swing
layer loss mean                                           449.999977      449.999977     3.3e-13      1e-06  yes
layer loss sd                                             234.831337      234.831337     3.9e-12      1e-06  yes
layer loss cv                                            0.521847442     0.521847442     3.5e-12      1e-06  yes
layer loss skew                                          0.607746445     0.607746445     2.0e-10      2e-05  yes
layer loss q0.5                                              425.125         425.125    0.00 bkt      0 bkt  yes
layer loss q0.9                                             764.8125        764.8125    0.00 bkt      0 bkt  yes
layer loss q0.99                                              1092.5          1092.5    0.00 bkt      0 bkt  yes
layer loss q0.999                                          1358.8125       1358.8125    0.00 bkt      0 bkt  yes
retro premium                                              624.50973       624.50973     4.6e-13      1e-06  yes
retro premium, LossSensitivePremium                        624.50973       624.50973     6.9e-14      1e-06  yes
retro rate on subject premium                           0.0520424775    0.0520424775     4.6e-13      1e-06  yes
P(minimum premium)                                       0.239650834     0.239650834     1.7e-15      1e-06  yes
P(maximum premium)                                      0.0418237453    0.0418237453     8.6e-13      1e-06  yes
swing premium, 100% placed                                838.319362      838.319362     3.4e-13      1e-06  yes
swing premium, 40% placed                                 335.327745      335.327745     3.5e-13      1e-06  yes
-- 5 profit commission
three-year loss mean                                      2699.99991      2699.99991     1.8e-12      1e-06  yes
three-year loss sd                                        1194.86167      1194.86167     1.8e-11      1e-06  yes
three-year loss cv                                       0.442541373     0.442541373     1.6e-11      1e-06  yes
three-year loss skew                                     0.516204689     0.516204689     7.3e-10      2e-05  yes
three-year loss q0.5                                          2595.5          2595.5    0.00 bkt      0 bkt  yes
three-year loss q0.9                                          4292.5          4292.5    0.00 bkt      0 bkt  yes
three-year loss q0.99                                        5900.25         5900.25    0.00 bkt      0 bkt  yes
three-year loss q0.999                                          7195            7195    0.00 bkt      0 bkt  yes
ceded loss ratio                                         0.479999984     0.479999984     3.4e-13      1e-06  yes
profit commission                                         370.724957      370.724957     1.4e-15      1e-06  yes
profit commission rate                                  0.0823833237    0.0823833237     1.3e-15      1e-06  yes
rate at the expected loss ratio                          0.080000004     0.080000004     5.1e-13      1e-06  yes
P(profit commission > 0)                                 0.922755956     0.922755956     1.2e-15      1e-06  yes
-- 5 sliding scale
expected claims                                            11.494352       11.494352     2.6e-15      1e-06  yes
ceded loss mean                                           2499.99875      2499.99875     3.5e-13      1e-06  yes
ceded loss sd                                             1212.89973      1212.89973     8.4e-12      1e-06  yes
ceded loss cv                                            0.485160135     0.485160135     8.1e-12      1e-06  yes
ceded loss skew                                          0.648568507     0.648568507     6.5e-10      2e-05  yes
ceded loss q0.5                                                 2367            2367    0.00 bkt      0 bkt  yes
ceded loss q0.9                                               4128.5          4128.5    0.00 bkt      0 bkt  yes
ceded loss q0.99                                                5855            5855    0.00 bkt      0 bkt  yes
ceded loss q0.999                                             7272.5          7272.5    0.00 bkt      0 bkt  yes
ceded loss ratio                                         0.499999751     0.499999751     3.5e-13      1e-06  yes
expected commission                                       1517.10427      1517.10427     9.2e-14      1e-06  yes
expected commission rate                                 0.303420854     0.303420854     9.2e-14      1e-06  yes
rate at the expected loss ratio                          0.287500187     0.287500187     4.6e-13      1e-06  yes
P(loss ratio <= 35%)                                     0.295079988     0.295079988     8.1e-15      1e-06  yes
P(loss ratio >= 65%)                                     0.248544663     0.248544663     1.1e-13      1e-06  yes
-- 6 ceded view
assets, the 99% quantile                                        1824            1824     0.0e+00      1e-06  yes
F(assets)                                                0.990037317     0.990037317     4.0e-15      1e-06  yes
expected loss E[min(X, a)]                                196.417196      196.417196     1.2e-13      1e-06  yes
CCoC premium                                              344.379269      344.379269     6.5e-14      1e-06  yes
capital *                                                 1479.62073      1479.62073     1.5e-14      1e-06  yes
return on capital *                                              0.1             0.1     4.7e-15      1e-06  yes
ccoc: g(0.05) at aggregate's parameter *                 0.136363636     0.136363636     4.1e-16      1e-06  yes
ccoc: g(0.5) at aggregate's parameter *                  0.545454545     0.545454545     2.0e-16      1e-06  yes
ccoc: parameter r *                                              0.1             0.1     6.9e-16      1e-06  yes
ccoc: price of min(X, a) *                                344.379269      344.379269     1.7e-16      1e-06  yes
ph: g(0.05) at aggregate's parameter                     0.113901694     0.113901694     2.8e-09      1e-06  yes
ph: g(0.5) at aggregate's parameter                      0.604925149     0.604925148     6.5e-10      1e-06  yes
ph: parameter rho                                        0.725171455     0.725171456     1.3e-09      1e-06  yes
ph: price of min(X, a) *                                   344.37927      344.379269     2.0e-09      1e-06  yes
ph: unlimited price                                       369.852591      369.852591     8.8e-10      1e-06  yes
wang: g(0.05) at aggregate's parameter                   0.104437292     0.104437292     9.2e-13      1e-06  yes
wang: g(0.5) at aggregate's parameter                    0.651061385     0.651061385     3.0e-13      1e-06  yes
wang: parameter lambda                                   0.388187572     0.388187572     1.4e-12      1e-06  yes
wang: price of min(X, a) *                                344.379269      344.379269     7.0e-13      1e-06  yes
wang: unlimited price                                     360.449861      360.449861     3.4e-12      1e-06  yes
dual: g(0.05) at aggregate's parameter                  0.0921889858    0.0921889858     6.1e-14      1e-06  yes
dual: g(0.5) at aggregate's parameter                    0.729370351     0.729370351     3.2e-14      1e-06  yes
dual: parameter beta                                      1.88560819      1.88560819     6.5e-14      1e-06  yes
dual: price of min(X, a) *                                344.379269      344.379269     5.5e-14      1e-06  yes
dual: unlimited price                                      354.69921       354.69921     4.7e-13      1e-06  yes
tvar: g(0.05) at aggregate's parameter                  0.0876652545    0.0876652544     1.0e-09      1e-06  yes
tvar: g(0.5) at aggregate's parameter                    0.876652545     0.876652544     1.0e-09      1e-06  yes
tvar: parameter p                                        0.429648607     0.429648606     1.4e-09      1e-06  yes
tvar: price of min(X, a) *                                 344.37927      344.379269     1.0e-09      1e-06  yes
tvar: unlimited price                                     353.997819      353.997819     1.0e-09      1e-06  yes
fixed ph0.7: price of min(X, a)                           363.110828      363.110828     1.4e-15      1e-06  yes
fixed wang0.4: price of min(X, a)                         349.740174      349.740174     2.6e-15      1e-06  yes
fixed dual1.8: price of min(X, a)                         331.010339      331.010339     1.7e-15      1e-06  yes
fixed tvar0.3: price of min(X, a)                         280.595994      280.595994     6.1e-16      1e-06  yes
fixed ccoc0.1: price of min(X, a) *                       344.379269      344.379269     1.2e-15      1e-06  yes
-- 6 gross view
assets, the 99% quantile                                        5440            5440     0.0e+00      1e-06  yes
F(assets)                                                0.990014951     0.990014951     2.2e-16      1e-06  yes
expected loss E[min(X, a)]                                941.883899      941.883899     3.3e-14      1e-06  yes
CCoC premium                                              1350.80354      1350.80354     2.3e-14      1e-06  yes
capital *                                                 4089.19646      4089.19646     7.6e-15      1e-06  yes
return on capital *                                              0.1             0.1     8.6e-15      1e-06  yes
ccoc: g(0.05) at aggregate's parameter *                 0.136363636     0.136363636     1.6e-15      1e-06  yes
ccoc: g(0.5) at aggregate's parameter *                  0.545454545     0.545454545     2.0e-16      1e-06  yes
ccoc: parameter r *                                              0.1             0.1     3.1e-15      1e-06  yes
ccoc: price of min(X, a) *                                1350.80354      1350.80354     1.7e-13      1e-06  yes
ph: g(0.05) at aggregate's parameter                     0.123313176     0.123313176     4.5e-14      1e-06  yes
ph: g(0.5) at aggregate's parameter                      0.616139992     0.616139992     1.0e-14      1e-06  yes
ph: parameter rho                                        0.698669916     0.698669916     2.1e-14      1e-06  yes
ph: price of min(X, a) *                                  1350.80354      1350.80354     3.0e-13      1e-06  yes
ph: unlimited price                                       1400.87857      1400.87859     1.6e-08      1e-06  yes
wang: g(0.05) at aggregate's parameter                   0.110369024     0.110369024     1.7e-13      1e-06  yes
wang: g(0.5) at aggregate's parameter                    0.662861612     0.662861612     5.5e-14      1e-06  yes
wang: parameter lambda                                   0.420285672     0.420285672     2.4e-13      1e-06  yes
wang: price of min(X, a) *                                1350.80354      1350.80354     2.4e-13      1e-06  yes
wang: unlimited price                                     1378.22496      1378.22496     3.3e-11      1e-06  yes
dual: g(0.05) at aggregate's parameter                   0.092502634     0.092502634     5.9e-15      1e-06  yes
dual: g(0.5) at aggregate's parameter                     0.73063116      0.73063116     3.5e-15      1e-06  yes
dual: parameter beta                                      1.89234512      1.89234512     7.2e-15      1e-06  yes
dual: price of min(X, a) *                                1350.80354      1350.80354     3.2e-13      1e-06  yes
dual: unlimited price                                     1366.43439      1366.43439     4.0e-12      1e-06  yes
tvar: g(0.05) at aggregate's parameter                  0.0808291916    0.0808291912     4.9e-09      1e-06  yes
tvar: g(0.5) at aggregate's parameter                    0.808291916     0.808291912     4.9e-09      1e-06  yes
tvar: parameter p                                        0.381411604     0.381411601     8.0e-09      1e-06  yes
tvar: price of min(X, a) *                                1350.80355      1350.80354     3.2e-09      1e-06  yes
tvar: unlimited price                                     1364.18388      1364.18387     3.2e-09      1e-06  yes
fixed ph0.7: price of min(X, a)                           1348.28798      1348.28798     3.2e-13      1e-06  yes
fixed wang0.4: price of min(X, a)                         1328.19389      1328.19389     3.2e-13      1e-06  yes
fixed dual1.8: price of min(X, a)                         1315.25173      1315.25173     3.1e-13      1e-06  yes
fixed tvar0.3: price of min(X, a)                         1244.59755      1244.59755     2.8e-13      1e-06  yes
fixed ccoc0.1: price of min(X, a) *                       1350.80354      1350.80354     1.7e-13      1e-06  yes

Where and why the numbers differ

All results are inside their tolerances. We set the tolerances after a first run, from the differences below. The summary prints the worst difference in each class beside its tolerance, and most results agree far better. The differences have six causes.

  1. The grid. The bucket size sets every grid value: the severity is rounded to it, and the loss above a limit sits on the limit. prospicio takes the bucket from the caller, so each section gives the bucket that aggregate chose, for parity only. recommend_grid and fft_auto can give a different bucket. For the book of section 1 they get only the unlimited lognormal, and they recommend a step of 2, where aggregate, which sees the policy limit, uses 4. A finer step is safer, but its values then differ from the values of aggregate by discretisation. On a shared grid the quantiles agree exactly. At every compared quantile the cdf is at least 6.7e-8 away from the probability, far above rounding, so no quantile sits on a tie.

  2. The grid mean is not the exact mean. est_m in aggregate and Grid.mean here are the mean of the rounded severity compounded: 950.16 against an exact 950.58 in section 1, 0.044% low, and 544.17 against 544.59 for the layer 250 xs 0. Contract terms are exact for the discretized severity, not for the continuous one. When the exact value is important, quote it (Lognormal.lev, Mixture.lev, layer), and compare grid with grid, as the tables do.

  3. A share off the grid. aggregate re-buckets a ceded amount between its buckets, which adds a little variance. prospicio gives a share its own step (share x bs), which adds no rounding. The means agree. In sections 2 and 4, the standard deviation differs by 2.6e-6 for the 80% share and 7.4e-6 for the 50% stop-loss share, the skewness by up to 9.5e-6, and a quantile by at most half a bucket.

  4. The tail beyond the grid. prospicio puts the probability beyond the last grid point on that point. aggregate (with normalize=False) removes it. The effect is the probability beyond the grid times the distance to the layer. Thus the stop loss at 2,800, deep in the tail of section 3, has a 1e-5 tolerance (5.7e-7 observed). The unnormalised setting gives the match. The default of aggregate, normalize=True, makes the tail thinner instead.

  5. Skewness. An FFT leaves rounding noise of order 1e-16 on every grid point. The noise goes up to the top of the grid at 2**16 x bs (262,144 for a bucket of 4). The two packages leave different noise. The third moment weights a point by the cube of its distance from the mean. Thus noise at the top of the grid moves the skewness of a light-tailed cover in the sixth digit. Against the skewness of aggregate’s density (*_skew_central in the reference file), the layer 250 xs 250 differs by about 2e-6. The noise depends on the platform: 1.5e-6 on Windows and 1.8e-6 on Linux. Remove prospicio’s probability above 10,000, and the difference falls under 1e-13 (the cell below). The annual loss of that layer cannot reach 10,000 with any real probability.

    The skew that aggregate quotes (*_skew) differs again, by up to 8.6e-7. The cause is xsden_to_meancvskew: it puts the mass that the density lacks (1 - sum(p)) one bucket past the grid, as truncation. Since aggregate 2.0 a deficit of 1e-12 or less counts as rounding and stays out, so the quoted skew equals the density’s to about 1e-11, except where the grid drops real tail mass: the stop loss at 2,800 of point 4 (normalize=False, a deficit of 5.7e-10). Version 1.0.1 also moved a rounding deficit of 1e-15, and its quoted skew differed by up to 8.1e-5. That is a convention, not a property of the distribution. Thus the notebook compares the skewness of the density, with a 2e-5 tolerance. The worst difference observed, 9.5e-6, is the 50% stop-loss share of point 3, where aggregate’s re-bucketing adds to the noise. Skewness is the one statistic with a tolerance from a modelling choice, not from the grid.

  6. Definitions. Some quantities have a specific meaning in aggregate, and the comparison uses the same meaning:

    • its quantiles are the lower quantile on the grid,
    • cond_sev_mean and the attachment probability are conditional on the claim reaching the layer,
    • net of holds the loss on the other side of the layer,
    • the “insurance charge” of an aggregate deductible is the excess ratio (the Table M charge), not the loss elimination ratio,
    • the probability of a reinstatement is the probability of any loss to the layer,
    • reinstatements are pro rata as to amount,
    • the placed share scales the terms of a swing premium, but not its loss conversion factor,
    • a profit commission does not deduct a ceding commission,
    • the calibration of the distortions stops at a premium error.
quoted = [(k, AGG[k] / AGG[(k[0], k[1] + "_central")] - 1.0) for k in AGG
          if k[1].endswith("_skew") and (k[0], k[1] + "_central") in AGG]
quoted.sort(key=lambda kv: -abs(kv[1]))
print(f"{len(quoted)} skewness values; aggregate's quoted skew is within {abs(quoted[0][1]):.1e} of its density's.")
print("largest differences, with the density deficit that aggregate places one bucket past the grid (above 1e-12):")
for (example, quantity), diff in quoted[:4]:
    deficit = AGG[(example, quantity.replace("_skew", "_density_deficit"))]
    beyond = POINTS * AGG[(example, "bs")]  # one bucket past the grid's top
    print(f"  {example} {quantity}: {diff:+.1e} (deficit {deficit:.1e} at {beyond:,.0f} adds about "
          f"{deficit * beyond**3:,.0f} to the third moment)")

# prospicio's skewness of 250 xs 250 against aggregate's density, with and without the noise at the top of the grid.
layer = tower_grids.ceded[1]
central = AGG[("tower_gross", "layer_250x250_ceded_skew_central")]
kept = [(i * layer.step, q) for i, q in enumerate(layer.probs) if i * layer.step < 10000.0]
mean = sum(x * q for x, q in kept)
var = sum((x - mean) ** 2 * q for x, q in kept)
below = sum((x - mean) ** 3 * q for x, q in kept) / var**1.5
whole = moments(layer)[3]
print(f"\nlayer 250 xs 250, skewness of aggregate's density {central:.10f}; prospicio's on the whole grid "
      f"{whole:.10f} ({whole / central - 1:+.1e}), below 10,000 {below:.10f} ({below / central - 1:+.1e}); "
      f"probability dropped {sum(q for i, q in enumerate(layer.probs) if i * layer.step >= 10000.0):.1e}")
27 skewness values; aggregate's quoted skew is within 8.6e-07 of its density's.
largest differences, with the density deficit that aggregate places one bucket past the grid (above 1e-12):
  agg_limit_reinst agglimit2800_ceded_skew: +8.6e-07 (deficit 5.7e-10 at 8,192 adds about 311 to the third moment)
  agg_limit_reinst gross_skew: +6.1e-07 (deficit 5.7e-10 at 8,192 adds about 311 to the third moment)
  variable_pc three_year_loss_skew: -8.7e-12 (deficit 2.9e-13 at 16,384 adds about 1 to the third moment)
  variable_retro ceded_loss_skew: -4.2e-12 (deficit 2.4e-13 at 4,096 adds about 0 to the third moment)

layer 250 xs 250, skewness of aggregate's density 1.3742361283; prospicio's on the whole grid 1.3742385535 (+1.8e-06), below 10,000 1.3742361283 (+3.3e-14); probability dropped 6.7e-16