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

Add hooks (adjustCosts, adjustMinCosts) to allow modifying costs per contract...

Add hooks (adjustCosts, adjustMinCosts) to allow modifying costs per contract (i.e. modifying existing cost definitions from the tariff); Add function costs.scsaleAlpha
parent 1e0cc031
Branches
Tags
No related merge requests found
...@@ -57,6 +57,7 @@ export(applyHook) ...@@ -57,6 +57,7 @@ export(applyHook)
export(contractGrid) export(contractGrid)
export(contractGridPremium) export(contractGridPremium)
export(costs.baseAlpha) export(costs.baseAlpha)
export(costs.scaleAlpha)
export(costsDisplayTable) export(costsDisplayTable)
export(deathBenefit.annuityDecreasing) export(deathBenefit.annuityDecreasing)
export(deathBenefit.linearDecreasing) export(deathBenefit.linearDecreasing)
......
...@@ -163,6 +163,25 @@ costs.baseAlpha = function(alpha) { ...@@ -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 #' Helper function to display all cost definitions in a concise table
#' #'
...@@ -492,6 +511,8 @@ InsuranceContract.Values = list( ...@@ -492,6 +511,8 @@ InsuranceContract.Values = list(
#' \describe{ #' \describe{
#' \item{\code{$adjustCashFlows}}{Function with signature \code{function(x, params, values, ...)} to adjust the benefit/premium cash flows after their setup.} #' \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{$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.} #' \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( ...@@ -604,6 +625,8 @@ InsuranceContract.ParameterDefaults = list(
# Functions with signature function(x, params, values, ...), default NULL is equivalent to function(x, ...) {x} # Functions with signature function(x, params, values, ...), default NULL is equivalent to function(x, ...) {x}
adjustCashFlows = NULL, adjustCashFlows = NULL,
adjustCashFlowsCosts = NULL, adjustCashFlowsCosts = NULL,
adjustCosts = NULL,
adjustMinCosts = NULL,
adjustPremiumCoefficients = NULL # function(coeff, type = type, premiums = premiums, params = params, values = values, premiumCalculationTime = premiumCalculationTime) adjustPremiumCoefficients = NULL # function(coeff, type = type, premiums = premiums, params = params, values = values, premiumCalculationTime = premiumCalculationTime)
) )
); );
......
...@@ -372,7 +372,9 @@ InsuranceTarif = R6Class( ...@@ -372,7 +372,9 @@ InsuranceTarif = R6Class(
browser(); browser();
} }
costs = valueOrFunction(params$Costs, params = params, values = NULL) 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 = 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)) { if (!is.null(baseCost)) {
costWaiver = valueOrFunction(params$ContractData$costWaiver, params = params, values = NULL, costs = costs, minCosts = baseCost) costWaiver = valueOrFunction(params$ContractData$costWaiver, params = params, values = NULL, costs = costs, minCosts = baseCost)
if (is.numeric(costWaiver)) { if (is.numeric(costWaiver)) {
......
...@@ -292,6 +292,8 @@ participation rates are defined at the level of profit classes.} ...@@ -292,6 +292,8 @@ participation rates are defined at the level of profit classes.}
\describe{ \describe{
\item{\code{$adjustCashFlows}}{Function with signature \code{function(x, params, values, ...)} to adjust the benefit/premium cash flows after their setup.} \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{$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.} \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.}
} }
} }
......
...@@ -632,13 +632,15 @@ that time will be left unchanged.} ...@@ -632,13 +632,15 @@ that time will be left unchanged.}
\subsection{Method \code{premiumWaiver()}}{ \subsection{Method \code{premiumWaiver()}}{
Stop premium payments and re-calculate sumInsured of the paid-up contract Stop premium payments and re-calculate sumInsured of the paid-up contract
\subsection{Usage}{ \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}{ \subsection{Arguments}{
\if{html}{\out{<div class="arguments">}} \if{html}{\out{<div class="arguments">}}
\describe{ \describe{
\item{\code{t}}{Time of the premium waiver.} \item{\code{t}}{Time of the premium waiver.}
\item{\code{...}}{Further parameters (currently unused)}
} }
\if{html}{\out{</div>}} \if{html}{\out{</div>}}
} }
......
% 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.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment