diff --git a/NAMESPACE b/NAMESPACE index 5bf430846b19ed52a8584cd01af01ad653b934ec..688dc8dd87d3de17ecd73985d8d23c9138cd75f7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -57,6 +57,7 @@ export(applyHook) export(contractGrid) export(contractGridPremium) export(costs.baseAlpha) +export(costs.scaleAlpha) export(costsDisplayTable) export(deathBenefit.annuityDecreasing) export(deathBenefit.linearDecreasing) diff --git a/R/InsuranceParameters.R b/R/InsuranceParameters.R index 79a4937816cc9241fac536e3ba8fa13c847fc73f..77e788e18890e9485e352f658f26c377d7561e5b 100644 --- a/R/InsuranceParameters.R +++ b/R/InsuranceParameters.R @@ -163,6 +163,25 @@ costs.baseAlpha = function(alpha) { } } +#' Helper function to modify alpha costs of an insurance contract individually +#' +#' Returns a function that modifies alpha (and Zillmer) costs by the given scale, +#' but otherwise uses the full costs defined by the Costs parameter. +#' +#' This function can be set as adjustCosts or adjustMinCosts hook parameters +#' for a tariff or contract and can be used to apply cost adjustments on a +#' per-contract basis. +#' +#' @param scale The scale for alpha / Zillmer cost +#' +#' @export +costs.scaleAlpha = function(scale) { + function(costs, ...) { + costs[c("alpha", "Zillmer"),,] = costs[c("alpha", "Zillmer"),,] * scale + costs + } +} + #' Helper function to display all cost definitions in a concise table #' @@ -492,6 +511,8 @@ InsuranceContract.Values = list( #' \describe{ #' \item{\code{$adjustCashFlows}}{Function with signature \code{function(x, params, values, ...)} to adjust the benefit/premium cash flows after their setup.} #' \item{\code{$adjustCashFlowsCosts}}{Function with signature \code{function(x, params, values, ...)} to adjust the costs cash flows after their setup.} +#' \item{\code{$adjustCosts}}{Function with signature \code{function(costs, params, values, ...)} to adjust the tariff costs after their setup (e.g. contract-specific conditions/waivers, etc.).} +#' \item{\code{$adjustMinCosts}}{Function with signature \code{function(minCosts, costs, params, values, ...)} to adjust the tariff minimum (unwaivable) costs after their setup (e.g. contract-specific conditions/waivers, etc.).} #' \item{\code{$adjustPremiumCoefficients}}{Function with signature \code{function(coeff, type, premiums, params, values, premiumCalculationTime)} to adjust the coefficients for premium calculation after their default setup. Use cases are e.g. term-fix tariffs where the Zillmer premium term contains the administration cost over the whole contract, but not other gamma- or beta-costs.} #' } #' @@ -604,6 +625,8 @@ InsuranceContract.ParameterDefaults = list( # Functions with signature function(x, params, values, ...), default NULL is equivalent to function(x, ...) {x} adjustCashFlows = NULL, adjustCashFlowsCosts = NULL, + adjustCosts = NULL, + adjustMinCosts = NULL, adjustPremiumCoefficients = NULL # function(coeff, type = type, premiums = premiums, params = params, values = values, premiumCalculationTime = premiumCalculationTime) ) ); diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R index ec977def14b08b3b0b5c7cf4cf23ae94ef222b82..85b231c575e42d6ac3e4de03b9831ba098f2bd45 100644 --- a/R/InsuranceTarif.R +++ b/R/InsuranceTarif.R @@ -372,7 +372,9 @@ InsuranceTarif = R6Class( browser(); } costs = valueOrFunction(params$Costs, params = params, values = NULL) + costs = applyHook(params$Hooks$adjustCosts, costs, params = params, values = NULL); baseCost = valueOrFunction(params$minCosts, params = params, values = NULL, costs = costs) + baseCost = applyHook(params$Hooks$adjustMinCosts, baseCost, costs = costs, params = params, values = NULL); if (!is.null(baseCost)) { costWaiver = valueOrFunction(params$ContractData$costWaiver, params = params, values = NULL, costs = costs, minCosts = baseCost) if (is.numeric(costWaiver)) { diff --git a/man/InsuranceContract.ParameterDefaults.Rd b/man/InsuranceContract.ParameterDefaults.Rd index a50140771c264390b9845967000404e23bcb700e..1fc6fd8d7c19ffbc7188c97213e9aebae119d163 100644 --- a/man/InsuranceContract.ParameterDefaults.Rd +++ b/man/InsuranceContract.ParameterDefaults.Rd @@ -292,6 +292,8 @@ participation rates are defined at the level of profit classes.} \describe{ \item{\code{$adjustCashFlows}}{Function with signature \code{function(x, params, values, ...)} to adjust the benefit/premium cash flows after their setup.} \item{\code{$adjustCashFlowsCosts}}{Function with signature \code{function(x, params, values, ...)} to adjust the costs cash flows after their setup.} +\item{\code{$adjustCosts}}{Function with signature \code{function(costs, params, values, ...)} to adjust the tariff costs after their setup (e.g. contract-specific conditions/waivers, etc.).} +\item{\code{$adjustMinCosts}}{Function with signature \code{function(minCosts, costs, params, values, ...)} to adjust the tariff minimum (unwaivable) costs after their setup (e.g. contract-specific conditions/waivers, etc.).} \item{\code{$adjustPremiumCoefficients}}{Function with signature \code{function(coeff, type, premiums, params, values, premiumCalculationTime)} to adjust the coefficients for premium calculation after their default setup. Use cases are e.g. term-fix tariffs where the Zillmer premium term contains the administration cost over the whole contract, but not other gamma- or beta-costs.} } } diff --git a/man/InsuranceContract.Rd b/man/InsuranceContract.Rd index aa65807f7007757b351787272eb941d581ea3d46..aeb37c472395b655fc43989260b1adfb2b334c58 100644 --- a/man/InsuranceContract.Rd +++ b/man/InsuranceContract.Rd @@ -632,13 +632,15 @@ that time will be left unchanged.} \subsection{Method \code{premiumWaiver()}}{ Stop premium payments and re-calculate sumInsured of the paid-up contract \subsection{Usage}{ -\if{html}{\out{<div class="r">}}\preformatted{InsuranceContract$premiumWaiver(t)}\if{html}{\out{</div>}} +\if{html}{\out{<div class="r">}}\preformatted{InsuranceContract$premiumWaiver(t, ...)}\if{html}{\out{</div>}} } \subsection{Arguments}{ \if{html}{\out{<div class="arguments">}} \describe{ \item{\code{t}}{Time of the premium waiver.} + +\item{\code{...}}{Further parameters (currently unused)} } \if{html}{\out{</div>}} } diff --git a/man/costs.scaleAlpha.Rd b/man/costs.scaleAlpha.Rd new file mode 100644 index 0000000000000000000000000000000000000000..36e3ff21745a93c132b4b7e361804fc86d955864 --- /dev/null +++ b/man/costs.scaleAlpha.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/InsuranceParameters.R +\name{costs.scaleAlpha} +\alias{costs.scaleAlpha} +\title{Helper function to modify alpha costs of an insurance contract individually} +\usage{ +costs.scaleAlpha(scale) +} +\arguments{ +\item{scale}{The scale for alpha / Zillmer cost} +} +\description{ +Returns a function that modifies alpha (and Zillmer) costs by the given scale, +but otherwise uses the full costs defined by the Costs parameter. +} +\details{ +This function can be set as adjustCosts or adjustMinCosts hook parameters +for a tariff or contract and can be used to apply cost adjustments on a +per-contract basis. +}