diff --git a/DESCRIPTION b/DESCRIPTION index 507d83923ce5073902c3faeebde6c617773acc46..1e749871a7fab6a8c4bf6dace057aba141d29dc3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: LifeInsuranceContracts Type: Package -Version: 0.1 -Date: 2016-05-07 +Version: 0.0.1 +Date: 2018-09-01 Title: A framework for general, traditional life insurance contracts, including profit participation and contract changes Description: R6 classes to model traditional life insurance @@ -44,6 +44,7 @@ Suggests: rmarkdown, pander, kableExtra, - magrittr + magrittr, + tibble VignetteBuilder: knitr Roxygen: list(markdown = TRUE) diff --git a/R/InsuranceContract.R b/R/InsuranceContract.R index 54e9398b0ec51e05318efcdae10fdbfc76270ad0..21b3bf7e7eda024c6f40014bb8fa5b5b87e03b6e 100644 --- a/R/InsuranceContract.R +++ b/R/InsuranceContract.R @@ -455,6 +455,7 @@ InsuranceContract = R6Class( # TODO: Generalize this to also allow specifying dynamic premium rather than sum insured if (!missing(SumInsuredDelta)) { SIdelta = SumInsuredDelta + NewSumInsured = SIdelta + self$Values$reserves[t + 1, "SumInsured"] } else if (!missing(NewSumInsured)) { SIdelta = NewSumInsured - self$Values$reserves[t + 1, "SumInsured"] } else { diff --git a/R/contractGrid.R b/R/contractGrid.R index 80e76b137a3549f0834494b2f61919005ddb8a4e..f7be7c45516f70db6066136a2db47b97fd9dfea0 100644 --- a/R/contractGrid.R +++ b/R/contractGrid.R @@ -1,13 +1,57 @@ -#' Create a multi-dimensional grid of InsuranceContract objects, where the axes -#' ranges are given with the axes argument. -#' This function will return the full InsuranceContract objects, so apply can -#' later be used to extract premiums, reserves and other values to display in -#' a grid. +#' @title Create a grid of InsuranceContract objects or premiums with each axis representing one varying parameter +#' +#' @description The function \code{contractGrid} creates a (two- or multi-dimensional) grid +#' of InsuranceContract objects, where each axis represents one of the insurance +#' parameters varying as given in the \code{axes} argument (as a named list). +#' +#' @description The function \code{contractGridPremium} returns a grid of premiums as requested in +#' the \code{premium} parameter rather than the full InsuranceContract objects. +#' It is a convenience wrapper around \code{contractGrid} and is recommended if +#' one is only interested in a grid of one particular value (typically some +#' kind of premium). +#' The function \code{contractGridPremium} can also be used on an existing +#' \code{contractGrid}-generated grid of contracts to extract grid of numerical +#' values of the specified premiums. If no contract grid is passed to +#' \code{contractGridPremium}, \code{contractGrid} will be called to create it. +#' +#' +#' @details The function \code{contractGrid} will return the full [InsuranceContract] +#' objects, so apply can later be used to extract premiums, reserves and other +#' values to display in a grid. For this feature, one can also use the convenience +#' function \code{contractGridPremium}. +#' +#' The \code{axes} list describing the parameters changing along the axes of the +#' resulting grid is internally expanded with [grid.expand()]. The resulting flat +#' list of parameter (together with the fixed parameters passed as \code{...}) +#' is then passed to the [InsuranceContract$new()] call to create the corresponding +#' contract object. +#' +#' To create the human-readable row-/columnnames of the resulting array, +#' the function [make.] +#' +#' #' #' @param axes List of paramters spanning the dimensions of the grid. #' @param YOB optional year of bith. If missing, the \code{observationYear} and the contract's age #' @param observationYear The observation year, for which the grid shall be calculated. If given, the YOB is calculated from it, otherwise the contract's YOB is used -#' @param ... Additional parameters to be passed to [InsuranceContract$new] +#' @param ... In \code{contractGrid}: Additional parameters to be passed to [InsuranceContract$new]; In \code{contractGridPremium}: Additional parameters to be passed to \code{contractGrid}. +# +# Params of the contractGridPreimium function: +#' @param contractGrid (optional) existing contract grid from which to derive +#' premiums. If not given, [contractGrid] is called with all parameters, so +#' \code{...} should contain an \code{axes} argument in that case. +#' @param premium The type of premium to derive (key of the \code{contract$Values$premiums} list. +#' @param .fun The function to extract the desired premium from a contract +#' object. By default it accesses the premium vector and extracts the +#' type of premium given in the \code{premium} parameter. One can, +#' however pass any other extractor function to access e.g. reserves, +#' cash flows etc. at any desired time. +#' +#' @rdname contractGrid +#' +#' @examples +#' # TODO +#' #' @export contractGrid = function(axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, 35, 5)), YOB = NULL, observationYear = NULL, ...) { @@ -26,57 +70,75 @@ contractGrid = function(axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, array(vals, dim = sapply(axes, length), dimnames = dimnames) } +#' @describeIn makeContractGridDimname Create a dimensional name for an [InsuranceTarif] object #' @export makeContractGridDimname.InsuranceTarif = function(value) { value$name } +#' @describeIn makeContractGridDimname Create a dimensional name for an R6 object (using its \code{name} field) #' @export makeContractGridDimname.R6 = function(value) { value$name } +#' @describeIn makeContractGridDimname Create a dimensional name for an [mortalityTable] object #' @export makeContractGridDimname.mortalityTable = function(value) { value@name } +#' @describeIn makeContractGridDimname Create a dimensional name for a numeric parameter value #' @export makeContractGridDimname.numeric = function(value) { value } +#' @describeIn makeContractGridDimname Create a dimensional name for a numeric parameter value #' @export makeContractGridDimname.double = function(value) { value } +#' @describeIn makeContractGridDimname Create a dimensional name for an object that can be directly used as a human-readable row-/columnname #' @export makeContractGridDimname.default = function(value) { value } -#' Generate a dimension label for the object passed as \code{value}, to be used in [contractGrid] +#' Create human-readable labels for the dimensions in a [contractGrid()] +#' +#' The funciton \code{makeContractGridDimname} generates a short, human-readable +#' dimension label for the object passed as \code{value}, to be used in [contractGrid]. +#' The default is to use the \code{value} unchanged as the row-/columnname, but +#' for some parameter values (like a [InsuranceTarif] or [mortalityTable]) +#' a custom method of this function is needed to create the (short) human-readable +#' representation for the axes in the grid. #' @param value the value along the axis, for which a name should be generated +# describeIn makeContractGridDimname Create a short, human-readable dimensional name for an object (default S3 method) #' @export makeContractGridDimname = function(value) { UseMethod("makeContractGridDimname", value) } -#' Generate proper dimnames for all exntries of the axes of a [contractGrid] +#' Generate proper dimnames for all entries of the axes of a [contractGrid()] #' @param axes the axes with all names, for which a name should be generated +#' @describeIn makeContractGridDimnames Generate proper dimnames for all entries of the axes of a [contractGrid()] #' @export makeContractGridDimnames = function(axes) { lapply(axes, function(axis) { lapply(axis, makeContractGridDimname); } ) } -#' Create a multi-dimensional grid of premiums for insurance contracts, where the axes -#' ranges are given with the axes argument. -#' This function will return the full InsuranceContract objects, so apply can -#' later be used to extract premiums, reserves and other values to display in -#' a grid. -#' +# Create a grid of insurance premiums with each axes representing one varying parameter +# +# The function \code{contractGridPremium} creates a (two- or multi-dimensional) grid +# of premiums for insurance contracts, where each axes represents one of the +# insurance parameters varying as given in the axes argument (as named list). +# +# This function will return the full InsuranceContract objects, so apply can +# later be used to extract premiums, reserves and other values to display in +# a grid. +# +# If one is only interested in a grid of one particular value (typically some +# kind of premium), the convenience function \code{contractGridPremium} is +# provided, which returns a grid of only the desired value. +# #' @param contractGrid (optional) existing contract grid from which to derive #' premiums. If not given, [contractGrid] is called with all parameters, so #' \code{...} should contain an \code{axes} argument in that case. #' @param premium The type of premium to derive (key of the \code{contract$Values$premiums} list. -#' @param ... Arguments pass on to [contractGrid] if no conract grid is given. +#' @param .fun The function to extract the desired premium from a contract +#' object. By default it accesses the premium vector and extracts the +#' type of premium given in the \code{premium} parameter. One can, +#' however pass any other extractor function to access e.g. reserves, +#' cash flows etc. at any desired time. +#' +#' @rdname contractGrid #' @export -contractGridPremium = function(contractGrid = NULL, premium="written", ...) { +contractGridPremium = function(contractGrid = NULL, premium="written", .fun = function(c) { c[[1]]$Values$premiums[[premium]] }, ...) { if (missing(contractGrid) || is.null(contractGrid)) { contractGrid = contractGrid(...) } - apply(contractGrid, 1:length(dim(contractGrid)), function(c) { c[[1]]$Values$premiums[[premium]] }) -} - -if (FALSE) { - gg = contractGrid(tarif = Generali.U188, axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, 35, 5)), sumInsured = 100000) - - contractGridPremium(gg) - apply(gg, 1:2, function(c) { c[[1]]$Parameters$ContractData$sumInsured }) - - contractGridPremium(tarif = Generali.U188, axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, 35, 5)), sumInsured = 100000) - - contractGridPremium(age = 30, axes = list(tarif = c(Generali.U188, Generali.U180, Generali.U3.1_2015), policyPeriod = seq(5, 35, 5)), sumInsured = 100000) + apply(contractGrid, 1:length(dim(contractGrid)), .fun) } diff --git a/man/contractGrid.Rd b/man/contractGrid.Rd index df7a9517a9a4b265a0fd1001c6c3a0c57b08af3d..ed0ef986125bded941d9d021dc1713460e255502 100644 --- a/man/contractGrid.Rd +++ b/man/contractGrid.Rd @@ -2,11 +2,8 @@ % Please edit documentation in R/contractGrid.R \name{contractGrid} \alias{contractGrid} -\title{Create a multi-dimensional grid of InsuranceContract objects, where the axes -ranges are given with the axes argument. -This function will return the full InsuranceContract objects, so apply can -later be used to extract premiums, reserves and other values to display in -a grid.} +\alias{contractGridPremium} +\title{Create a grid of InsuranceContract objects or premiums with each axis representing one varying parameter} \usage{ contractGrid( axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, 35, 5)), @@ -14,6 +11,13 @@ contractGrid( observationYear = NULL, ... ) + +contractGridPremium( + contractGrid = NULL, + premium = "written", + .fun = function(c) { c[[1]]$Values$premiums[[premium]] }, + ... +) } \arguments{ \item{axes}{List of paramters spanning the dimensions of the grid.} @@ -22,12 +26,51 @@ contractGrid( \item{observationYear}{The observation year, for which the grid shall be calculated. If given, the YOB is calculated from it, otherwise the contract's YOB is used} -\item{...}{Additional parameters to be passed to \link{InsuranceContract$new}} +\item{...}{In \code{contractGrid}: Additional parameters to be passed to \link{InsuranceContract$new}; In \code{contractGridPremium}: Additional parameters to be passed to \code{contractGrid}.} + +\item{contractGrid}{(optional) existing contract grid from which to derive +premiums. If not given, \link{contractGrid} is called with all parameters, so +\code{...} should contain an \code{axes} argument in that case.} + +\item{premium}{The type of premium to derive (key of the \code{contract$Values$premiums} list.} + +\item{.fun}{The function to extract the desired premium from a contract +object. By default it accesses the premium vector and extracts the +type of premium given in the \code{premium} parameter. One can, +however pass any other extractor function to access e.g. reserves, +cash flows etc. at any desired time.} } \description{ -Create a multi-dimensional grid of InsuranceContract objects, where the axes -ranges are given with the axes argument. -This function will return the full InsuranceContract objects, so apply can -later be used to extract premiums, reserves and other values to display in -a grid. +The function \code{contractGrid} creates a (two- or multi-dimensional) grid +of InsuranceContract objects, where each axis represents one of the insurance +parameters varying as given in the \code{axes} argument (as a named list). + +The function \code{contractGridPremium} returns a grid of premiums as requested in +the \code{premium} parameter rather than the full InsuranceContract objects. +It is a convenience wrapper around \code{contractGrid} and is recommended if +one is only interested in a grid of one particular value (typically some +kind of premium). +The function \code{contractGridPremium} can also be used on an existing +\code{contractGrid}-generated grid of contracts to extract grid of numerical +values of the specified premiums. If no contract grid is passed to +\code{contractGridPremium}, \code{contractGrid} will be called to create it. +} +\details{ +The function \code{contractGrid} will return the full \link{InsuranceContract} +objects, so apply can later be used to extract premiums, reserves and other +values to display in a grid. For this feature, one can also use the convenience +function \code{contractGridPremium}. + +The \code{axes} list describing the parameters changing along the axes of the +resulting grid is internally expanded with \code{\link[=grid.expand]{grid.expand()}}. The resulting flat +list of parameter (together with the fixed parameters passed as \code{...}) +is then passed to the \code{\link[=InsuranceContract$new]{InsuranceContract$new()}} call to create the corresponding +contract object. + +To create the human-readable row-/columnnames of the resulting array, +the function \link{make.} +} +\examples{ +# TODO + } diff --git a/man/contractGridPremium.Rd b/man/contractGridPremium.Rd deleted file mode 100644 index de0296777fd84ab328329ee2cb085541185541df..0000000000000000000000000000000000000000 --- a/man/contractGridPremium.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/contractGrid.R -\name{contractGridPremium} -\alias{contractGridPremium} -\title{Create a multi-dimensional grid of premiums for insurance contracts, where the axes -ranges are given with the axes argument. -This function will return the full InsuranceContract objects, so apply can -later be used to extract premiums, reserves and other values to display in -a grid.} -\usage{ -contractGridPremium(contractGrid = NULL, premium = "written", ...) -} -\arguments{ -\item{contractGrid}{(optional) existing contract grid from which to derive -premiums. If not given, \link{contractGrid} is called with all parameters, so -\code{...} should contain an \code{axes} argument in that case.} - -\item{premium}{The type of premium to derive (key of the \code{contract$Values$premiums} list.} - -\item{...}{Arguments pass on to \link{contractGrid} if no conract grid is given.} -} -\description{ -Create a multi-dimensional grid of premiums for insurance contracts, where the axes -ranges are given with the axes argument. -This function will return the full InsuranceContract objects, so apply can -later be used to extract premiums, reserves and other values to display in -a grid. -} diff --git a/man/makeContractGridDimname.Rd b/man/makeContractGridDimname.Rd index 92c729e96bdb58a974b2d53db7d0cb2d51f0b5ec..97cac4a8fcb8439198c60331ce3348e2d1928837 100644 --- a/man/makeContractGridDimname.Rd +++ b/man/makeContractGridDimname.Rd @@ -1,14 +1,52 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/contractGrid.R -\name{makeContractGridDimname} +\name{makeContractGridDimname.InsuranceTarif} +\alias{makeContractGridDimname.InsuranceTarif} +\alias{makeContractGridDimname.R6} +\alias{makeContractGridDimname.mortalityTable} +\alias{makeContractGridDimname.numeric} +\alias{makeContractGridDimname.double} +\alias{makeContractGridDimname.default} \alias{makeContractGridDimname} -\title{Generate a dimension label for the object passed as \code{value}, to be used in \link{contractGrid}} +\title{Create human-readable labels for the dimensions in a \code{\link[=contractGrid]{contractGrid()}}} \usage{ +\method{makeContractGridDimname}{InsuranceTarif}(value) + +\method{makeContractGridDimname}{R6}(value) + +\method{makeContractGridDimname}{mortalityTable}(value) + +\method{makeContractGridDimname}{numeric}(value) + +\method{makeContractGridDimname}{double}(value) + +\method{makeContractGridDimname}{default}(value) + makeContractGridDimname(value) } \arguments{ \item{value}{the value along the axis, for which a name should be generated} } \description{ -Generate a dimension label for the object passed as \code{value}, to be used in \link{contractGrid} +The funciton \code{makeContractGridDimname} generates a short, human-readable +dimension label for the object passed as \code{value}, to be used in \link{contractGrid}. +The default is to use the \code{value} unchanged as the row-/columnname, but +for some parameter values (like a \link{InsuranceTarif} or \link{MortalityTable}) +a custom method of this function is needed to create the (short) human-readable +representation for the axes in the grid. } +\section{Methods (by class)}{ +\itemize{ +\item \code{InsuranceTarif}: Create a dimensional name for an \link{InsuranceTarif} object + +\item \code{R6}: Create a dimensional name for an R6 object (using its \code{name} field) + +\item \code{mortalityTable}: Create a dimensional name for an \link{MortalityTable} object + +\item \code{numeric}: Create a dimensional name for a numeric parameter value + +\item \code{double}: Create a dimensional name for a numeric parameter value + +\item \code{default}: Create a dimensional name for an object that can be directly used as a human-readable row-/columnname +}} + diff --git a/man/makeContractGridDimnames.Rd b/man/makeContractGridDimnames.Rd index f8ced4fde975066216aa1a0e8a56ab1fdcf061da..989aacf1593f935385dc20b5d032dad264795169 100644 --- a/man/makeContractGridDimnames.Rd +++ b/man/makeContractGridDimnames.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/contractGrid.R \name{makeContractGridDimnames} \alias{makeContractGridDimnames} -\title{Generate proper dimnames for all exntries of the axes of a \link{contractGrid}} +\title{Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}}} \usage{ makeContractGridDimnames(axes) } @@ -10,5 +10,10 @@ makeContractGridDimnames(axes) \item{axes}{the axes with all names, for which a name should be generated} } \description{ -Generate proper dimnames for all exntries of the axes of a \link{contractGrid} +Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}} } +\section{Functions}{ +\itemize{ +\item \code{makeContractGridDimnames}: Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}} +}} + diff --git a/vignettes/using-the-lifeinsurancecontracts-package.Rmd b/vignettes/using-the-lifeinsurancecontracts-package.Rmd index b21cc4be7499b8b01c2f407939fbc7a14d1d1146..65ac3b738b27e4c5390e7cc01c2e9e6562db099b 100644 --- a/vignettes/using-the-lifeinsurancecontracts-package.Rmd +++ b/vignettes/using-the-lifeinsurancecontracts-package.Rmd @@ -268,8 +268,11 @@ contract.L71U$Values$cashFlows %>% select(starts_with('premiums'), starts_with(' ```{r SimpleExampleRiskCFCostCode, eval=F} contract.L71U$Values$cashFlowsCosts ``` -```{r SimpleExampleRiskCFCostOut, echo=F} -contract.L71U$Values$cashFlowsCosts +```{r SimpleExampleRiskCFCostOut, echo=F, results="asis"} +for (base in dimnames(contract.L71U$Values$cashFlowsCosts)[[3]]) { + cat("* ,,\"", base, "\"\n", sep = "") + cat(contract.L71U$Values$cashFlowsCosts[,,base ] %>% pander(round = 4, style = "rmarkdown")) +} ``` Once these unit cash flows are set, all insurance contracts are handled identically. @@ -285,8 +288,11 @@ contract.L71U$Values$presentValues %>% as.data.frame() %>% select(starts_with('p ```{r SimpleExampleRiskPVCostCode, eval=F} contract.L71U$Values$presentValuesCosts ``` -```{r SimpleExampleRiskPVCostOut, echo=F} -contract.L71U$Values$presentValuesCosts +```{r SimpleExampleRiskPVCostOut, echo=F, results="asis"} +for (base in dimnames(contract.L71U$Values$presentValuesCosts)[[3]]) { + cat("* ,,\"", base, "\"\n", sep = "") + cat(contract.L71U$Values$presentValuesCosts[,,base ] %>% pander(round = 4, style = "rmarkdown")) +} ``` ```{r SimpleExampleRiskPVPremCode, eval=F} contract.L71U$Values$premiums @@ -355,22 +361,35 @@ are passed unchanged to `InsuranceContract$new()`. First, let us create a grid of premiums for different ages and maturities (for sum insured 100,000 Euro): -```{r SimpleExampleRiskPremiumGrid} -contractGridPremium( +```{r SimpleExampleRiskPremiumGrid, eval=T, results="hide"} +grd = contractGridPremium( axes = list(age = seq(20, 80, 5), policyPeriod = seq(10, 40, 5)), tarif = Tarif.L71U, contractClosing = as.Date("2020-08-18"), sumInsured = 100000 ) +grd +``` +```{r SimpleExampleRiskPremiumGridOut, echo = F} +# TODO: Table with dimnames in vignette +grd %>% as.data.frame() %>% rownames_to_column("age | policyPeriod") %>% pander + ``` One can also pass more than two dimensions to the axes: -```{r SimpleExampleRiskPremiumGrid3D} -contractGridPremium( +```{r SimpleExampleRiskPremiumGrid3D, results = "hide"} +grd = contractGridPremium( axes = list(age = seq(20, 80, 10), policyPeriod = seq(10, 40, 10), sumInsured = c(10000, 50000, 100000)), tarif = Tarif.L71U, contractClosing = as.Date("2020-08-18") ) +grd +``` +```{r SimpleExampleRiskPremiumGrid3DOut, echo=F, results="asis"} +for (d in dimnames(grd)[[3]]) { + cat("* , , ", names(dimnames(grd))[[3]], "=", d, "\n", sep = "") + cat(grd[,,d ] %>% as.data.frame() %>% rownames_to_column("age \\| policyPeriod") %>% pander(digits = 7, round = 2, style = "rmarkdown")) +} ``` @@ -659,8 +678,8 @@ Waiving premiums and recalculating the sum insured is very easy, one just calls the method `InsuranceContract$premiumWaiver(t = ..)` on the existing contract. ```{r Contract.PureEndPrf} -contract.PureEnd.NoRefund$premiumWaiver(t=7) -contract.PureEnd.NoRefund$Values$reserves +contract.PureEnd.NoRefund.Prf = contract.PureEnd.NoRefund$clone()$premiumWaiver(t = 7) +contract.PureEnd.NoRefund.Prf$Values$reserves ``` Notice that the contract changes are made directly to the contract ("reference semantics"). This is @@ -803,7 +822,7 @@ initializeCosts() %>% dimnames The most common types of cost can be directly given in the call to `initializeCosts()`, but for some uncommon combinations, one can directly fill any of the fields in the three-dimensional array manually. -```{r costExample} +```{r costExample, eval=F} initializeCosts(alpha = 0.04, Zillmer = 0.025, beta = 0.05, gamma.contract = 0.001) # the above is the short form of: @@ -822,7 +841,7 @@ premium waiver at time 7), the absolute cost cash flows are: contract.PureEnd.NoRefund$Values$absCashFlows ``` ```{r costCashFlows, echo=F} -contract.PureEnd.NoRefund$Values$absCashFlows %>% select(alpha, Zillmer, beta, gamma, gamma_nopremiums, unitcosts) %>% pander() +contract.PureEnd.NoRefund$Values$absCashFlows[1:11,] %>% select(alpha, Zillmer, beta, gamma, gamma_nopremiums, unitcosts) %>% pander() ``` @@ -830,7 +849,7 @@ In addition to these standardized costs, which are included in the expense-loade premium (sometimes also called the "(actuarial) gross premium"), there are certain loadings and rebates that are applied after the expense-loaded premium $BP_x$: -$$P_\xn = \left\{ (BP_x + oUZu - SuRa) \cdot VS \cdot (1-VwGew) + unitC\right\} \cdot \left(1-PrRa-VwGew_{StkK}-PartnerRa\right)\cdot \left(1+uz(k)\right) \cdot (1+tax)$$ +$$P_x = \left\{ (BP_x + oUZu - SuRa) \cdot VS \cdot (1-VwGew) + unitC\right\} \cdot \left(1-PrRa-VwGew_{StkK}-PartnerRa\right)\cdot \left(1+uz(k)\right) \cdot (1+tax)$$ with the following surcharges and rebates: @@ -851,14 +870,118 @@ with the following surcharges and rebates: # Creating premium and contract grids +When developing a new product or comparing different products, it is often +required to create tables of premiums or reserves for a product/tarif where +just some of the parameters (like age, sum insured or maturity) change. + +For this purpose, this package provides two functions to create two- or +higher-dimensional grids of contracts with each dimension representing one +of the parameters varying. + +* `contra +TODO + # Exporting contract data to Excel +The LifeInsuranceContracts package also provides a function to export a given +contract to a spreadsheet in Excel format: + +* `exportInsuranceContract.xlsx(contract, filename)` + +This function takes the contract and exports all data.frames in the contract's +`contract$Values` data list as separate tabs to a spreadsheet file. It also +adds some nice formatting and additional markup. For contracts with multiple +contract blocks (e.g. dynamic increases / sum increases or riders), the main +contract and all its child blocks are exported as well. + +The tab containing the premiums and the premium calculation coefficients even +include the formulas, so one can in theory play around with the parameters to +see how the premium changes. + +If the contract has profit participation features and some profit scenarios have +been added, they are exported as well. + +Notice, however, that the Excel export is in general a static file containing +the current state of the contract and all its values (cash flows, present values, +premiums, reserves, profit participation, etc.) as well as the most important +parameters and an overview of the history of the contract. + +```{r ExcelExport,eval=F} +contract.exportExample = contract.PureEnd.NoRefund$clone()$ + addDynamics(t = 3, SumInsuredDelta = 10000)$ + addDynamics(t = 5, SumInsuredDelta = 15000)$ + addDynamics(t = 10, SumInsuredDelta = 15000)$ + addDynamics(t = 14, SumInsuredDelta = 10000) +exportInsuranceContract.xlsx(contract.exportExample, filename = "Example_PureEndowment_Dynamics.xlsx") +``` + + + +# Creating example values required for submission to the Austrian Financial Market Authority + +When introducing a new tariff, an Austrian insurance company has to submit +a detailled mathematical description (so-called "Versicherungsmathematische +Grundlagen") of the tariff to the Financial Market Authority (FMA), which have +to follow the [regulation on actuarial bases for life insurance -- LV-VMGV](https://www.ris.bka.gv.at/GeltendeFassung.wxe?Abfrage=Bundesnormen&Gesetzesnummer=20009298). The sections and contents +of this document are strictly defined in the regulation, and in addition to the +formulas of the tariff, an example contract has to be calculated with the following +key parameters: + +* age 35, duration 30 years (15 years for protection tariffs) +* sum insured 100 000 Euro / monthly annuity 1000 Euro for annuities +* yearly premiums during the whole contract period (defereal period of 30 years for annuities) +* intermediate values (reserves, etc.) have to be calculated at $t=10$. + +Given a tariff and a derived contract (with the above key parameters), this +package provides two functions to calculate and print / export +the required values either to the console / screen or to a file: + +* `showVmGlgExamples(contract, prf = 10, t = 10, t_prf = 12, file = "", ...)` +* `exportInsuranceContractExample(contract, prf = 10, outdir = ".", basename=NULL, extraname = NULL, ...)` + +The function `showVmGlgExamples` calculates all required values for the actuarial +bases document in the required order (including values after a premium waiver +at the given time). If a filename is given, the output is exported to that text file, +otherwise it is simply printed out in the R console: + +```{r VmGlgExample} +VMGL.contract = InsuranceContract$new( + Tarif.PureEnd, + age = 35, policyPeriod = 30, + premiumFrequency = 1, + sumInsured = 100000, + contractClosing = as.Date("2020-07-01") + ) + +showVmGlgExamples(VMGL.contract) +``` + + +The `exportInsuranceContractExample` provides no new functionality, but combines +the Excel export feature and the regulatory example together. For a given contract +it will create three files: + +* Excel export of the contract +* Excel export of the contract with a premium waiver applied at the given time +* The regulatory example (with premium waiver at the same time as in the Excel export) in a text file + +One can give a base name and an extra name to distinguish different calculations +in the file names. + + # Handling contracts with increases (fixed increasing benefits / premiums, dynamic increases, sum increases) +TODO + # Advance profit participation (premium rebate) +TODO # Profit participation schemes +TODO # Modifying the default calculation approach + +TODO +