R/empirical_LE_calc.R

Defines functions empirical_lev

#' @title Empirical LEV calculation
#' @param data data frame of loss data
#' @param loss_col column name of the loss field
#' @param cutoff_col column name of the cutoff field
#' @param lower left truncation of the LEV calculation
#' @param upper attachment of the LEV calculation
#' @param limit limit of the LEV calculation
#' @export
empirical_lev <- function(data, loss_col, cutoff_col, lower, upper, limit) {
  data %>%
    dplyr::filter(
      !!rlang::sym(cutoff_col) <= lower
    ) %>%
    dplyr::filter(
      !!rlang::sym(loss_col) > lower
    ) %>%
    dplyr::mutate(
      y = pmin(pmax(!!rlang::sym(loss_col) - upper, 0), limit)
    ) %>%
    dplyr::summarise(
      n = dplyr::n(),
      lev = mean(y),
      surv = sum(ifelse(y == limit, 1, 0) / n)
    )
}
Atan1988/FlexFit documentation built on Jan. 16, 2022, 12:32 a.m.