Property catastrophe 7: Larkspur's whole book
cat-7-portfolio.RmdRendered from docs/guides/cat-7-portfolio.qmd.
The code runs each time the site is built, so the output below is
current.
This is the R twin of the Python guide cat-7-portfolio.md,
with the same sections, files and numbers. The text under each R chunk
is what the chunk prints. R/prospicio/tests/test-guides.R
checks that each chunk prints exactly that text.
Larkspur Re holds five contracts on three cedents, and one windstorm can hit all of them in the same year. This page adds the five contracts into one book, measures the tail of the book, splits its capital back to the contracts, and shows which contracts pay for their capital.
The story, the files and the notation are on the overview. The page types no number by
hand: every attachment, limit and share comes from
cat_book_contracts.csv.
1. The idea
Each row of the year event loss table belongs to one simulated year, and every contract sees the same 2,000 years. The loss of the book in a year is the sum of the losses of the five contracts. The events carry the dependence: one event in the catalog lands on several cedents at once. No copula or reordering is needed.
That is the only dependence here. The script that wrote the book draws each cedent’s loss from an event independently, so the correlated part of secondary uncertainty (page 1) is not correlated across cedents. A model that shares it would give the book a heavier tail.
Three questions follow from the sum.
- How bad is the bad year? TVaR at 99% of the summed loss: the mean of the worst 1% of years.
- Which contracts cause it? The Euler split: each contract’s mean loss in the years that make the tail of the book. Price allocation compares other splits.
- Does each contract pay for its capital? A return on allocated capital, against the premium charged.
2. The book
The chunk repeats the helpers of the earlier pages (each guide runs
on its own), builds a tower for each contract on its subject loss, and
wraps each result in a deal_run_from_tower(). A
deal_book() aligns the runs by year.
library(prospicio)
# The data files, found from the repository root (CI) or from docs/guides (Quarto).
find_data <- function(name, dir = getwd()) {
repeat {
path <- file.path(dir, "examples", "data", name)
if (file.exists(path)) return(path)
parent <- dirname(dir)
if (identical(parent, dir)) stop("examples/data/", name, " not found", call. = FALSE)
dir <- parent
}
}
read_text <- function(name) read.csv(find_data(name), colClasses = "character")
YELT <- read_text("cat_book_yelt.csv")
CONTRACTS <- read_text("cat_book_contracts.csv")
CEDENTS <- read_text("cat_book_cedents.csv")
N_YEARS <- 2000
# One cedent's years of losses, with times (fraction of the year) and peril labels.
cedent_events <- function(cedent, perils = "all") {
rows <- YELT[YELT$cedent == cedent, ]
if (perils != "all") rows <- rows[rows$peril %in% strsplit(perils, "+", fixed = TRUE)[[1]], ]
year <- factor(as.integer(rows$year), levels = seq_len(N_YEARS))
time <- ((as.integer(rows$day) - 1) * 24 + as.integer(rows$hour)) / 8760
ev <- events_from_years(unname(split(as.double(rows$loss), year)),
times = unname(split(time, year)))
with_labels(ev, list(peril = rows$peril[order(year)]))
}
num <- function(x, default = NULL) if (x != "") as.double(x) else default
# The contract's terms from cat_book_contracts.csv as a layer.
contract_layer <- function(c) {
share <- num(c$share)
if (c$kind == "occurrence_xl") {
limit <- num(c$limit)
return(xol_layer(c$contract, limit, num(c$attachment), share = share,
premium = num(c$rate_on_line) * limit * share,
reinstatement_rates = rep(num(c$reinstatement_rate),
as.integer(c$reinstatements))))
}
if (c$kind == "aggregate_xl") {
agg_limit <- num(c$aggregate_limit)
return(xol_layer(c$contract, Inf, 0, share = share,
aggregate_deductible = num(c$aggregate_deductible),
aggregate_limit = agg_limit,
premium = num(c$rate_on_line) * agg_limit * share))
}
premium <- share * as.double(CEDENTS$cat_premium[CEDENTS$cedent == c$cedent])
with_ceding_commission(
xol_layer(c$contract, num(c$limit), 0, share = share,
aggregate_limit = num(c$aggregate_limit), premium = premium),
num(c$ceding_commission))
}
# The contract's subject loss: its cedent and perils, grouped by its hours clause.
subject <- function(c) {
e <- cedent_events(c$cedent, c$perils)
if (c$hours != "") hours_clause(e, as.double(c$hours)) else e
}
deals <- CONTRACTS$contract
towers <- list()
results <- list()
for (i in seq_len(nrow(CONTRACTS))) {
c <- CONTRACTS[i, ]
towers[[c$contract]] <- reinsurance_tower(list(contract_layer(c)))
results[[c$contract]] <- apply_tower(towers[[c$contract]], subject(c))
}
runs <- lapply(deals, function(d) deal_run_from_tower(d, towers[[d]], results[[d]], d))
book <- deal_book(runs)
amounts <- book_amounts(book)
cat(sprintf("%d deals, %d years\n", length(runs), as.integer(amounts@n_sims)))## 5 deals, 2000 years
## items: premium, loss, ceding_commission, total_deductions, nmbf, margin
book_summary() gives the mean of every item by deal and
for the book, with its ratio to the mean premium. Premium is the yearly
deposit plus the reinstatement premium that the year’s losses pay
(section 3). Margin is premium less loss less deductions (only
corran_qs has any: its ceding commission). The data has no
expenses of Larkspur, so the margin is before them.
library(gt)
s <- book_summary(book)
item_mean <- function(s, d, i) s$mean[s$deal == d & s$item == i]
item_ratio <- function(s, d, i) s$ratio[s$deal == d & s$item == i]
all_deals <- c(deals, "total")
result <- data.frame(
deal = all_deals,
premium = sapply(all_deals, item_mean, s = s, i = "premium"),
loss = sapply(all_deals, item_mean, s = s, i = "loss"),
deduct = sapply(all_deals, item_mean, s = s, i = "total_deductions") + 0,
margin = sapply(all_deals, item_mean, s = s, i = "margin"),
LR = sapply(all_deals, item_ratio, s = s, i = "loss")
)
gt(result, rowname_col = "deal") |>
tab_header("Mean annual result by deal", "Premium units; LR = loss / premium") |>
fmt_number(columns = c(premium, loss, deduct, margin, LR), decimals = 3)| Mean annual result by deal | |||||
| Premium units; LR = loss / premium | |||||
| premium | loss | deduct | margin | LR | |
|---|---|---|---|---|---|
| alder_cat_1 | 1.921 | 0.823 | 0.000 | 1.098 | 0.428 |
| alder_cat_2 | 1.020 | 0.416 | 0.000 | 0.604 | 0.408 |
| bracken_cat | 1.846 | 0.685 | 0.000 | 1.161 | 0.371 |
| bracken_agg | 0.450 | 0.162 | 0.000 | 0.288 | 0.360 |
| corran_qs | 3.000 | 1.202 | 0.750 | 1.048 | 0.401 |
| total | 8.237 | 3.289 | 0.750 | 4.198 | 0.399 |
3. Reinstatement premium in the book
deal_run_from_tower() adds the reinstatement premium of
each year to the deposit premium of the layer. The tower computes it for
the two Alder layers and bracken_cat, pro rata as to
amount, so alder_cat_1 earns 1.8 in a quiet year and more
in a year that reaches the layer.
reinstatement_premium = FALSE keeps the deposit alone. The
losses and the capital below do not change; the premium and the margin
do.
premium <- marginal(amounts, c("premium", "alder_cat_1"))@draws
cat(sprintf("alder_cat_1 book premium: min %.3f, max %.3f\n", min(premium), max(premium)))## alder_cat_1 book premium: min 1.800, max 3.600
deposit <- deal_book(lapply(deals, function(d) {
deal_run_from_tower(d, towers[[d]], results[[d]], d, reinstatement_premium = FALSE)
}))
s_dep <- book_summary(deposit)
reinstatement <- data.frame(
deal = deals,
premium = sapply(deals, item_mean, s = s, i = "premium"),
deposit = sapply(deals, item_mean, s = s_dep, i = "premium")
)
reinstatement$reinstatement <- reinstatement$premium - reinstatement$deposit
gt(reinstatement, rowname_col = "deal") |>
tab_header("Reinstatement premium by deal", "Mean per year, premium units") |>
fmt_number(columns = c(premium, deposit), decimals = 3) |>
fmt_number(columns = reinstatement, decimals = 4)| Reinstatement premium by deal | |||
| Mean per year, premium units | |||
| premium | deposit | reinstatement | |
|---|---|---|---|
| alder_cat_1 | 1.921 | 1.800 | 0.1207 |
| alder_cat_2 | 1.020 | 1.000 | 0.0203 |
| bracken_cat | 1.846 | 1.750 | 0.0959 |
| bracken_agg | 0.450 | 0.450 | 0.0000 |
| corran_qs | 3.000 | 3.000 | 0.0000 |
4. The book’s tail
book_distribution(book, "loss", ...) gives three views
of each deal at once.
-
total: the statistics of the book. -
contribution: the mean loss of the deal in the years that make the statistic of the book. For TVaR this is the Euler split, and the contributions add up to the TVaR of the book. -
marginal: the statistic of the book less the same statistic of the book without that deal. It answers “what would we save by not writing this?”.
capital_allocation() gives the stand-alone TVaR of each
deal, the first column of the table.
dist <- book_distribution(book, "loss", 99, tvar_levels = 99)
loss <- select_components(select_components(amounts, "item", "loss"), "deal", deals)
alloc <- capital_allocation(loss, distortion("tvar", 0.99))
cat(sprintf("book: mean %.3f, VaR 99 %.3f, TVaR 99 %.3f\n", dist$total[["Mean"]],
dist$total[["Percentile 99"]], dist$total[["TVaR 99"]]))## book: mean 3.289, VaR 99 46.505, TVaR 99 55.096
## sum of contributions 55.096
tail_tvar <- data.frame(
deal = deals,
alone = alloc$by_component$standalone,
contrib = unname(dist$contribution["TVaR 99", deals]),
marginal = unname(dist$marginal["TVaR 99", deals])
)
gt(tail_tvar, rowname_col = "deal") |>
tab_header("TVaR 99 of the loss by deal", "Premium units") |>
fmt_number(columns = c(alone, contrib, marginal), decimals = 3)| TVaR 99 of the loss by deal | |||
| Premium units | |||
| alone | contrib | marginal | |
|---|---|---|---|
| alder_cat_1 | 13.843 | 13.195 | 12.728 |
| alder_cat_2 | 20.998 | 19.026 | 14.560 |
| bracken_cat | 14.136 | 9.397 | 8.840 |
| bracken_agg | 7.500 | 0.262 | 0.193 |
| corran_qs | 16.363 | 13.216 | 12.609 |
library(ggplot2, exclude = "layer") # keeps prospicio's layer()
tail_views <- rbind(
data.frame(deal = deals, view = "alone", tvar = alloc$by_component$standalone),
data.frame(deal = deals, view = "contribution (Euler)", tvar = dist$contribution["TVaR 99", deals]),
data.frame(deal = deals, view = "marginal", tvar = dist$marginal["TVaR 99", deals])
)
tail_views$deal <- factor(tail_views$deal, levels = deals)
tail_views$view <- factor(tail_views$view, levels = c("alone", "contribution (Euler)", "marginal"))
ggplot(tail_views, aes(deal, tvar, fill = view)) +
geom_col(position = position_dodge(width = 0.8), width = 0.7) +
scale_fill_manual(values = c("alone" = "grey75", "contribution (Euler)" = scales::hue_pal()(2)[1],
"marginal" = scales::hue_pal()(2)[2])) +
labs(x = NULL, y = "TVaR 99 of the loss (premium units)", fill = NULL,
title = "Tail of the book: alone, in the book, and removed from it") +
theme(legend.position = "top")By deal:
-
alder_cat_2, the high Alder layer, has the largest TVaR alone and keeps most of it in the book: the years that exhaust it are the big coastal windstorms that drive the whole book. -
bracken_agglooks risky alone: in its worst 1% of years it pays its whole aggregate limit. Those are mostly years of one large flood or storm outbreak on the plains (page 3, section 5), not the worst of the book, so it adds little to the tail of the book. - Contributions add up to the TVaR of the book. Marginals do not: removing a deal changes the worst years.
5. A trap: the total row
book_amounts() holds every item for each deal
and a "total" deal. A selection on the item alone
keeps that total, so capital_allocation() adds it to the
deals as a sixth contract and the TVaR of the book doubles.
wrong <- capital_allocation(select_components(amounts, "item", "loss"), distortion("tvar", 0.99))
right <- capital_allocation(loss, distortion("tvar", 0.99))
cat(sprintf("item only: total %.3f, components %d\n", wrong$total, nrow(wrong$by_component)))## item only: total 110.192, components 6
## item and deals: total 55.096, components 5
Select the deals by name,
select_components(..., "deal", deals), every time.
6. Capital and diversification
capital_allocation(loss, distortion("tvar", 0.99))
allocates the TVaR of the book by Euler, so the allocated amounts are
the contributions above. Diversification is the sum of the stand-alone
TVaRs less the TVaR of the book:
diversification = sum over deals i of TVaR(X_i) - TVaR(X_1 + ... + X_5)
TVaR is subadditive, so this is never negative.
bc <- alloc$by_component
divers <- data.frame(
deal = deals,
alone = bc$standalone,
allocated = bc$allocated,
saved = bc$diversification
)
gt(divers, rowname_col = "deal") |>
tab_header("Capital by deal: alone and in the book",
"TVaR 99, premium units; saved = alone - allocated") |>
fmt_number(columns = c(alone, allocated, saved), decimals = 3)| Capital by deal: alone and in the book | |||
| TVaR 99, premium units; saved = alone - allocated | |||
| alone | allocated | saved | |
|---|---|---|---|
| alder_cat_1 | 13.843 | 13.195 | 0.648 |
| alder_cat_2 | 20.998 | 19.026 | 1.973 |
| bracken_cat | 14.136 | 9.397 | 4.738 |
| bracken_agg | 7.500 | 0.262 | 7.238 |
| corran_qs | 16.363 | 13.216 | 3.147 |
cat(sprintf("sum alone %.3f, book %.3f, benefit %.3f\n", sum(bc$standalone), alloc$total,
alloc$diversification_benefit))## sum alone 72.840, book 55.096, benefit 17.744
7. The book priced on its capital
price_portfolio() prices the book as page 6, section 2
prices one contract: P = (EL + r A) / (1 + r), with the
assets A now the TVaR of the book. It splits that premium
to the deals by the same Euler weights (portfolio pricing has the theory),
and prices each deal alone. Compare these prices with what Larkspur
keeps: the premium charged, plus the expected reinstatement premium of
section 3, less the deductions (the ceding commission of Corran).
pp <- price_portfolio(loss, distortion("tvar", 0.99), cost_of_capital = 0.10)
cat(sprintf("book: EL %.3f, premium %.3f, capital %.3f\n", pp$total$expected_loss,
pp$total$premium, pp$total$capital))## book: EL 3.289, premium 7.998, capital 47.097
## premium saved by diversification 1.613
kept <- function(d) item_mean(s, d, "premium") - item_mean(s, d, "total_deductions")
prices <- data.frame(
deal = c(deals, "book"),
charged = sapply(all_deals, item_mean, s = s_dep, i = "premium"),
kept = sapply(all_deals, kept),
in_book = c(pp$by_component$premium, pp$total$premium),
alone = c(pp$by_component$standalone_premium, NA)
)
gt(prices, rowname_col = "deal") |>
tab_header("Premium by deal: charged, kept and needed",
"Premium units; needed = cost of capital 10% on TVaR 99 capital") |>
tab_spanner("needed", columns = c(in_book, alone)) |>
cols_label(in_book = "in book") |>
fmt_number(columns = c(charged, kept, in_book, alone), decimals = 3) |>
sub_missing(columns = alone, missing_text = "")| Premium by deal: charged, kept and needed | ||||
| Premium units; needed = cost of capital 10% on TVaR 99 capital | ||||
| charged | kept |
needed
|
||
|---|---|---|---|---|
| in book | alone | |||
| alder_cat_1 | 1.800 | 1.921 | 1.948 | 2.007 |
| alder_cat_2 | 1.000 | 1.020 | 2.108 | 2.287 |
| bracken_cat | 1.750 | 1.846 | 1.477 | 1.908 |
| bracken_agg | 0.450 | 0.450 | 0.171 | 0.829 |
| corran_qs | 3.000 | 2.250 | 2.295 | 2.581 |
| book | 8.000 | 7.487 | 7.998 | |
Alone, alder_cat_1 needs the 2.007 of page 6. In the
book it needs 1.948. The book charges 8.000 against the 7.998 that a 10%
return on TVaR capital needs, but keeps 7.487 after the reinstatement
premium comes in and the ceding commission of Corran goes out. So the
book falls short of the target (section 9: a 9.0% return). Both Alder
layers keep less than their share, alder_cat_2 about half
of it. The Bracken contracts keep more. The quota share of Corran keeps
2.250 of 3.000, a little under its 2.295.
8. The marginal price of a new contract
The allocated price shares the price of the book among the deals
already written. A new contract asks what it must charge so that the
return of the book does not fall. Its extra assets dA are
its marginal TVaR (the book with it less the book without it), and
EL is its expected loss:
P = EL + r * (dA - P), so P = (EL + r * dA) / (1 + r)
Below, each deal in turn is the last one written. The chunk computes
the price from marginal (#588).
r <- 0.10
marg <- data.frame(
deal = deals,
EL = unname(dist$marginal["Mean", deals]),
dA = unname(dist$marginal["TVaR 99", deals])
)
marg$marginal_P <- (marg$EL + r * marg$dA) / (1 + r)
marg$charged <- sapply(deals, item_mean, s = s_dep, i = "premium")
gt(marg, rowname_col = "deal") |>
tab_header("Marginal price of each deal as the last one written",
"Premium units; P = (EL + r dA) / (1 + r), r = 10%") |>
cols_label(marginal_P = "marginal P") |>
fmt_number(columns = c(EL, dA, marginal_P, charged), decimals = 3)| Marginal price of each deal as the last one written | ||||
| Premium units; P = (EL + r dA) / (1 + r), r = 10% | ||||
| EL | dA | marginal P | charged | |
|---|---|---|---|---|
| alder_cat_1 | 0.823 | 12.728 | 1.905 | 1.800 |
| alder_cat_2 | 0.416 | 14.560 | 1.702 | 1.000 |
| bracken_cat | 0.685 | 8.840 | 1.426 | 1.750 |
| bracken_agg | 0.162 | 0.193 | 0.165 | 0.450 |
| corran_qs | 1.202 | 12.609 | 2.239 | 3.000 |
marginal_p <- (dist$marginal["Mean", deals] + r * dist$marginal["TVaR 99", deals]) / (1 + r)
compare <- rbind(
data.frame(deal = deals, price = "charged", premium = sapply(deals, function(d) item_mean(s_dep, d, "premium"))),
data.frame(deal = deals, price = "marginal price", premium = marginal_p)
)
compare$deal <- factor(compare$deal, levels = deals)
compare$price <- factor(compare$price, levels = c("charged", "marginal price"))
ggplot(compare, aes(deal, premium, fill = price)) +
geom_col(position = position_dodge(width = 0.8), width = 0.7) +
scale_fill_manual(values = c("charged" = "grey75", "marginal price" = scales::hue_pal()(1))) +
labs(x = NULL, y = "premium (premium units)", fill = NULL,
title = "Charged premium against the marginal price of each deal") +
theme(legend.position = "top")Every marginal price is below the allocated price, because a deal’s marginal TVaR is at most its Euler contribution (TVaR is subadditive). Price the next contract on its marginal, and the TVaR return holds. Price every contract on its marginal, and the book falls short.
9. A return on allocated capital
A risk-adjusted return on capital (RAROC) sets the margin of each deal against its allocated capital: the allocated assets less the premium of the deal. The margin includes the reinstatement premium of section 3, and there is no expense line, so the return is before the costs of Larkspur.
returns <- data.frame(
deal = c(deals, "book"),
margin = sapply(c(deals, "total"), function(d) item_mean(s, d, "margin")),
capital = c(bc$allocated - sapply(deals, function(d) item_mean(s, d, "premium")),
alloc$total - item_mean(s, "total", "premium"))
)
returns$return <- ifelse(returns$capital > 0, returns$margin / returns$capital, NA_real_)
gt(returns, rowname_col = "deal") |>
tab_header("Return on allocated capital", "Premium units; return = margin / capital") |>
fmt_number(columns = c(margin, capital), decimals = 3) |>
fmt_percent(columns = return, decimals = 1) |>
sub_missing(columns = return, missing_text = "none")| Return on allocated capital | |||
| Premium units; return = margin / capital | |||
| margin | capital | return | |
|---|---|---|---|
| alder_cat_1 | 1.098 | 11.274 | 9.7% |
| alder_cat_2 | 0.604 | 18.005 | 3.4% |
| bracken_cat | 1.161 | 7.552 | 15.4% |
| bracken_agg | 0.288 | −0.188 | none |
| corran_qs | 1.048 | 10.216 | 10.3% |
| book | 4.198 | 46.859 | 9.0% |
Against a 10% target, alder_cat_2 is the weak contract:
it uses over a third of the capital of the book and returns a few
percent. bracken_agg has no return: its premium exceeds the
assets allocated to it, so it needs no shareholder capital here, and a
ratio over negative capital has no meaning.
10. Reproducibility
The VaR of the book is the default inverted-cdf quantile; page 2, section 2 compares the other conventions. Every number on this page follows from four committed files and one seed.
-
examples/data/make_cat_book.pywrites the files with a fixed seed. A test checks that the committed files are what the script writes. - No step draws a random number: the book adds the same 2,000 years for every contract.
-
read_ylt()stamps the event set with a hash of the file that it read, so you can trace a result to its input. The rebuild bycedent_events()drops that hash, so record it fromread_ylt()once.
ylt <- read_ylt(find_data("cat_book_yelt.csv"), year = "year", loss = "loss", slot = "slot",
labels = c("peril", "region", "cedent"))
cat(strsplit(ylt@input_hash, ":", fixed = TRUE)[[1]][1], ylt@n_sims, "\n")## blake3 2000
The page does not print the hash: it depends on the bytes of the file, and a checkout that changes line endings to CRLF gives a different hash.
In Python
The Python guide, cat-7-portfolio.md,
runs the same steps with DealRun.from_tower,
DealBook, book.summary(),
book.distribution(), capital and
price_portfolio.
Further reading
Price allocation and portfolio pricing cover allocation and pricing on a book in depth. reinsurance.dev by Oliver Baltzer is another introduction to property catastrophe reinsurance.