From 1494646c23158f931e526ffd60f08dda92ef0b1b Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Thu, 12 Jan 2023 11:04:43 +0100
Subject: [PATCH] Annuities: For lifelong annuities, implement survival payment
 at the end of the final year of the lift table (only relevant if final qx<0).

---
 R/InsuranceTarif.R | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R
index a1c02f5..0fe1323 100644
--- a/R/InsuranceTarif.R
+++ b/R/InsuranceTarif.R
@@ -299,11 +299,13 @@ InsuranceTarif = R6Class(
       }
       age = params$ContractData$technicalAge
       maxAge = MortalityTables::getOmega(params$ActuarialBases$mortalityTable)
-      policyPeriod = params$ContractData$policyPeriod
+      policyTerm = min(maxAge + 1 - age, params$ContractData$policyPeriod)
       list(
-        l = min(maxAge - age, policyPeriod) + 1,
-        policyTerm = min(maxAge - age, policyPeriod),
-        premiumTerm = min(policyPeriod, params$ContractData$premiumPeriod)
+        l = min(maxAge +1 - age, policyTerm),
+        # maxAge is the last age with a given death probability, so it can be included in the policy term!
+        # The policy must end AFTER that final year, not at the beginning!
+        policyTerm = policyTerm,
+        premiumTerm = min(policyTerm, params$ContractData$premiumPeriod)
       )
     },
 
-- 
GitLab