Aggregate loss and rp by group and compute the corresponding total
loss ratio over a selected period window.
This function is intended for high-level portfolio comparison across groups such as products, coverages, or channels. It summarises:
the number of observed periods (
n_obs)the first and last observed periods (
sales_start,sales_end)total
lossand totalrptotal loss ratio (
lr = loss / rp)each group's share of total loss and risk premium
If period_from and/or period_to are supplied, the input data are first
restricted to that period window before aggregation. This is useful when
comparing groups on a common period basis.
Usage
build_total(
df,
group_var,
cohort_var = "uym",
dev_var = "elap_m",
value_var = c("loss", "rp"),
period_from = NULL,
period_to = NULL,
fill_gaps = FALSE
)Arguments
- df
A data.frame containing experience data.
- group_var
Grouping variable(s).
- cohort_var
A single period variable. This may be an underwriting period (
uym,uyq,uyh,uy) or a calendar period (cym,cyq,cyh,cy). Default"uym".- dev_var
A single development variable used to count observed periods. Default
"elap_m".- value_var
Value variables to aggregate. Must include both
"loss"and"rp". Defaultc("loss", "rp").- period_from
Optional lower bound for
cohort_var. Only rows withcohort_var >= period_fromare kept. May be supplied asDate, character, or any value coercible toDate. DefaultNULL.- period_to
Optional upper bound for
cohort_var. Only rows withcohort_var <= period_toare kept. May be supplied asDate, character, or any value coercible toDate. DefaultNULL.- fill_gaps
Logical; if
TRUE, zero-fill missing(group_var, cohort_var, dev_var)cells before aggregation so that every cohort has a consecutivedev_varsequence. DefaultFALSE. Note that filling inflatesn_obs(counts filled rows as observed periods); usevalidate_triangle()to inspect first.
