
Add standard period variables to an experience dataset
Source:R/experience.R
add_experience_period.RdAdd underwriting, calendar, and development period variables to an experience dataset using standard column conventions for loss ratio analysis.
The function detects the presence of key source columns such as uym,
cym, and elap_m, and derives additional period variables when
possible.
Details
The following variables are added when the required source columns exist:
Underwriting period (from uym):
uy: underwriting yearuyh: underwriting half-yearuyq: underwriting quarter
Calendar period (from cym):
cy: calendar yearcyh: calendar half-yearcyq: calendar quarter
Elapsed period:
elap_yis derived fromelap_mas yearly development index, where months 1 to 12 map to 1, 13 to 24 map to 2, and so on.elap_his derived fromuymandcymusing calendar half-year boundaries. For example, contracts issued in January to June are aligned to the same first development half-year block, and the next calendar half-year becomes development half-year 2.elap_qis derived fromuymandcymusing calendar quarter boundaries. For example, contracts issued in January to March are aligned to the same first development quarter block, and the next calendar quarter becomes development quarter 2.
Therefore, elap_h and elap_q are not simple grouped versions of
elap_m; they are aligned to calendar half-year and quarter boundaries
so that underwriting cohorts such as Q1, Q2, H1, and H2 are compared
consistently on the same cumulative development basis.
Newly created columns are inserted before their corresponding base columns.
Examples
if (FALSE) { # \dontrun{
df <- data.frame(
uym = as.Date("2023-01-01") + 0:5 * 30,
cym = as.Date("2023-01-01") + 0:5 * 30,
elap_m = 1:6
)
df2 <- add_experience_period(df)
head(df2)
} # }