## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE, fig.width = 7, fig.height = 4)

## ----data---------------------------------------------------------------------
library("NetSimR")
head(xl_large_losses)
xl_premium

## ----burning cost-------------------------------------------------------------
development <- setNames(xl_premium$development, xl_premium$year)
rate_index <- setNames(xl_premium$rate_index, xl_premium$year)
premium <- xl_premium[, c("year", "premium")]
bc <- burning_cost(xl_large_losses, premium, deductible = 1e6, limit = 4e6, aggregate_limit = 8e6,
                   inflation = 0.04, rating_year = 2025, development = development,
                   premium_index = rate_index, threshold = 5e5, rating_premium = 60e6)
bc
bc$by_year[, c("year", "layer_count", "aggregate_losses", "onlevel_premium", "burning_cost")]

## ----pareto-------------------------------------------------------------------
pr <- pareto_rating(xl_large_losses, premium, threshold = 7.5e5, deductible = 1e6, limit = 4e6,
                    inflation = 0.04, rating_year = 2025, development = development,
                    premium_index = rate_index, rating_premium = 60e6)
pr

## ----exposure-----------------------------------------------------------------
exposure <- property_exposure_rating(xl_property_profile, deductible = 1e6, limit = 4e6,
                                     curve = "Y3", loss_ratio = 0.55)
exposure
exposure$bands[, c("band", "sum_insured", "deductible_share", "exhaustion_share", "layer_share", "layer_loss")]

## ----curves-------------------------------------------------------------------
x <- seq(0, 1, by = 0.01)
plot(x, swiss_re_curve(x, "Y1"), type = "l", xlab = "Deductible as a share of the sum insured",
     ylab = "Share of the expected loss below it")
for (c in c("Y2", "Y3", "Y4", "Lloyds")) lines(x, swiss_re_curve(x, c))

## ----casualty-----------------------------------------------------------------
casualty_exposure_rating(xl_casualty_profile, deductible = 1e6, limit = 4e6, severity = "LogNormal",
                         severity_params = c(meanlog = 10, sdlog = 2), loss_ratio = 0.65)

## ----blend--------------------------------------------------------------------
z <- credibility_weight(bc$n_layer_losses, full = 100)
z
rate <- z * bc$rate + (1 - z) * exposure$rate
expected_loss <- rate * 60e6
expected_loss

## ----premium------------------------------------------------------------------
years <- bc$by_year$at_rating_premium * expected_loss / bc$expected_loss
used <- mean(pmin(years, 1 * 4e6)) / 4e6
used
premium <- technical_premium(expected_loss, limit = 4e6, loading = 0.25, reinstatements = 1,
                             reinstatement_rate = 1, used = used)
premium

