From 95142a49fd0acc024c02e4fc546cc1bfb995e171 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Wed, 8 Dec 2021 15:13:22 +0100
Subject: [PATCH] Add Features$absPremiumRefund to allow an addition death
 benefit

When a single-premium contract is used to emulate a paid-up contract with premium refund, the past premiums paid need to be given externally and is not related to the premium calculated for the contractis relative to the (new) sum insured.
---
 R/InsuranceParameters.R                    | 5 ++++-
 R/InsuranceTarif.R                         | 3 +++
 man/InsuranceContract.ParameterDefaults.Rd | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/R/InsuranceParameters.R b/R/InsuranceParameters.R
index a339e25..9caff53 100644
--- a/R/InsuranceParameters.R
+++ b/R/InsuranceParameters.R
@@ -467,6 +467,8 @@ InsuranceContract.Values = list(
 #'               surrender value before surrender penalties are applied)}
 #'     \item{\code{$unitcostsInGross}}{Whether unit costs are included in the
 #'               gross premium calculation or added after gross premiums. (default: FALSE)}
+#'     \item{\code{$absPremiumRefund}}{Constant death benefit (typically premium
+#'               refund of a previous contract), relative to the sum insured.}
 #' }
 #'
 #' ## Elements of sublist \code{InsuranceContract.ParameterDefault$ProfitParticipation}
@@ -591,7 +593,8 @@ InsuranceContract.ParameterDefaults = list(
         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)
-        unitcostsInGross = FALSE
+        unitcostsInGross = FALSE,
+        absPremiumRefund = 0                 # Constant death benefit (irrespective of the type of contract), typically a premium refund for a previous contract
     ),
 
     ProfitParticipation = list(
diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R
index 222634d..52734eb 100644
--- a/R/InsuranceTarif.R
+++ b/R/InsuranceTarif.R
@@ -591,6 +591,9 @@ InsuranceTarif = R6Class(
 
       # Death Benefits
       cf$death_SumInsured = pad0(values$cashFlowsBasic$death, cflen);
+      if ((!is.null(params$Features$absPremiumRefund)) && (params$Features$absPremiumRefund > 0)) {
+        cf$death_SumInsured = cf$death_SumInsured + pad0(padLast(params$Features$absPremiumRefund, cflen - 1), cflen);
+      }
       cf$disease_SumInsured = pad0(values$cashFlowsBasic$disease, cflen);
       cf$death_PremiumFree = cf$death_SumInsured;
       # premium refund
diff --git a/man/InsuranceContract.ParameterDefaults.Rd b/man/InsuranceContract.ParameterDefaults.Rd
index 925f970..3026da8 100644
--- a/man/InsuranceContract.ParameterDefaults.Rd
+++ b/man/InsuranceContract.ParameterDefaults.Rd
@@ -243,6 +243,8 @@ cost reserves are paid out on surrender (i.e. included in the
 surrender value before surrender penalties are applied)}
 \item{\code{$unitcostsInGross}}{Whether unit costs are included in the
 gross premium calculation or added after gross premiums. (default: FALSE)}
+\item{\code{$absPremiumRefund}}{Constant death benefit (typically premium
+refund of a previous contract), relative to the sum insured.}
 }
 }
 
-- 
GitLab