Property catastrophe 1: what the cat model hands over
cat-1-loss-tables.RmdRendered from docs/guides/cat-1-loss-tables.qmd.
The code runs each time the site is built, so the output below is
current.
The renewal starts when the cedents’ cat model results arrive. A cat model gives tables, not a distribution: a list of possible events, or a long run of simulated years. This page reads the Larkspur Re book into prospicio and checks that two views of one cedent agree. The story, the files and the notation are on the overview.
This is the R twin of the Python guide cat-1-loss-tables.md,
with the same sections, files and numbers.
R/prospicio/tests/test-guides.R requires each chunk to
print the text under it. R counts rows from 1, so the ELT rows in
section 4 are one higher than on the Python page.
1. The words
A trial is one simulated year; a cat model runs many (here 2,000). Other names are year and simulation. From page 2, the track says year.
An event is one instance of a peril in the model’s catalog: one windstorm, one earthquake. A model can give one event as several pieces: rows a few hours apart whose losses add up to the event’s loss. An occurrence is what a contract counts as one loss: the pieces, and sometimes several events, that its hours clause joins (page 3). Every page keeps these three terms separate.
A YELT (year event loss table) has one row per event loss: the trial, the event, its time and its cost. It is the most detailed table, and most pages use it.
A YLT (year loss table) keeps one number per trial,
the annual total. It is enough for aggregate covers and annual risk
measures, but not for a layer that applies to each event, because it has
no events. read_ylt reads both tables. With a slot column,
it keeps each event.
An ELT (event loss table) does not simulate. It lists each possible event once, with an annual rate and a loss distribution. The rates add up to the expected number of events in a year.
Secondary uncertainty is the spread of an event’s loss around its mean, when it occurs: building damage varies, even for a storm of given track and strength. An ELT gives it as standard deviations. A YELT holds it implicitly: each row is one draw.
The AAL (average annual loss) is the expected loss in a year. On an ELT it is a sum over events of rate times mean loss:
AAL = sum over events i of rate_i * mean_i
On a YELT or YLT it is the average of the annual totals over the
N trials:
AAL = (1 / N) * sum over trials t of total_t
The two agree up to simulation error (section 4).
2. Reading a YELT
The Larkspur YELT is examples/data/cat_book_yelt.csv,
written by examples/data/make_cat_book.py. Each row is the
loss of one cedent from one event (or piece) in one trial, with columns
year, slot, event_id,
day, hour, peril,
region, cedent and loss. The
slot is the order of the event in its year, the same for
every cedent that the event hit. Losses are in millions of Varland
crowns. Some trials have no events (the first, for example).
read_ylt() reads such a file into an
event_set, the prospicio container for years of losses. It
keeps the named columns as labels, so you can split later results by
peril, region or cedent. total() gives the annual totals as
a predictive distribution, one value per trial.
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
}
}
yelt_path <- find_data("cat_book_yelt.csv")
labels <- c("peril", "region", "cedent")
book <- read_ylt(yelt_path, year = "year", loss = "loss", slot = "slot", labels = labels)
cat("trials:", book@n_sims, "\n")## trials: 2000
cat("losses:", sum(event_counts(book)), "\n")## losses: 16432
## labels: ['peril', 'region', 'cedent']
## hash starts with: blake3:
## mean annual loss, all cedents: 45.204
read_ylt() checks the file when it reads it. It refuses
the file if:
- a loss is negative, infinite or missing. Losses are positive on
every page of this track. If a file writes losses as negative numbers
(money out), flip their sign first (#593).
ceded()reads a negative loss as a loss below the attachment, with no warning. - a year is less than 1. Years count from 1. The largest year sets the
number of trials, unless
n_years =says otherwise. - two rows have the same year, slot and labels, usually a duplicated
row. One event that hits all three cedents has three rows with the same
slot, so the labels must include
cedent. Orunique_by =names the labels that make a row unique. - a label value is not in
expected =, if you give it.
The last check stops a wrong peril code from becoming a silent fifth peril:
refused <- tryCatch(
read_ylt(yelt_path, year = "year", loss = "loss", slot = "slot", labels = labels,
expected = list(peril = c("WS", "EQ", "FL"))),
error = function(e) conditionMessage(e)
)
cat(strsplit(refused, "\n")[[1]][1], "\n")## invalid data: row 18: peril "CS" is not one of ["WS", "EQ", "FL"]
The hash fingerprints the file’s bytes, so a result traces to its table. The page prints only the first characters, because a checkout that changes line endings changes the full hash.
Tiling and resampling. A model can give 2,000 years
when a capital model runs 10,000 trials. n_sims = extends
the table. With expand = "tile" (the default), the 2,000
years repeat in order, so the mean is unchanged. With
expand = "resample", each trial draws a year at random
(seeded), so the mean moves a little:
tiled <- read_ylt(yelt_path, year = "year", loss = "loss", slot = "slot", labels = labels,
n_sims = 10000)
drawn <- read_ylt(yelt_path, year = "year", loss = "loss", slot = "slot", labels = labels,
n_sims = 10000, expand = "resample", seed = 1)
cat(sprintf("tiled: %d trials, mean %.3f\n", as.integer(tiled@n_sims), mean(total(tiled))))## tiled: 10000 trials, mean 45.204
cat(sprintf("resampled: %d trials, mean %.3f\n", as.integer(drawn@n_sims), mean(total(drawn))))## resampled: 10000 trials, mean 44.184
Neither adds information. Tile when the trials must align with
another model’s trials; resample when a whole multiple is not possible.
Both have two limits. The “5,000-year loss” of the 10,000-trial table is
the worst of the original 2,000 years. And the extra trials are copies,
so a standard error that treats them as independent is too small by
about sqrt(5).
3. Times and one cedent
Most pages need one cedent’s losses with their times (the hours
clause and reinstatements pro rata as to time use them). A short helper
builds these event sets (#594): it keeps one cedent’s rows, turns
day and hour into a fraction of the year and
labels each loss with its peril. Each page that needs it holds the same
code.
The chunk reads the times back with event_times() on
every year and checks that each loss has a time (#596).
yelt <- utils::read.csv(yelt_path, colClasses = c(peril = "character", region = "character",
cedent = "character"))
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(rows$year, levels = seq_len(n_years))
years <- unname(split(rows$loss, year))
times <- unname(split(((rows$day - 1) * 24 + rows$hour) / 8760, year))
ev <- events_from_years(years, times = times)
# with_labels() wants the labels in the order events() lists the losses, year by year.
with_labels(ev, list(peril = unlist(split(rows$peril, year), use.names = FALSE)))
}
alder <- cedent_events("alder")
alder_totals <- total(alder)
has_times <- all(vapply(seq_len(alder@n_sims), function(y) {
length(event_times(alder, y)) == length(events(alder, y))
}, logical(1)))
cat("trials:", alder@n_sims, " losses:", sum(event_counts(alder)), " has times:",
if (has_times) "True" else "False", "\n")## trials: 2000 losses: 5391 has times: True
## Alder's AAL from the YELT: 16.778
An event set built this way has no file hash, because
events_from_years() did not read the file.
Alder’s events come in seasons. The figure counts them by month and peril:
library(ggplot2, exclude = "layer") # keeps prospicio's layer()
alder_rows <- yelt[yelt$cedent == "alder", ]
alder_rows$month <- pmin(12, floor((alder_rows$day - 1) / (365 / 12)) + 1)
by_month <- as.data.frame(table(month = alder_rows$month, peril = alder_rows$peril),
responseName = "losses", stringsAsFactors = FALSE)
by_month$month <- as.integer(by_month$month)
by_month$peril <- factor(by_month$peril, levels = c("EQ", "CS", "WS", "FL"))
ggplot(by_month, aes(month, losses, group = peril)) +
geom_line(data = by_month[by_month$peril == "EQ", ], colour = "grey75") +
geom_line(aes(colour = peril), data = by_month[by_month$peril != "EQ", ]) +
geom_point(aes(colour = peril), data = by_month[by_month$peril != "EQ", ]) +
scale_x_continuous(breaks = 1:12) +
labs(x = "month of the year", y = "losses of Alder in 2,000 trials", colour = NULL,
title = "Alder: losses by month and peril in the YELT (EQ in grey)")4. An ELT, and reconciling it with the YELT
Alder’s cat model also gives an ELT,
examples/data/cat_book_elt_alder.csv. It has one row per
event: rate, mean, two standard deviations and exposure. The
exposure is the event’s maximum cost to Alder: the
insured value in its footprint. The two standard deviations give the
secondary uncertainty. The independent part varies
separately at each location or cedent that the event hits. The
correlated part moves together across them.
event_loss_table() takes these five columns. When an
event occurs, its loss has a beta distribution on 0 to the exposure,
with the row’s mean and a standard deviation equal to the sum of the two
(they add, not the variances). The table’s rate is the
expected number of events in a year, and
expected_annual_loss is the AAL formula of section 1.
rows <- utils::read.csv(find_data("cat_book_elt_alder.csv"))
elt <- event_loss_table(rows$rate, rows$mean, rows$sd_independent,
rows$sd_correlated, rows$exposure)
cat("events:", length(elt$columns$rate), "\n")## events: 299
## events a year: 2.3365
## AAL: 16.056
simulate_elt() turns the ELT into trials: each year has
a Poisson number of events, each chosen in proportion to its rate and
given a beta loss. It also returns the row of each loss (rows count from
1 in R).
sim <- simulate_elt(elt, 2000, seed = 7)
simulated <- sim$events
cat(sprintf("simulated mean over 2,000 years: %.3f\n", mean(total(simulated))))## simulated mean over 2,000 years: 16.851
first <- which(lengths(sim$ids) > 0)[1]
cat(sprintf("year %d: losses [%s] from rows [%s]\n", first,
paste(sprintf("%.2f", events(simulated, first)), collapse = ", "),
paste(sim$ids[[first]], collapse = ", ")))## year 2: losses [0.02, 5.24, 4.89] from rows [289, 280, 238]
Alder’s AAL has three estimates: the exact sum of the ELT, the YELT average and the average of a new ELT simulation. Each average differs from the true value by about one standard error:
SE = sd(total_t) / sqrt(N)
se <- sqrt(variance(alder_totals)) / sqrt(n_years)
cat(sprintf("standard error, 2,000 years: %.2f\n", se))## standard error, 2,000 years: 0.79
The table gives each estimate and its gap to the exact AAL. The figure shows the two averages with bars one standard error wide on each side:
library(gt)
estimates <- c("ELT exact" = elt$expected_annual_loss,
"YELT average" = mean(alder_totals),
"ELT simulated" = mean(total(simulated)))
exact <- estimates[["ELT exact"]]
reconcile <- data.frame(
estimate = names(estimates),
aal = unname(estimates),
gap = unname(estimates) - exact,
gap_se = (unname(estimates) - exact) / se
)
gt(reconcile, rowname_col = "estimate") |>
tab_header("AAL of Alder: three estimates", "Millions of Varland crowns") |>
cols_label(aal = "AAL", gap = "gap to the ELT exact", gap_se = "gap in standard errors") |>
fmt_number(columns = c(aal, gap), decimals = 3) |>
fmt_number(columns = gap_se, decimals = 2)| AAL of Alder: three estimates | |||
| Millions of Varland crowns | |||
| AAL | gap to the ELT exact | gap in standard errors | |
|---|---|---|---|
| ELT exact | 16.056 | 0.000 | 0.00 |
| YELT average | 16.778 | 0.723 | 0.92 |
| ELT simulated | 16.851 | 0.795 | 1.01 |
averages <- data.frame(estimate = factor(c("YELT average", "ELT simulated"),
levels = c("YELT average", "ELT simulated")),
aal = unname(estimates[c("YELT average", "ELT simulated")]))
ggplot(averages, aes(aal, estimate)) +
geom_vline(xintercept = exact, colour = "grey75") +
geom_pointrange(aes(xmin = aal - se, xmax = aal + se, colour = estimate),
orientation = "y") +
labs(x = "average annual loss of Alder (millions of Varland crowns)", y = NULL,
title = "Three estimates of the AAL, with one standard error (grey: ELT exact)") +
theme(legend.position = "none")The estimates agree within about one standard error, and cannot agree better: cat losses are very skewed, so a few large years move the average. Check that differences are this size, not zero.
One difference is built in. The script that wrote the YELT removes each loss below 0.05 (a cedent that an event almost missed), as many vendor extracts do. The ELT keeps every event. So the YELT’s AAL is lower than the ELT’s by a small amount on average. Here that amount is much smaller than the sampling error, so the YELT’s average still comes out above the exact AAL.
In Python
The Python guide (cat-1-loss-tables.md) runs the same
steps with read_ylt, EventLossTable,
EventLossTable.simulate,
EventSet.from_years(times=) and
with_labels.
Further reading
reinsurance.dev by Oliver Baltzer is another introduction to property catastrophe reinsurance.