From 5d86b8d052a4432fc88cc6559ebbd8ebb3a1bfd4 Mon Sep 17 00:00:00 2001
From: Kainhofer Reinhold <reinhold.kainhofer@generali.com>
Date: Tue, 10 Mar 2020 16:48:55 +0100
Subject: [PATCH] implement invalidityEndsContract flag (default TRUE)

If this flag is set (default), the contract ends when invalidity happens, i.e. the survival probability of the contract is
   px = 1 - qx - ix
If the flag is set to FALSE, a dread-disease/disability/morbidity claim is paid with propbability ix, but the contract continues, potentially paying our further disease claims in the future
---
 R/InsuranceParameters.R | 1 +
 R/InsuranceTarif.R      | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/R/InsuranceParameters.R b/R/InsuranceParameters.R
index 9e93bbf..883686b 100644
--- a/R/InsuranceParameters.R
+++ b/R/InsuranceParameters.R
@@ -119,6 +119,7 @@ InsuranceContract.ParameterDefaults = list(
     ActuarialBases = list(
         mortalityTable = NULL,
         invalidityTable = NULL,
+        invalidityEndsContract = FALSE,         # Whether a claim for disease ends the contract or not
         i = 0.00,                               # guaranteed interest rate
         balanceSheetDate = as.Date("1900-12-31"),  # Balance sheet date (for the calculation of the balance sheet reserves, year is irrelevant)
         balanceSheetMethod = "30/360",
diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R
index ccd5fd7..1544677 100644
--- a/R/InsuranceTarif.R
+++ b/R/InsuranceTarif.R
@@ -106,8 +106,13 @@ InsuranceTarif = R6Class(
         i = rep(0, length(q));
       }
       i = pad0(i, length(q));
-      # TODO: Implement case where invalidity/disease does NOT end the contract!
-      df = data.frame(age = ages, q = q, i = i, p = 1 - q - i, row.names = ages - age)
+      # invalidity/disease does NOT end the contract if flag is set!
+      if (params$ActuarialBases$invalidityEndsContract) {
+        p = 1 - q - i
+      } else {
+        p = 1 - q
+      }
+      df = data.frame(age = ages, q = q, i = i, p = p, row.names = ages - age)
       df
     },
 
-- 
GitLab