From f76d205aee03af5276ba9b8627f815b0373ddabc Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Wed, 22 Nov 2023 00:12:05 +0100
Subject: [PATCH] Clean up minor mistakes / typos; Improve test case generation
 (include code to expoert sample contract to Excel)

---
 NEWS.md               |  7 +++++++
 R/InsuranceTarif.R    |  2 +-
 R/contractGrid.R      |  2 +-
 R/showVmGlgExamples.R |  4 +++-
 man/contractGrid.Rd   | 20 ++++++++++++++++++++
 5 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 5645ebd..c078859 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,11 @@
 
+# Version 1.0.1: XXXXXXXXXXX XX, 2023
+  * New parameters:
+    - survivalBenefit: Generalize survival benefit vectors (previously: unit CF 1 at end of contract)
+    - gammaInZillmer: As a feature, include gamma costs (but not beta) in the Zillmer premium
+  * Improve test case generation: Als generate code to export sample contract to Excel
+  
+
 # Version 1.0.0: October 27, 2023
   * Renamed package from LifeInsuranceContracts to LifeInsureR
 
diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R
index 6d55660..59539ee 100644
--- a/R/InsuranceTarif.R
+++ b/R/InsuranceTarif.R
@@ -462,7 +462,7 @@ InsuranceTarif = R6Class(
     #'   - For constant death benefit it will be rep(1, policyPeriod),
     #'   - for linearly decreasing sum insured it will be (policyPeriod:0)/policyPeriod
     #' @details Not to be called directly, but implicitly by the [InsuranceContract] object.
-    #' @param len The desired length of the returned data frame (the number of contract periods desire)
+    #' @param len The desired length of the returned data frame (the number of contract periods desired)
     getDeathCF = function(len, params, values) {
       if (getOption('LIC.debug.getDeathCF', FALSE)) {
         browser();
diff --git a/R/contractGrid.R b/R/contractGrid.R
index a5da2bb..7c87f7a 100644
--- a/R/contractGrid.R
+++ b/R/contractGrid.R
@@ -172,7 +172,7 @@ makeContractGridDimnames = function(axes) {
 #'
 #' @rdname contractGrid
 #' 
-#' @example
+#' @examples
 #' library("MortalityTables")
 #' mortalityTables.load("Austria_Annuities_AVOe2005R")
 #' # A trivial deferred annuity tariff with no costs, premiums during whole 
diff --git a/R/showVmGlgExamples.R b/R/showVmGlgExamples.R
index bb10d57..606f503 100644
--- a/R/showVmGlgExamples.R
+++ b/R/showVmGlgExamples.R
@@ -354,7 +354,9 @@ vmGlgExample.generateTest = function(contract, prf = 10, t = 10, t_prf = 12, ...
                   paste(names(arguments), arguments, sep = " = ", collapse = ",\n\t\t")
            );
     code = paste0(code, "\n\t);\n")
-    code = paste0(code, "\t# showVmGlgExamples(contract, t = ", t, ", prf = ", prf, ", t_prf = ", t_prf, ");\n\n")
+    code = paste0(code, "\t# showVmGlgExamples(contract, t = ", t, ", prf = ", prf, ", t_prf = ", t_prf, ");\n")
+    code = paste0(code, "\t# exportInsuranceContract.xlsx(contract, filename = here(\"", cntr, ".xlsx\"));\n")
+    code = paste0(code, "\t# openxlsx::openXL(here(\"", cntr, ".xlsx\"));\n\n")
     code = paste0(code, "\ttestVmGlgExample(\n\t\tcontract, \n\t\tt = ", t, ", prf = ", prf, ", t_prf = ", t_prf, ",\n")
 
     check.keys = c("net", "Zillmer", "gross", "written", "savings", "risk",
diff --git a/man/contractGrid.Rd b/man/contractGrid.Rd
index f84c465..fbaf359 100644
--- a/man/contractGrid.Rd
+++ b/man/contractGrid.Rd
@@ -99,4 +99,24 @@ contractGrid(
     contractClosing = as.Date("2023-11-01")
 )
 
+library("MortalityTables")
+mortalityTables.load("Austria_Annuities_AVOe2005R")
+# A trivial deferred annuity tariff with no costs, premiums during whole 
+# deferral period, 30 years annuity payments:
+tariff = InsuranceTarif$new(name="Test Annuity", type="annuity", tarif = "Annuity 1A",
+    mortalityTable = AVOe2005R.unisex, i=0.01, 
+    deferralPeriod = function(params, ...) { params$ContractData$premiumPeriod }, 
+    policyPeriod = function(params, ...) { params$ContractData$premiumPeriod + 30 }
+)
+contractGridPremium(
+    axes = list(
+        age = seq(20, 60, 10),
+        premiumPeriod = seq(5,30, 5)
+    ),
+    tarif = tariff,
+    sumInsured = 1000,
+    contractClosing = as.Date("2023-11-01")
+)
+
+
 }
-- 
GitLab