#' @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)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.