diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 0000000000000000000000000000000000000000..1c79fb43ca280a91b8cbde534de433e80921147f --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 1.0.0 +Date: 2023-10-27 15:52:28 UTC +SHA: f06a2e16963b59f836d6231a86043ef5996e638f diff --git a/R/InsuranceParameters.R b/R/InsuranceParameters.R index fd6e178de152314cfc5478c5a2f6bddb674c3b03..691d60355b420f4bf3cb2fd8cebe73e9530061f0 100644 --- a/R/InsuranceParameters.R +++ b/R/InsuranceParameters.R @@ -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 @@ -592,6 +602,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) diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R index 51d6195cbc6cfd9d37c6588003228ffc9a569b9b..bded4ea9b3b2217119bcc57b2d681130b00d21eb 100644 --- a/R/InsuranceTarif.R +++ b/R/InsuranceTarif.R @@ -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)