View source: R/simulate_claims.R
| simulate_claims | R Documentation |
A simpler interface to simulate_function, with short argument names and
defaults for everything optional. Leaving an option out (NULL) switches the feature off:
no seed, no Pareto slices, no cap, no reinstatement limit.
simulate_claims(
n_sims,
frequency,
frequency_params,
severity,
severity_params,
seed = NULL,
truncate_at_zero = FALSE,
pareto_thresholds = NULL,
pareto_alphas = NULL,
severity_cap = NULL,
eel_layer = "none",
eel_deductible = NULL,
eel_limit = NULL,
eel_reinstatements = NULL,
agg_layer = "none",
agg_deductible = NULL,
agg_limit = NULL,
parallel = FALSE,
chunk_size = NULL,
gross = TRUE,
shortcuts = TRUE,
progress = NULL
)
n_sims |
Number of simulations (e.g. years). |
frequency |
Name of the claim count distribution; see Details. |
frequency_params |
Parameters of the claim count distribution, either all unnamed in the order of Details or all named. |
severity |
Name of the claim size distribution; see Details. |
severity_params |
Parameters of the claim size distribution, either all unnamed in the order of Details or all named. |
seed |
A whole number for a reproducible run. NULL (the default) uses the current random number stream, so |
truncate_at_zero |
TRUE to draw Normal claim sizes from the Normal distribution truncated at zero, so no claim is negative. Only used with the Normal severity. |
pareto_thresholds |
Increasing claim sizes above which the severity tail is replaced by Pareto slices, one per slice (at most six). NULL (the default) for no slices. |
pareto_alphas |
The Pareto alpha of each slice, one per threshold. |
severity_cap |
The largest amount a single claim can reach, or NULL (the default) for no cap. |
eel_layer |
The each-and-every-loss layer: "none" (the default), "unlimited", "limited" or "exclude". |
eel_deductible |
The deductible of the each-and-every-loss layer. |
eel_limit |
The limit of a "limited" or "exclude" each-and-every-loss layer. |
eel_reinstatements |
The number of reinstatements of a "limited" each-and-every-loss layer, so it pays at most |
agg_layer |
The aggregate layer: "none" (the default), "unlimited", "limited" or "exclude". |
agg_deductible |
The deductible of the aggregate layer. |
agg_limit |
The limit of a "limited" or "exclude" aggregate layer. |
parallel |
TRUE to run the chunks of simulations on parallel workers. Results are the same as a sequential run. |
chunk_size |
The number of simulations per vectorised batch; NULL (the default) chooses it from the expected number of claims. |
gross |
TRUE (the default) to return the gross totals before the layers. FALSE allows a much faster run with an "unlimited" or "limited" each-and-every-loss layer, by drawing only the claims that reach it. |
shortcuts |
TRUE (the default) to use exact shortcuts where the settings allow; see |
progress |
An optional function called after each chunk of a sequential run with the fraction done and a short description. |
Distributions are chosen by name; case, spaces and underscores are ignored, so "Negative Binomial", "negative_binomial" and "Negative_Binomial" are the same. Their parameters are given in the order below, or named with these names:
| Distribution | Type | Parameters |
| Poisson | frequency | lambda |
| Negative_Binomial | frequency | r, beta (Gamma shape and scale of the Poisson mean) |
| Binomial | frequency | n, p |
| Fixed_number_of_Counts | frequency | count |
| Normal | severity | mean, sd |
| LogNormal | severity | meanlog, sdlog |
| Gamma | severity | shape, scale |
| Exponential | severity | rate |
| Pareto | severity | alpha, x_m (minimum) |
| Fixed_Severity | severity | amount |
Layers are "none", "unlimited" (everything above the deductible), "limited" (the limit excess of the deductible) or "exclude" (the claims with that layer removed). The each-and-every-loss layer applies to every claim; the aggregate layer applies to each simulation's total after the each-and-every-loss layer.
A data frame with one row per simulation: claim_counts, total_claims (after the layers), gross_claims (before them, unless gross = FALSE) and, with limited reinstatements, number_of_reinstatements_used.
simulate_function, which this calls, and run_shiny_simulator for the same model in an app.
# 10,000 years of Poisson claim counts with Log-Normal claim sizes
claims <- simulate_claims(
10000, frequency = "Poisson", frequency_params = 3,
severity = "LogNormal", severity_params = c(meanlog = 8, sdlog = 1.5), seed = 1
)
summary(claims$total_claims)
# a Pareto tail above 100,000, and a layer of 50,000 excess of 20,000 on each
# claim with two reinstatements
ceded <- simulate_claims(
10000, "Poisson", 3, "LogNormal", c(8, 1.5), seed = 1,
pareto_thresholds = 100000, pareto_alphas = 1.5,
eel_layer = "limited", eel_deductible = 20000, eel_limit = 50000,
eel_reinstatements = 2
)
mean(ceded$total_claims)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.