Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • R/LifeInsureR
1 result
Select Git revision
Show changes
Commits on Source (4)
Version: 1.0.0
Date: 2023-10-27 15:52:28 UTC
SHA: f06a2e16963b59f836d6231a86043ef5996e638f
# Version 1.0.1: XXXXXXXXXXX XX, 2023
* New parameters:
- survivalBenefit: Generalize survival benefit vectors (previously: unit CF 1 at end of contract)
- gammaInZillmer: As a feature, include gamma costs (but not beta) in the Zillmer premium
* Improve test case generation: Als generate code to export sample contract to Excel
# Version 1.0.0: October 27, 2023
* Renamed package from LifeInsuranceContracts to LifeInsureR
......@@ -350,6 +350,16 @@ InsuranceContract.Values = list(
#' \item{\code{$deathBenefit}}{The yearly relative death benefit (relative
#' to the initial sum insured); Can be set to a \code{function(len,
#' params, values)}, e.g. \code{deathBenefit = deathBenefit.linearDecreasing}}
#' \item{\code{$survivalBenefit}}{The survival benefit (relative to the initial
#' sum insured). By default, for (pure) endowments a survival benefit
#' of 1 is assumed at the end of the contract period. Other values
#' (e.g. double survival benefit in endowments) or multiple survival
#' payments during the contract period can be set with this parameter.
#' A single numeric value indicates a single survival benefit at
#' the end of the contract, a vector of numeric values indicates
#' yearly survival benefits (not neccessarily with a survival
#' payment at the end of the contract). Can be set to a \code{function(len,
#' params, values)} returning the benefit as a numeric value or vector.
#' \item{\code{$benefitParameter}}{(optional) Tariff-specific parameter to
#' indicate special benefit conditions (e.g. for non-constant benefits
#' the initial starting value, or a minimum benefit, etc.). This
......@@ -482,6 +492,8 @@ InsuranceContract.Values = list(
#' reserve) (default: TRUE)}
#' \item{\code{$betaGammaInZillmer}}{Whether beta and gamma-costs should be
#' included in the Zillmer premium calculation}
#' \item{\code{$gammaInZillmer}}{Whether gamma- (but not beta-) costs should be
#' included in the Zillmer premium calculation}
#' \item{\code{$alphaRefundLinear}}{Whether the refund of alpha-costs on
#' surrender is linear in t or follows the NPV of an annuity}
#' \item{\code{$useUnearnedPremiums}}{Whether unearned premiums should be
......@@ -592,6 +604,7 @@ InsuranceContract.ParameterDefaults = list(
premiumIncrease = 1, # The yearly growth factor of the premium, i.e. 1.05 means +5% increase each year; a Vector describes the premiums for all years
annuityIncrease = 1, # The yearly growth factor of the annuity payments, i.e. 1.05 means +5% incrase each year; a vector describes the annuity unit payments for all years
deathBenefit = 1, # The yearly relative death benefit (relative to the initial sum insured); Can be fixed, e.g. 0.5 for 50% death cover, or set to a function(len, params, values) like deathBenefit = deathBenefit.linearDecreasing
survivalBenefit = NULL, # The custom survival benefit (for endowments and pure endowments). By default, a single payment of 1 at the end of the contract is assumed, unless this parameter give a different value/vector.
benefitParameter = NULL, # Tariff-Specific additional parameter to define custom benefits (e.g. a minimum death benefit quota, an initial )
costWaiver = 0, # The cost waiver (up to minCosts, 0=no cost waiver, 1=full cost waiver down to minCosts)
......@@ -638,6 +651,7 @@ InsuranceContract.ParameterDefaults = list(
Features = list( # Special cases for the calculations
zillmering = TRUE, # Whether the contract uses Zillmering (and bases reserves on the Zillmer reserve as opposed to the adequate reserve)
betaGammaInZillmer = FALSE, # Whether beta and gamma-costs should be included in the Zillmer premium calculation
gammaInZillmer = FALSE, # Whether gamma- (but not beta-) costs should be included in the Zillmer premium calculation
alphaRefundLinear = TRUE, # Whether the refund of alpha-costs on surrender is linear in t or follows the NPV of an annuity
useUnearnedPremiums = isRegularPremiumContract, # Whether unearned premiums should be calculated in the balance sheet reserves. Otherwise, a premium paid at the beginning of the period is added to the reserve for balance-sheet purposes.
surrenderIncludesCostsReserves = TRUE, # Whether (administration) cost reserves are paid out on surrender (i.e. included in the surrender value before surrender penalties are applied)
......
......@@ -462,7 +462,7 @@ InsuranceTarif = R6Class(
#' - For constant death benefit it will be rep(1, policyPeriod),
#' - for linearly decreasing sum insured it will be (policyPeriod:0)/policyPeriod
#' @details Not to be called directly, but implicitly by the [InsuranceContract] object.
#' @param len The desired length of the returned data frame (the number of contract periods desire)
#' @param len The desired length of the returned data frame (the number of contract periods desired)
getDeathCF = function(len, params, values) {
if (getOption('LIC.debug.getDeathCF', FALSE)) {
browser();
......@@ -484,6 +484,29 @@ InsuranceTarif = R6Class(
}
},
#' @description Returns the unit survival cash flow profile for the whole contract
#' period (after potential deferral period!)
#' - a single numeric value indicates a single survival payment at the end of the contract
#' - a vector of numeric values indicates potentially multiple survival payments for the whole contract period (paddded with 0 to the full contract length if shorter)
#' @details Not to be called directly, but implicitly by the [InsuranceContract] object.
getSurvivalCF = function(len, params, values) {
if (getOption('LIC.debug.getSurvivalCF', FALSE)) {
browser();
}
benefit = valueOrFunction(params$ContractData$survivalBenefit, len = len, params = params, values = values)
if (is.null(benefit)) {
benefit = 1
}
if (is.vector(benefit) && length(benefit) == 1) {
c(rep(0, len - 1), benefit)
} else {
# If survivalBenefit is (or returns) a vector, treat it as yearly
# survival payments, pad it to the desired length
pad0(benefit, len)
}
},
#' @description Returns the basic (unit) cash flows associated with the type
#' of insurance given in the InsuranceTarif's `tariffType` field
#' @details Not to be called directly, but implicitly by the [InsuranceContract] object.
......@@ -537,7 +560,7 @@ InsuranceTarif = R6Class(
deathCF = self$getDeathCF(values$int$l - 1 - deferralPeriod, params = params, values = values)
if (self$tariffType == "endowment" || self$tariffType == "pureendowment" || self$tariffType == "endowment + dread-disease") {
cf$survival = c(rep(0, values$int$policyTerm), 1)
cf$survival = pad0(self$getSurvivalCF(len = values$int$l, params = params, values = values), values$int$l)
}
if (self$tariffType == "endowment" || self$tariffType == "wholelife" || self$tariffType == "endowment + dread-disease") {
cf$death = c(rep(0, deferralPeriod), deathCF, 0)
......@@ -995,6 +1018,9 @@ InsuranceTarif = R6Class(
if (params$Features$betaGammaInZillmer) {
affected = c(affected, "beta", "gamma")
}
if (params$Features$gammaInZillmer) {
affected = c(affected, "gamma")
}
coeff[["SumInsured"]][["costs"]][affected,"SumInsured", ] = 1;
coeff[["SumInsured"]][["costs"]][affected,"SumPremiums", ] = values$unitPremiumSum * premiums[["unit.gross"]];
coeff[["SumInsured"]][["costs"]][affected,"GrossPremium",] = premiums[["unit.gross"]];
......
......@@ -172,7 +172,7 @@ makeContractGridDimnames = function(axes) {
#'
#' @rdname contractGrid
#'
#' @example
#' @examples
#' library("MortalityTables")
#' mortalityTables.load("Austria_Annuities_AVOe2005R")
#' # A trivial deferred annuity tariff with no costs, premiums during whole
......
......@@ -354,7 +354,9 @@ vmGlgExample.generateTest = function(contract, prf = 10, t = 10, t_prf = 12, ...
paste(names(arguments), arguments, sep = " = ", collapse = ",\n\t\t")
);
code = paste0(code, "\n\t);\n")
code = paste0(code, "\t# showVmGlgExamples(contract, t = ", t, ", prf = ", prf, ", t_prf = ", t_prf, ");\n\n")
code = paste0(code, "\t# showVmGlgExamples(contract, t = ", t, ", prf = ", prf, ", t_prf = ", t_prf, ");\n")
code = paste0(code, "\t# exportInsuranceContract.xlsx(contract, filename = here(\"", cntr, ".xlsx\"));\n")
code = paste0(code, "\t# openxlsx::openXL(here(\"", cntr, ".xlsx\"));\n\n")
code = paste0(code, "\ttestVmGlgExample(\n\t\tcontract, \n\t\tt = ", t, ", prf = ", prf, ", t_prf = ", t_prf, ",\n")
check.keys = c("net", "Zillmer", "gross", "written", "savings", "risk",
......
......@@ -243,6 +243,8 @@ reserves on the Zillmer reserve as opposed to the adequate
reserve) (default: TRUE)}
\item{\code{$betaGammaInZillmer}}{Whether beta and gamma-costs should be
included in the Zillmer premium calculation}
\item{\code{$gammaInZillmer}}{Whether gamma- (but not beta-) costs should be
included in the Zillmer premium calculation}
\item{\code{$alphaRefundLinear}}{Whether the refund of alpha-costs on
surrender is linear in t or follows the NPV of an annuity}
\item{\code{$useUnearnedPremiums}}{Whether unearned premiums should be
......
......@@ -99,4 +99,24 @@ contractGrid(
contractClosing = as.Date("2023-11-01")
)
library("MortalityTables")
mortalityTables.load("Austria_Annuities_AVOe2005R")
# A trivial deferred annuity tariff with no costs, premiums during whole
# deferral period, 30 years annuity payments:
tariff = InsuranceTarif$new(name="Test Annuity", type="annuity", tarif = "Annuity 1A",
mortalityTable = AVOe2005R.unisex, i=0.01,
deferralPeriod = function(params, ...) { params$ContractData$premiumPeriod },
policyPeriod = function(params, ...) { params$ContractData$premiumPeriod + 30 }
)
contractGridPremium(
axes = list(
age = seq(20, 60, 10),
premiumPeriod = seq(5,30, 5)
),
tarif = tariff,
sumInsured = 1000,
contractClosing = as.Date("2023-11-01")
)
}