Commit ef059688 authored by Carl Corder's avatar Carl Corder
Browse files

roll claims up to a yearly basis for each group.

parent d4ce0db3
......@@ -19,16 +19,30 @@ tax <- read_excel(input, sheet = "Tax") # join by state
data <- data %>% select(-c(ICOS, WAIVER_IBNR, GAAP_RESV, WAIVER_RESERVE))
# create date from incurred year and month
data <- data %>% mutate(INC_DATE = as.Date(paste(INC_YEAR, INC_MONTH, "01", sep = "-")))
#data <- data %>% mutate(INC_DATE = as.Date(paste(INC_YEAR, INC_MONTH, "01", sep = "-")))
# drop redundant incurred date columns
data <- data %>% select(-c(INC_MONTH, INC_YEAR, INC_MONTHYEAR))
# drop redundant incurred date columns, keep INC_YEAR for grouping
data <- data %>% select(-c(INC_MONTH, INC_MONTHYEAR))
# drop broker and LFG sales rep hash key
#data <- data %>% select(-c(DIST_ID, REP_ID))
# positive lives, duration, premiums, claims and reserves
data <- data %>% filter(MAX_LIVES > 0, POLICY_DURATION >= 0,
EST_ANNUALIZED_NET_PREM > 0, PREM > 0,
PAID_CLAIMS >= 0, IBNR > 0)
# format policy effective date
data <- data %>% mutate(POLICY_EFFECTIVE_DATE = as.Date(data$POLICY_EFFECTIVE_DATE, "%Y-%m-%d"))
# group claims on annual basis
data <- data %>% group_by(GROUP_ID, DIST_ID, REP_ID,
COVG_CODE, TRUE_GROUP_VOL, POLICY_EFFECTIVE_DATE,
REG_OFFICE, SIC, STATE,
MAX_LIVES, ACTIVE_TERMED, LTD_INDICATOR, INC_YEAR, POLICY_DURATION) %>%
summarise(PREM = sum(PREM), EST_ANNUALIZED_NET_PREM = mean(EST_ANNUALIZED_NET_PREM),
PAID_COMMISSION = sum(PAID_COMMISSION), PAID_CLAIMS = sum(PAID_CLAIMS), IBNR = sum(IBNR))
# left outer-join on industry code
data <- merge(x = data, y = sic, by.x = "SIC", by.y = "SIC_CODE", all.x = TRUE)
......@@ -41,6 +55,9 @@ data <- data %>% filter(!is.na(INDUSTRY))
# left outer-join on demographics (age, gender & salary)
data <- merge(x = data, y = demographic, by.x = "GROUP_ID", by.y = "GROUP_ID", all.x = TRUE)
# remove groups without demographics
data <- data %>% filter(!is.na(AVG_AGE), !is.na(AVG_SALARY), !is.na(PCT_FEMALE))
# append percent commission
data <- merge(x = data,
y = commission[, c("GROUP_ID", "POLICY_DURATION", "PERCENT_COMMISSION")],
......@@ -70,8 +87,7 @@ data <- data %>% mutate(REGION = case_when(STATE %in% regions$east ~ "east",
get_internal_expense <- function(premium) {
sapply(premium, function(x) {
for (i in 1:nrow(expense)) {
if (x >= expense$EST_ANN_NET_PREM_MIN[i] &
x < expense$EST_ANN_NET_PREM_MAX[i]) {
if (expense$EST_ANN_NET_PREM_MIN[i] <= x & x < expense$EST_ANN_NET_PREM_MAX[i]) {
return(expense$INTERNAL_EXPENSE[i])
}
}
......@@ -126,14 +142,11 @@ data <- data %>% mutate(ACTUAL_CLAIMS = PAID_CLAIMS + IBNR)
# calculate actual to expected ratio
data <- data %>% mutate(ACTUAL_TO_EXPECTED = ACTUAL_CLAIMS / EXPECTED_CLAIMS)
# formatting
data <- data %>% mutate(POLICY_EFFECTIVE_DATE = as.Date(data$POLICY_EFFECTIVE_DATE, "%Y-%m-%d"))
# re-order columns
data <- data %>% select("GROUP_ID", "DIST_ID", "REP_ID",
"REG_OFFICE", "STATE", "REGION", "INDUSTRY", "SUB_INDUSTRY",
"AVG_SALARY", "AVG_AGE", "PCT_FEMALE",
"POLICY_EFFECTIVE_DATE", "INC_DATE", "POLICY_DURATION",
"POLICY_EFFECTIVE_DATE", "POLICY_DURATION",
"COVG_CODE", "TRUE_GROUP_VOL", "ACTIVE_TERMED", "LTD_INDICATOR",
"MAX_LIVES", "PREM", "NEEDED_PREMIUM", "RTN", "EST_ANNUALIZED_NET_PREM",
"PAID_COMMISSION", "PAID_CLAIMS", "IBNR", "ACTUAL_CLAIMS", "EXPECTED_CLAIMS", "ACTUAL_TO_EXPECTED",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment