Skip to content
Snippets Groups Projects
Unverified Commit fbf603b5 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V0.0.6: Rename to LifeInsureR, retire old name LifeInsuranceContracts

There will still be a packge LifeInsuranceContracts, but that will only depend on LifeInsureR and contain links to the new package. No functionality will be provided.
parent aa001051
Branches
Tags
No related merge requests found
Showing
with 13 additions and 7634 deletions
...@@ -2,8 +2,3 @@ ...@@ -2,8 +2,3 @@
.Rhistory .Rhistory
.RData .RData
.~lock.*# .~lock.*#
R/Companies/
Formulas_Reference/2013*.xls*
LifeInsuranceContracts.Rproj
Vergleichsrechnung_Excel
inst/doc
Package: LifeInsuranceContracts Package: LifeInsuranceContracts
Type: Package Type: Package
Version: 0.0.5 Version: 0.0.6
Date: 2023-10-18 Date: 2023-10-20
Title: Framework for Traditional Life Insurance Contracts Title: Framework for Traditional Life Insurance Contracts
Description: R6 classes to model traditional life insurance Description: This package has been renamed to LifeInsureR, please use that package.
contracts like annuities, whole life insurances or endowments. Such life
insurance contracts provide a guaranteed interest and are not directly linked
to the performance of a particular investment vehicle. However, they typically
provide (discretionary) profit participation. This package provides a framework
to model such contracts in a very generic (cash-flow-based) way and includes
modelling profit participation schemes, dynamic increases or more general
contract layers, as well as contract changes (like sum increases or premium
waivers). All relevant quantities like premium decomposition, reserves and
benefits over the whole contract period are calculated and potentially
exported to excel. Mortalities are given using the 'MortalityTables' package.
Authors@R: c(person("Reinhold", "Kainhofer", role=c("aut", "cre"), email="reinhold@kainhofer.com")) Authors@R: c(person("Reinhold", "Kainhofer", role=c("aut", "cre"), email="reinhold@kainhofer.com"))
Author: Reinhold Kainhofer [aut, cre] Author: Reinhold Kainhofer [aut, cre]
Maintainer: Reinhold Kainhofer <reinhold@kainhofer.com> Maintainer: Reinhold Kainhofer <reinhold@kainhofer.com>
Encoding: UTF-8 Encoding: UTF-8
Imports: Imports:
R6, LifeInsureR,
MortalityTables, rmarkdown
objectProperties,
lubridate,
openxlsx,
dplyr,
scales,
abind,
stringr,
methods,
rlang,
rmarkdown,
kableExtra,
pander,
tidyr
License: GPL (>= 2) License: GPL (>= 2)
RoxygenNote: 7.2.3
Collate:
'HelperFunctions.R'
'InsuranceParameters.R'
'ProfitParticipation_Functions.R'
'ProfitParticipation.R'
'InsuranceTarif.R'
'InsuranceContract.R'
'addDataTableWorksheet.R'
'contractGrid.R'
'create_LIC_project.R'
'exportInsuranceContract_xlsx.R'
'showVmGlgExamples.R'
'exportInsuranceContractExample.R'
Suggests: Suggests:
knitr, knitr
magrittr,
tibble,
testthat,
fs
VignetteBuilder: knitr VignetteBuilder: knitr
Roxygen: list(markdown = TRUE) Roxygen: list(markdown = TRUE)
URL: https://gitlab.open-tools.net/R/r-life-insurance-contracts URL: https://gitlab.open-tools.net/R/LifeInsureR
BugReports: https://gitlab.open-tools.net/R/r-life-insurance-contracts/-/issues BugReports: https://gitlab.open-tools.net/R/LifeInsureR/-/issues
RoxygenNote: 7.2.3
# 2.2 Tariff implementation (InsuranceTarif)
library(magrittr)
library(MortalityTables)
library(lubridate)
library(LifeInsuranceContracts)
mortalityTables.load("Austria_Census")
mort.AT.census.2011.male
Tarif.L71U = InsuranceTarif$new(
name = "L71-U",
type = "wholelife",
tarif = "DeathPlus - Short Term Life Insurance",
desc = "Term Life insurance (5 years) with constant sum insured and regular premiums",
policyPeriod = 5, premiumPeriod = 5, # premiumPeriod not needed, defaults to maturity
mortalityTable = mortalityTable.mixed(
table1 = mort.AT.census.2011.male, weight1 = 0.65,
table2 = mort.AT.census.2011.female, weight2 = 0.35
),
i = 0.005,
tax = 0.04,
costs = initializeCosts(alpha = 0.05, gamma = 0.01, gamma.paidUp = 0.01, unitcosts = 10),
surrenderValueCalculation = function(surrenderReserve, params, values) {
surrenderReserve * 0.9
}
);
# 2.3 Creating a contract
contract.L71U = InsuranceContract$new(
Tarif.L71U,
age = 35,
contractClosing = as.Date("2020-08-18"),
sumInsured = 100000);
contract.L71U.1996R = InsuranceContract$new(
Tarif.L71U,
age = 35,
contractClosing = as.Date("2020-08-18"),
mortalityTable = AVOe1996R.male,
sumInsured = 100000);
contract.L71U$Values$premiums
contract.L71U.1996R$Values$premiums
library(openxlsx)
exportInsuranceContract.xlsx(contract.L71U, "L71U.xlsx")
openXL("L71U.xlsx")
contract.L71U$Values$premiums
contract.L71U$Values$reserves
contract.L71U$Values$cashFlows
contract.L71U$Values$cashFlowsCosts[,,,"survival"]
contract.L71U$Parameters$Costs %>% costsDisplayTable()
contract.L71U$Values$presentValues
contract.L71U$Values$presentValuesCosts
VMGL.contract = InsuranceContract$new(
Tarif.L71U,
age = 35, policyPeriod = 5, premiumPeriod
sumInsured = 100000,
contractClosing = as.Date("2020-07-01")
)
showVmGlgExamples(VMGL.contract, t_prf = 3, t = 3)
library(MortalityTables)
mortalityTables.load("Austria_Census")
mortalityTables.load("Austria_Annuities_AVOe2005R")
# Costs: 4% acquisition, where 2.5% are zillmered, 5\% of each premium as beta costs,
# 1%o acquisition costs of the sum insured over the whole contract period
example.Costs = initializeCosts(
alpha = 0.04, Zillmer = 0.025,
beta = 0.05,
gamma.contract = 0.001, gamma.paidUp = 0.001
)
example.Surrender = function(surrenderReserve, params, values) {
n = params$ContractData$policyPeriod
# Surrender Penalty is 10% at the beginning and decreases linearly to 0%
surrenderReserve * (0.9 + 0.1 * (0:n)/n)
}
Tarif.Endowment = InsuranceTarif$new(
name = "Example Tariff - Endowment",
type = "endowment",
tarif = "EN1",
desc = "An endowment with regular premiums",
mortalityTable = mort.AT.census.2011.unisex,
i = 0.005,
costs = example.Costs,
unitcosts = 10,
tax = 0.04, # 4% insurance tax
surrenderValueCalculation = example.Surrender
)
contract.Endowment.Dynamics = InsuranceContract$new(
tarif = Tarif.Endowment,
sumInsured = 10000,
age = 40,
policyPeriod = 10,
contractClosing = as.Date("2020-09-01"),
id = "Initial contract"
)$
addDynamics(t = 5, NewSumInsured = 11000, id = "Dynamic at 5")$
addDynamics(t = 7, NewSumInsured = 12000, id = "Dynamic at 7")$
addDynamics(t = 8, NewSumInsured = 13500, id = "Dynamic at 8")
contract.Endowment.Dynamics
exportInsuranceContract.xlsx(contract.Endowment.Dynamics, "dyn.xlsx")
openXL("dyn.xlsx")
contract.Endowment.Dynamics = InsuranceContract$new(
tarif = Tarif.Endowment,
sumInsured = 10000,
age = 40,
policyPeriod = 10,
contractClosing = as.Date("2020-09-01"),
id = "Initial contract"
)$addBlock(t = 3, tarif = Tarif.Endowment, age = 43, policyPeriod = 7,
sumInsured = 1000, premiumPeriod = 1, id = "Einmalzuzahlung at 5")
contract.L71U.prf = contract.L71U$premiumWaiver(t = 3)
contract.L71U.prf$Values$reservesBalanceSheet
contract.L71U.prf$Values$cashFlows
grd = contractGridPremium(
axes = list(mortalityTable = mort.AT.census["m", ], age = seq(20, 80, 10)),
tarif = Tarif.L71U,
sumInsured = 100000,
contractClosing = as.Date("2020-08-18")
)
File deleted
library(magrittr)
library(MortalityTables)
library(LifeInsuranceContracts)
mortalityTables.load("Austria_Census")
# Costs: 4% acquisition, where 2.5% are zillmered, 5\% of each premium as beta costs,
# 1%o acquisition costs of the sum insured over the whole contract period
example.Costs = initializeCosts(
alpha = 0.04, Zillmer = 0.025,
beta = 0.05,
gamma.contract = 0.001, gamma.paidUp = 0.001
)
example.Surrender = function(surrenderReserve, params, values) {
n = params$ContractData$policyPeriod
# Surrender Penalty is 10% at the beginning and decreases linearly to 0%
surrenderReserve * (0.9 + 0.1 * (0:n)/n)
}
Tarif.Endowment = InsuranceTarif$new(
name = "Example Tariff - Endowment",
type = "endowment",
tarif = "EN1",
desc = "An endowment with regular premiums",
mortalityTable = mort.AT.census.2011.unisex,
i = 0.005,
costs = example.Costs,
unitcosts = 10,
tax = 0.04, # 4% insurance tax
surrenderValueCalculation = example.Surrender
)
contract.Endowment = InsuranceContract$new(
Tarif.Endowment,
age = 50, policyPeriod = 35,
premiumFrequency = 12,
sumInsured = 100000,
contractClosing = as.Date("2020-07-01")
)
contract.exportExample = contract.Endowment$clone()$
addDynamics(t = 3, SumInsuredDelta = 10000)$
addDynamics(t = 5, SumInsuredDelta = 15000)$
addDynamics(t = 10, SumInsuredDelta = 15000)$
addDynamics(t = 14, SumInsuredDelta = 10000)
exportInsuranceContract.xlsx(contract.exportExample, filename = "Example_Endowment_Dynamics.xlsx")
openxlsx::openXL("Example_Endowment_Dynamics.xlsx")
*.aux
*.dvi
*.log
*.synctex.gz
*.backup
*.kilepr
Bernkopf Max
Formelsammlung_Beispielrechnung.toc
Formelsammlung_Beispielrechnung.out
.gitignore
File deleted
This diff is collapsed.
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
S3method(makeContractGridDimname,InsuranceTarif) import(LifeInsureR)
S3method(makeContractGridDimname,R6)
S3method(makeContractGridDimname,default)
S3method(makeContractGridDimname,double)
S3method(makeContractGridDimname,mortalityTable)
S3method(makeContractGridDimname,numeric)
export(CalculationEnum)
export(InsuranceContract)
export(InsuranceContract.ParameterDefaults)
export(InsuranceContract.ParameterStructure)
export(InsuranceContract.ParametersFallback)
export(InsuranceContract.ParametersFill)
export(InsuranceContract.Values)
export(InsuranceTarif)
export(PP.base.NULL)
export(PP.base.PreviousZillmerReserve)
export(PP.base.ZillmerReserveT2)
export(PP.base.ZillmerRiskPremium)
export(PP.base.contractualReserve)
export(PP.base.meanContractualReserve)
export(PP.base.previousContractualReserve)
export(PP.base.sumInsured)
export(PP.base.totalProfitAssignment)
export(PP.benefit.None)
export(PP.benefit.Profit)
export(PP.benefit.ProfitGuaranteeSupporting)
export(PP.benefit.ProfitPlusGuaranteedInterest)
export(PP.benefit.ProfitPlusHalfGuaranteedInterest)
export(PP.benefit.ProfitPlusHalfInterestMinGuaranteeTotal)
export(PP.benefit.ProfitPlusHalfTotalInterest)
export(PP.benefit.ProfitPlusInterestMinGuaranteeTotal)
export(PP.benefit.ProfitPlusTerminalBonusReserve)
export(PP.benefit.ProfitPlusTotalInterest)
export(PP.benefit.TerminalBonus)
export(PP.benefit.TerminalBonus5Years)
export(PP.benefit.TerminalBonus5YearsProRata)
export(PP.calculate.RateOnBase)
export(PP.calculate.RateOnBaseMin0)
export(PP.calculate.RateOnBaseSGFFactor)
export(PP.calculate.RatePlusGuaranteeOnBase)
export(PP.rate.expenseProfit)
export(PP.rate.interestProfit)
export(PP.rate.interestProfit2)
export(PP.rate.interestProfit2PlusGuarantee)
export(PP.rate.interestProfitPlusGuarantee)
export(PP.rate.riskProfit)
export(PP.rate.sumProfit)
export(PP.rate.terminalBonus)
export(PP.rate.terminalBonusFund)
export(PP.rate.totalInterest)
export(PP.rate.totalInterest2)
export(PVfactory)
export(PaymentTimeEnum)
export(ProfitComponentsEnum)
export(ProfitParticipation)
export(SexEnum)
export(TariffTypeEnum)
export(age.exactRounded)
export(age.yearDifference)
export(applyHook)
export(contractGrid)
export(contractGridPremium)
export(costs.baseAlpha)
export(costs.scaleAlpha)
export(costsDisplayTable)
export(deathBenefit.annuityDecreasing)
export(deathBenefit.linearDecreasing)
export(exportInsuranceContract.xlsx)
export(exportInsuranceContractExample)
export(fallbackFields)
export(fillFields)
export(fillNAgaps)
export(filterProfitRates)
export(freqCharge)
export(head0)
export(initializeCosts)
export(isRegularPremiumContract)
export(isSinglePremiumContract)
export(makeContractGridDimname)
export(makeContractGridDimnames)
export(pad0)
export(padLast)
export(premiumRefundPeriod.default)
export(rollingmean)
export(setCost)
export(showVmGlgExamples)
export(sumProfits)
export(testVmGlgExample)
export(valueOrFunction)
export(vmGlgExample.generateTest)
exportClasses(CalculationSingleEnum)
exportClasses(PaymentTimeSingleEnum)
exportClasses(ProfitComponentsMultipleEnum)
exportClasses(SexSingleEnum)
exportClasses(TariffTypeSingleEnum)
import(MortalityTables)
import(R6)
import(dplyr)
import(lubridate)
import(openxlsx)
import(scales)
import(stringr)
import(tidyr)
importFrom(abind,abind)
importFrom(kableExtra,kable)
importFrom(lubridate,"year<-")
importFrom(lubridate,days)
importFrom(lubridate,interval)
importFrom(lubridate,month)
importFrom(lubridate,time_length)
importFrom(lubridate,year)
importFrom(lubridate,years)
importFrom(methods,is)
importFrom(methods,new)
importFrom(objectProperties,setSingleEnum)
importFrom(pander,pander)
importFrom(rlang,.data)
importFrom(rmarkdown,render) importFrom(rmarkdown,render)
importFrom(utils,head)
importFrom(utils,tail)
dummy.R
*.R.bak
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#' @include HelperFunctions.R InsuranceParameters.R
#'
#' @import dplyr
NULL
#' Helper functions for profit participation
#'
#' Various helper functions for the \code{ProfitParticipation} class that
#' provide the building blocks for the individual components of profit participation,
#' the rates and how the assigned profit is calculated.
#'
#' @name ProfitParticipationFunctions
#' @param rates data.frame of profit rates
#' @param params Contract-specific, full set of parameters of the contract
#' (merged parameters of the defaults, the tariff, the profit participation
#' scheme and the contract)
#' @param values Contract values calculated so far (guaranteed component of the
#' insurance contract, including cash flows, premiums, reserves etc.).
#' @param ... Other values that might be used for the calculation (currently unused)
#'
#' @param base The profit calculation base, on which the rate is to be applied
#' @param rate The profit participation rate
#' @param waiting A possible waiting period
NULL
shiftBy = function(rate, n = 1) {
nm = names(rate)
res = c(rep(0, n), head(rate, -n))
names(res) = nm
res
}
##########################################################################m##
# Calculation bases for the various types of profit ####
##########################################################################m##
#' @describeIn ProfitParticipationFunctions
#' Basis for profit: NONE (i.e. always returns 0)
#' @export
PP.base.NULL = function(rates, params, values, ...) {
rep(0, values$int$l)
};
#' @describeIn ProfitParticipationFunctions
#' Basis for profit: Previous Zillmer reserve (no administration cost reserve)
#' @export
PP.base.PreviousZillmerReserve = function(rates, params, values, ...) {
shiftBy(values$reserves[,"Zillmer"], n = 1)
}
#' @describeIn ProfitParticipationFunctions
#' Basis for profit: Zillmer reserve (no administration cost reserve) at time t-2
#' @export
PP.base.ZillmerReserveT2 = function(rates, params, values, ...) {
shiftBy(values$reserves[,"Zillmer"], n = 2)
}
#' @describeIn ProfitParticipationFunctions
#' Basis for profit: Contractual reserve (including administration costs) at time t
#' @export
PP.base.contractualReserve = function(rates, params, values, ...) {
pmax(0, values$reserves[,"contractual"])
};
#' @describeIn ProfitParticipationFunctions
#' Basis for profit: Contractual reserve (including administration costs) at time t-1
#' @export
PP.base.previousContractualReserve = function(rates, params, values, ...) {
shiftBy(values$reserves[,"contractual"], n = 1)
}
#' @describeIn ProfitParticipationFunctions
#' Basis for profit: Contractual reserve (including administration costs) averaged over t and t-1
#' @export
PP.base.meanContractualReserve = function(rates, params, values, ...) {
# Rolling mean of the value for the current and previous year.
pmax(0, rollingmean(c(0, values$reserves[,"contractual"])))
};
#' @describeIn ProfitParticipationFunctions
#' Basis for risk/mortality profit: Zillmer Risk Premium of the past year
#' @export
PP.base.ZillmerRiskPremium = function(rates, params, values, ...) {
# The risk premium of t=0 is used to determine the risk profit at time
# t=1, so shift the whole vector!
shiftBy(values$premiumComposition[,"Zillmer.risk"], n = 1)
};
#' @describeIn ProfitParticipationFunctions
#' Basis for expense/sum profit: sum insured
#' @export
PP.base.sumInsured = function(rates, params, values, ...) {
params$ContractData$sumInsured
};
#' @describeIn ProfitParticipationFunctions
#' Basis for Terminal Bonus Fund Assignment: total profit assignment of the year
#'
#' @param res the data.frame of reserves.
#' @export
PP.base.totalProfitAssignment = function(res, ...) {
res[,"totalProfitAssignment"]
}
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Profit rates for the various types of profit
# Can / shall be overridden in child classes that use other schemes!
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#' @describeIn ProfitParticipationFunctions
#' Returns the array of interest profit rates (keyed by year)
#' @export
PP.rate.interestProfit = function(rates, ...) {
rates$interestProfitRate
};
#' @describeIn ProfitParticipationFunctions
#' Returns the array of risk profit rates (keyed by year)
#' @export
PP.rate.riskProfit = function(rates, ...) {
rates$mortalityProfitRate
};
#' @describeIn ProfitParticipationFunctions
#' Returns the array of expense profit rates (keyed by year)
#' @export
PP.rate.expenseProfit = function(rates, ...) {
rates$expenseProfitRate
};
#' @describeIn ProfitParticipationFunctions
#' Returns the array of sum profit rates (keyed by year)
#' @export
PP.rate.sumProfit = function(rates, ...) {
rates$sumProfitRate
};
#' @describeIn ProfitParticipationFunctions
#' Returns the array of terminal bonus rates (keyed by year)
#' @export
PP.rate.terminalBonus = function(rates, ...) {
rates$terminalBonusRate
};
#' @describeIn ProfitParticipationFunctions
#' Returns the array of terminal bonus rates (keyed by year) as the terminal bonus fund ratio
#' @export
PP.rate.terminalBonusFund = function(rates, ...) {
rates$terminalBonusFundRate
};
#' @describeIn ProfitParticipationFunctions
#' Rate for interest on past profits: total credited rate, but at least the guarantee
#' @export
PP.rate.interestProfitPlusGuarantee = function(rates, ...) {
rates$interestProfitRate + rates$guaranteedInterest
};
#' @describeIn ProfitParticipationFunctions
#' Rate for interest on past profits: total creditedrate2, but at least the guarantee
#' @export
PP.rate.interestProfit2PlusGuarantee = function(rates, ...) {
rates$interestProfitRate2 + rates$guaranteedInterest
};
#' @describeIn ProfitParticipationFunctions
#' Rate for interest on past profits: total interest rate
#' @export
PP.rate.totalInterest = function(rates, ...) {
rates$totalInterest
};
#' @describeIn ProfitParticipationFunctions
#' Rate for interest on past profits: second total interest rate
#' @export
PP.rate.totalInterest2 = function(rates, ...) {
rates$totalInterest2
};
#' @describeIn ProfitParticipationFunctions
#' Rate for interest on past profits: second interest profit rate (not including guaranteed interest), keyed by year
#' @export
PP.rate.interestProfit2 = function(rates, ...) {
rates$interestProfitRate2
};
# TODO
#' @describeIn ProfitParticipationFunctions
#'
#' Calculate the terminal bonus reserve.
#' @param profits The data.frame of profits assigned
#' @param terminalBonus The terminal bonus calculated
#' @param terminalBonusAccount The terminal bonus account (like a bank account,
#' where terminal bonuses are accrued, potentiall discounted from the maturity)
getTerminalBonusReserve = function(profits, rates, terminalBonus, terminalBonusAccount, params, values, ...) {
n = length(terminalBonusAccount)
terminalBonusAccount * 1/(1.07) ^ ((n - 1):0)
};
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Calculations of the assigned profit amounts, based on the bases and
# rates defined with the functions above.
# Can / shall be overridden in child classes that use other bases!
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#' @describeIn ProfitParticipationFunctions
#' Calculate profit by a simple rate applied on the basis (with an optional waiting vector of values 0 or 1)
#' @export
PP.calculate.RateOnBase = function(base, rate, waiting, rates, params, values, ...) {
base * rate * waiting
};
#' @describeIn ProfitParticipationFunctions
#' Calculate profit by a simple rate applied on the basis (with an optional waiting vector of values 0 or 1), bound below by 0
#' @export
PP.calculate.RateOnBaseMin0 = function(base, rate, waiting, rates, params, values, ...) {
pmax(0, base * rate * waiting)
};
#' @describeIn ProfitParticipationFunctions
#' Calculate profit by a rate + guaranteed interest applied on the basis (with an optional waiting vector of values 0 or 1)
#' @export
PP.calculate.RatePlusGuaranteeOnBase = function(base, rate, waiting, rates, params, values, ...) {
base * (rate + rates$guaranteedInterest) * waiting
};
#' @describeIn ProfitParticipationFunctions
#' Calculate profit by a simple rate applied on the basis (with only (1-SGFFactor) put into profit participation, and an optional waiting vector of values 0 or 1)
#' @export
PP.calculate.RateOnBaseSGFFactor = function(base, rate, waiting, rates, params, values, ...) {
base * rate * waiting * (1 - rates$terminalBonusFund)
};
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Calculations of the benefits, based on the assigned profit amounts and
# rates defined with the functions above.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#' @describeIn ProfitParticipationFunctions
#' Extract the given columns of the profit participation array of values and sum
#' them up. Columns that do not exist, because the profit scheme does not
#' provide the corresponding profit component will be silently ignored.
#' This allows generic benefit calculation functions to be written that do
#' not need to distinguish e.g. whether an old-style terminal bonus or a terminal
#' bonus fund is provided.
#'
#' This function is not meant to be called directly, but within a profit benefit
#' calculation function.
#'
#' @param profits The array of profit participation component values
#' @param cols The columns of the profit values array to be summed (columns given that do not exist in the profits array are ignired)
#' @export
sumProfits = function(profits, cols) {
# extract the columns -- if they exist -- and sum them up:
rowSums(
profits[, intersect(cols, colnames(profits)), drop = FALSE]
)
}
#' @describeIn ProfitParticipationFunctions
#' Calculate survival benefit as total profit amount plus the terminal bonus reserve
#' @export
PP.benefit.ProfitPlusTerminalBonusReserve = function(profits, ...) {
sumProfits(profits, c("regularBonus", "TBF", "terminalBonusReserve"))
};
#' @describeIn ProfitParticipationFunctions
#' Calculate benefit as total profit accrued so far
#' @export
PP.benefit.Profit = function(profits, ...) {
profits[,"regularBonus"]
};
#' @describeIn ProfitParticipationFunctions
#' Calculate accrued death benefit as total profit with (guaranteed) interest for one year
#' @export
PP.benefit.ProfitPlusGuaranteedInterest = function(profits, rates, ...) {
profits[,"regularBonus"] * (1 + rates$guaranteedInterest)
};
#' @describeIn ProfitParticipationFunctions
#' Calculate accrued death benefit as total profit with total interest (interest on profit rate) for one year
#' @export
PP.benefit.ProfitPlusTotalInterest = function(profits, rates, params, values) {
profits[,"regularBonus"] * (1 + profits[,"interestOnProfitRate"])
};
#' @describeIn ProfitParticipationFunctions
#' Calculate accrued benefit as total profit with total interest (interest on profit rate) for half a year
#' @export
PP.benefit.ProfitPlusHalfTotalInterest = function(profits, ...) {
profits[,"regularBonus"] * (1 + profits[,"interestOnProfitRate"]/2)
};
#' @describeIn ProfitParticipationFunctions
#' Calculate death benefit as total profit with (guaranteed) interest for one year
#' @export
PP.benefit.ProfitPlusHalfGuaranteedInterest = function(profits, rates, ...) {
profits[,"regularBonus"] * (1 + rates$guaranteedInterest/2)
};
#' @describeIn ProfitParticipationFunctions
#' Calculate accrued benefit as total profit with interest for one year (max of guarantee and total interest)
#' @export
PP.benefit.ProfitPlusInterestMinGuaranteeTotal = function(profits, rates, ...) {
profits[,"regularBonus"] * (1 + pmax(rates$guaranteedInterest, rates$totalInterest))
};
#' @describeIn ProfitParticipationFunctions
#' Calculate accrued benefit as total profit with interest for half a year (max of guarantee and total interest)
#' @export
PP.benefit.ProfitPlusHalfInterestMinGuaranteeTotal = function(profits, rates, ...) {
profits[,"regularBonus"] * (1 + pmax(rates$guaranteedInterest, rates$totalInterest)/2)
};
#' @describeIn ProfitParticipationFunctions
#' Calculate accrued benefit as regular profit, but used to cover initial Zillmerization
#' @export
PP.benefit.ProfitGuaranteeSupporting = function(profits, rates, params, values, ...) {
pmax(0, values$reserves[,"contractual"] + profits[,"regularBonus"] - pmax(0, values$reserves[,"contractual"]))
};
#' @describeIn ProfitParticipationFunctions
#' Calculate benefit from terminal bonus as 1/n parts of the terminal bonus reserve during the last 5 years
#' @export
PP.benefit.TerminalBonus5YearsProRata = function(profits, params, ...) {
n = params$ContractData$policyPeriod;
sumProfits(profits, c("TBF", "terminalBonusReserve")) * (0:n)/n * ((0:n) >= max(10, n - 5))
};
#' @describeIn ProfitParticipationFunctions
#' Terminal bonus is only paid out during the last 5 years of the contract (but never during the first 10 years)
#' @export
PP.benefit.TerminalBonus5Years = function(profits, params, ...) {
n = params$ContractData$policyPeriod;
sumProfits(profits, c("TBF", "terminalBonusReserve")) * ((0:n) >= max(10, n - 5))
}
#' @describeIn ProfitParticipationFunctions
#' Calculate benefit from terminal bonus (full bonus), either old-style terminal bonus reserve or Terminal Bonus Fund (TBF)
#' @export
PP.benefit.TerminalBonus = function(profits, params, ...) {
sumProfits(profits, c("TBF", "terminalBonusReserve"))
};
#' @describeIn ProfitParticipationFunctions
#' No benefit paid out
#' @export
PP.benefit.None = function(profits, ...) {
0
};
"dummy"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment