portfolio <- data.frame(
policy_id = c("P001", "P002", "P003"),
sector = c("Industry", "Retail", "Services"),
coverage_start = as.Date(c("2025-01-15", "2025-02-01", "2025-03-20")),
coverage_end = as.Date(c("2025-03-31", "2025-02-28", "2025-05-10")),
earned_exposure = c(0.21, 0.08, 0.14),
earned_premium = c(420, 160, 280)
)
# Allocate each policy period and its amounts over calendar months.
monthly_portfolio <- split_periods_to_months(
portfolio,
period_start = "coverage_start",
period_end = "coverage_end",
prorate_cols = c("earned_exposure", "earned_premium")
)
monthly_portfolio
# The allocated monthly amounts reconcile to the source portfolio.
aggregate(
cbind(earned_exposure, earned_premium) ~ id,
data = monthly_portfolio,
FUN = sum
)
# Deprecated interface with unquoted column names
if (FALSE) {
period_to_months(
portfolio,
coverage_start,
coverage_end,
earned_exposure,
earned_premium
)
}
Run the code above in your browser using DataLab