Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • R/LifeInsureR
1 result
Select Git revision
Show changes
Commits on Source (5)
Showing
with 162 additions and 109 deletions
...@@ -8,3 +8,5 @@ ...@@ -8,3 +8,5 @@
^Examples ^Examples
.Rbuildignore$ .Rbuildignore$
^revdep$
^cran-comments\.md$
Package: LifeInsureR Package: LifeInsureR
Type: Package Type: Package
Version: 1.0.0 Version: 1.0.0
Date: 2023-10-20 Date: 2023-10-27
Title: Framework for Traditional Life Insurance Contracts Title: Modelling Traditional Life Insurance Contracts
Description: R6 classes to model traditional life insurance Description: R6 classes to model traditional life insurance
contracts like annuities, whole life insurances or endowments. Such life contracts like annuities, whole life insurances or endowments. Such life
insurance contracts provide a guaranteed interest and are not directly linked insurance contracts provide a guaranteed interest and are not directly linked
to the performance of a particular investment vehicle. However, they typically to the performance of a particular investment vehicle, but they typically
provide (discretionary) profit participation. This package provides a framework provide (discretionary) profit participation. This package provides a framework
to model such contracts in a very generic (cash-flow-based) way and includes to model such contracts in a very generic (cash-flow-based) way and includes
modelling profit participation schemes, dynamic increases or more general modelling profit participation schemes, dynamic increases or more general
contract layers, as well as contract changes (like sum increases or premium contract layers, as well as contract changes (like sum increases or premium
waivers). All relevant quantities like premium decomposition, reserves and waivers). All relevant quantities like premium decomposition, reserves and
benefits over the whole contract period are calculated and potentially benefits over the whole contract period are calculated and potentially
exported to excel. Mortality rates are given using the 'MortalityTables' package. exported to 'Excel'. Mortality rates are given using the 'MortalityTables' package.
Authors@R: c(person("Reinhold", "Kainhofer", role=c("aut", "cre"), email="reinhold@kainhofer.com")) Authors@R: c(person("Reinhold", "Kainhofer", role=c("aut", "cre", "cph"), email="reinhold@kainhofer.com"))
Author: Reinhold Kainhofer [aut, cre] Author: Reinhold Kainhofer [aut, cre, cph]
Maintainer: Reinhold Kainhofer <reinhold@kainhofer.com> Maintainer: Reinhold Kainhofer <reinhold@kainhofer.com>
Encoding: UTF-8 Encoding: UTF-8
Imports: Imports:
...@@ -43,7 +43,6 @@ Collate: ...@@ -43,7 +43,6 @@ Collate:
'ProfitParticipation.R' 'ProfitParticipation.R'
'InsuranceTarif.R' 'InsuranceTarif.R'
'InsuranceContract.R' 'InsuranceContract.R'
'addDataTableWorksheet.R'
'contractGrid.R' 'contractGrid.R'
'create_LIR_project.R' 'create_LIR_project.R'
'exportInsuranceContract_xlsx.R' 'exportInsuranceContract_xlsx.R'
...@@ -57,5 +56,5 @@ Suggests: ...@@ -57,5 +56,5 @@ Suggests:
fs fs
VignetteBuilder: knitr VignetteBuilder: knitr
Roxygen: list(markdown = TRUE) Roxygen: list(markdown = TRUE)
URL: https://gitlab.open-tools.net/R/LifeInsureR URL: https://gitlab.open-tools.net/R/LifeInsureR, https://github.com/kainhofer/LifeInsureR
BugReports: https://gitlab.open-tools.net/R/LifeInsureR/-/issues BugReports: https://gitlab.open-tools.net/R/LifeInsureR/-/issues
# Version 1.0.0: October 27, 2023
* Renamed package from LifeInsuranceContracts to LifeInsureR
...@@ -112,6 +112,7 @@ ProfitComponentsEnum = objectProperties::setMultipleEnum("ProfitComponents", ...@@ -112,6 +112,7 @@ ProfitComponentsEnum = objectProperties::setMultipleEnum("ProfitComponents",
#' #'
#' @param params The parameters of the contract. #' @param params The parameters of the contract.
#' @param values Unused by default (already calculated values of the contract) #' @param values Unused by default (already calculated values of the contract)
#' @returns TRUE or FALSE, indicating a single-premium contract or not
#' #'
#' @export #' @export
isSinglePremiumContract = function(params, values) { params$ContractData$premiumPeriod <= 1 } isSinglePremiumContract = function(params, values) { params$ContractData$premiumPeriod <= 1 }
...@@ -123,6 +124,7 @@ isSinglePremiumContract = function(params, values) { params$ContractData$premium ...@@ -123,6 +124,7 @@ isSinglePremiumContract = function(params, values) { params$ContractData$premium
#' #'
#' @param params The parameters of the contract. #' @param params The parameters of the contract.
#' @param values Unused by default (already calculated values of the contract) #' @param values Unused by default (already calculated values of the contract)
#' @returns TRUE or FALSE, indicating a contract with regular premiums
#' #'
#' @export #' @export
isRegularPremiumContract = function(params, values) { params$ContractData$premiumPeriod > 1 } isRegularPremiumContract = function(params, values) { params$ContractData$premiumPeriod > 1 }
...@@ -141,6 +143,7 @@ isRegularPremiumContract = function(params, values) { params$ContractData$premiu ...@@ -141,6 +143,7 @@ isRegularPremiumContract = function(params, values) { params$ContractData$premiu
#' @param params The full parameter set of the insurance contract (including #' @param params The full parameter set of the insurance contract (including
#' all inherited values from the tariff and the profit participation) #' all inherited values from the tariff and the profit participation)
#' @param values The values calculated from the insurance contract so far #' @param values The values calculated from the insurance contract so far
#' @returns vector of linearly decreasing benefits over the whole insurance coverage period
#' #'
#' @export #' @export
deathBenefit.linearDecreasing = function(len, params, values) { deathBenefit.linearDecreasing = function(len, params, values) {
...@@ -158,6 +161,7 @@ deathBenefit.linearDecreasing = function(len, params, values) { ...@@ -158,6 +161,7 @@ deathBenefit.linearDecreasing = function(len, params, values) {
#' @param params The full parameter set of the insurance contract (including #' @param params The full parameter set of the insurance contract (including
#' all inherited values from the tariff and the profit participation) #' all inherited values from the tariff and the profit participation)
#' @param values The values calculated from the insurance contract so far #' @param values The values calculated from the insurance contract so far
#' @returns The length of the premium refund period (deferral period for deferred contracts, contract period otherwise)
#' #'
#' @export #' @export
premiumRefundPeriod.default = function(params, values) { premiumRefundPeriod.default = function(params, values) {
...@@ -187,6 +191,7 @@ premiumRefundPeriod.default = function(params, values) { ...@@ -187,6 +191,7 @@ premiumRefundPeriod.default = function(params, values) {
#' #'
#' #'
#' @param interest The interest rate of the loan, which is underlying the insurance. #' @param interest The interest rate of the loan, which is underlying the insurance.
#' @returns vector of decreasing death benefits
#' #'
#' #'
#' @export #' @export
...@@ -209,6 +214,7 @@ deathBenefit.annuityDecreasing = function(interest) { ...@@ -209,6 +214,7 @@ deathBenefit.annuityDecreasing = function(interest) {
#' #'
#' @param params The parameters of the contract. #' @param params The parameters of the contract.
#' @param values Unused by default (already calculated values of the contract) #' @param values Unused by default (already calculated values of the contract)
#' @returns the resulting age
#' #'
#' @export #' @export
age.exactRounded = function(params, values) { age.exactRounded = function(params, values) {
...@@ -222,6 +228,7 @@ age.exactRounded = function(params, values) { ...@@ -222,6 +228,7 @@ age.exactRounded = function(params, values) {
#' #'
#' @param params The parameters of the contract. #' @param params The parameters of the contract.
#' @param values Unused by default (already calculated values of the contract) #' @param values Unused by default (already calculated values of the contract)
#' @returns the resulting age
#' #'
#' @export #' @export
age.yearDifference = function(params, values) { age.yearDifference = function(params, values) {
...@@ -255,6 +262,7 @@ age.yearDifference = function(params, values) { ...@@ -255,6 +262,7 @@ age.yearDifference = function(params, values) {
#' @param quarterly Surcharge for quarterly premium payments #' @param quarterly Surcharge for quarterly premium payments
#' @param semiannually Surcharge for semi-annual premium payments #' @param semiannually Surcharge for semi-annual premium payments
#' @param yearly Surcharge for yearly premium payments (optiona, default is no surcharge) #' @param yearly Surcharge for yearly premium payments (optiona, default is no surcharge)
#' @returns a named list of surcharges for names 1 (yearly), 2 (semiannually), 4 (quarterly) and 12 (monthly) payments
#' #'
#' @export #' @export
freqCharge = function(monthly = 0, quarterly = 0, semiannually = 0, yearly = 0) { freqCharge = function(monthly = 0, quarterly = 0, semiannually = 0, yearly = 0) {
...@@ -757,6 +765,7 @@ head0 = function(v, start = 0, value.start = 0) { ...@@ -757,6 +765,7 @@ head0 = function(v, start = 0, value.start = 0) {
#' #'
#' @param v the vector to pad by repeating the last element #' @param v the vector to pad by repeating the last element
#' @param ... arguments passed through to \code{pad0} #' @param ... arguments passed through to \code{pad0}
#' @returns vector padded to the correct length
#' #'
#' @examples #' @examples
#' padLast(1:5, 7) # 5 is repeated twice #' padLast(1:5, 7) # 5 is repeated twice
...@@ -785,6 +794,7 @@ padLast = function(v, ...) { ...@@ -785,6 +794,7 @@ padLast = function(v, ...) {
#' @param x The vector where NA-values should be filled by repeating the last preceeding non-NA value #' @param x The vector where NA-values should be filled by repeating the last preceeding non-NA value
#' @param firstBack if \code{TRUE}, leading NAs are replaced by the first non-NA #' @param firstBack if \code{TRUE}, leading NAs are replaced by the first non-NA
#' value in the vector, otherwise leading NAs are left untouched. #' value in the vector, otherwise leading NAs are left untouched.
#' @returns vector with NAs properly replaced
#' #'
#' @export #' @export
fillNAgaps <- function(x, firstBack=FALSE) { fillNAgaps <- function(x, firstBack=FALSE) {
...@@ -824,6 +834,8 @@ fillNAgaps <- function(x, firstBack=FALSE) { ...@@ -824,6 +834,8 @@ fillNAgaps <- function(x, firstBack=FALSE) {
#' If \code{val} is a function, evaluate it, otherwise return \code{val} #' If \code{val} is a function, evaluate it, otherwise return \code{val}
#' @param val Function or value #' @param val Function or value
#' @param ... Argument passed to \code{val} if it is a function #' @param ... Argument passed to \code{val} if it is a function
#' @returns the value, potentially with the given function applied
#'
#' @examples #' @examples
#' valueOrFunction(3) # returns 3 #' valueOrFunction(3) # returns 3
#' valueOrFunction(`+`, 1, 2) # also returns 3 #' valueOrFunction(`+`, 1, 2) # also returns 3
...@@ -842,6 +854,8 @@ valueOrFunction = function(val, ...) { ...@@ -842,6 +854,8 @@ valueOrFunction = function(val, ...) {
#' @param hook (optional) function to apply to \code{val} and the other parameters #' @param hook (optional) function to apply to \code{val} and the other parameters
#' @param val The value to which the hook is applied (ifgiven) #' @param val The value to which the hook is applied (ifgiven)
#' @param ... optional parameters passed to the hook function (if it is a function) #' @param ... optional parameters passed to the hook function (if it is a function)
#' @returns the value with the hook function applied (if a function) or unchanged otherwiese
#'
#' @examples #' @examples
#' applyHook(NULL, 3) # returns 3 unchanged #' applyHook(NULL, 3) # returns 3 unchanged
#' applyHook(function(x) 2*x, 3) # applies the function, returns 6 #' applyHook(function(x) 2*x, 3) # applies the function, returns 6
...@@ -854,6 +868,7 @@ applyHook = function(hook, val, ...) { ...@@ -854,6 +868,7 @@ applyHook = function(hook, val, ...) {
val val
} else { } else {
warning("Hook function", hook, "is neither a function nor NULL. Please provide a function or leave it empty!") warning("Hook function", hook, "is neither a function nor NULL. Please provide a function or leave it empty!")
val
} }
} }
...@@ -868,6 +883,7 @@ applyHook = function(hook, val, ...) { ...@@ -868,6 +883,7 @@ applyHook = function(hook, val, ...) {
#' #'
#' @param fields existing list #' @param fields existing list
#' @param valuelist list of fields to replace in \code{fields}. Only keys that exist in \code{fields} are overwritten, no new fields are added to \code{fields} #' @param valuelist list of fields to replace in \code{fields}. Only keys that exist in \code{fields} are overwritten, no new fields are added to \code{fields}
#' @returns updated fields list
#' #'
#' @export #' @export
fillFields = function(fields, valuelist) { fillFields = function(fields, valuelist) {
...@@ -884,6 +900,7 @@ fillFields = function(fields, valuelist) { ...@@ -884,6 +900,7 @@ fillFields = function(fields, valuelist) {
#' in fields are inserted #' in fields are inserted
#' @param fields existing list #' @param fields existing list
#' @param valuelist list of fields to replace in \code{fields}. Only keys that are missing in \code{fields} are added, no existing fields in \code{fields} are overwritten #' @param valuelist list of fields to replace in \code{fields}. Only keys that are missing in \code{fields} are added, no existing fields in \code{fields} are overwritten
#' @return fields with missing values filled from the fallback data
#' @export #' @export
fallbackFields = function(fields, valuelist) { fallbackFields = function(fields, valuelist) {
keepFields = !sapply(fields, is.null); keepFields = !sapply(fields, is.null);
......
...@@ -456,8 +456,8 @@ InsuranceContract = R6Class( ...@@ -456,8 +456,8 @@ InsuranceContract = R6Class(
#' @param id The identifier of the contract block describing the dynamic #' @param id The identifier of the contract block describing the dynamic
#' increase. This is a free-form string that should be unique #' increase. This is a free-form string that should be unique
#' within the list of child blocks. It will be displayed in the #' within the list of child blocks. It will be displayed in the
#' Excel export feature and in the history snapshot list. #' 'Excel' export feature and in the history snapshot list.
#' @param ... Paramters to override in the dynamic block. By default, #' @param ... Parameters to override in the dynamic block. By default,
#' all parameters of the main contract block will be used, but #' all parameters of the main contract block will be used, but
#' they can be overridden per dynamic increase block. #' they can be overridden per dynamic increase block.
#' #'
...@@ -951,7 +951,7 @@ InsuranceContract = R6Class( ...@@ -951,7 +951,7 @@ InsuranceContract = R6Class(
#' profit scenarios. #' profit scenarios.
#' #'
#' @param id The unique ID of the profit scenario. Will be used as key #' @param id The unique ID of the profit scenario. Will be used as key
#' in the list of profit scenarios and printed out in the Excel #' in the list of profit scenarios and printed out in the 'Excel'
#' export. #' export.
#' @param ... Scenario-specific profit sharing parameters, overriding #' @param ... Scenario-specific profit sharing parameters, overriding
#' the default values. Typically, adjusted profit rates are required #' the default values. Typically, adjusted profit rates are required
......
...@@ -70,6 +70,8 @@ setCost = function(costs, type, basis = "SumInsured", frequency = "PolicyPeriod" ...@@ -70,6 +70,8 @@ setCost = function(costs, type, basis = "SumInsured", frequency = "PolicyPeriod"
#' even if the insured has already dies (for term-fix insurances) #' even if the insured has already dies (for term-fix insurances)
#' @param unitcosts Unit costs (absolute monetary amount, during premium period) #' @param unitcosts Unit costs (absolute monetary amount, during premium period)
#' @param unitcosts.PolicyPeriod Unit costs (absolute monetary amount, during full contract period) #' @param unitcosts.PolicyPeriod Unit costs (absolute monetary amount, during full contract period)
#'
#' @returns an insurance cost structure (multi-dimensional matrix)
#' #'
#' @examples #' @examples
#' # empty cost structure (only 0 costs) #' # empty cost structure (only 0 costs)
......
#' Add a new worksheet to the excel workbook and export the given data table x to it nicely formatted.
# @export
# addDataTableWorksheet = function(wb, sheet, title = NULL, x = NULL, loopdim = 3, style = NULL, tableStyle = "TableStyleMedium17", comparisons = NULL, comparisonStyle = NULL, ...) {
# addWorksheet(wb, sheet);
# rw = 1;
# if (!missing(title)) {
# titleStyle = createStyle(
# fontSize = 26,
# fontColour = "#365F91", borderColour = "#4F81BD",
# borderStyle = "medium", border = "Bottom", textDecoration = "bold")
# writeData(wb, sheet, title, startCol = 1, startRow = rw)
# addStyle(wb, sheet, style = titleStyle, rows = rw, cols = 1);
# rw = rw + 2;
# }
# if (!missing(x)) {
# if (loopdim > length(dim(x)))
# loopdim = length(dim(x));
# if (loopdim < 0)
# loopdim = 1;
# # str(dimnames(x));
# rnames = dimnames(x)[[1]];
# cnames = dimnames(x)[[2]];
# # str("rnames, cnames: ");str(rnames);str(cnames);
# dmname = names(dimnames(x))[[loopdim]];
# dmnameStyle = createStyle(
# fontSize = 20,
# fontColour = "#4F81BD", #borderColour = "#4F81BD",
# # borderStyle = "medium", border = "Bottom",
# textDecoration = "bold")
# headerStyle = createStyle(halign = "center", valign = "center");
# lapply(
# seq_along(dimnames(x)[[loopdim]]),
# function(i) {
# dmheader = paste(dmname, dimnames(x)[[loopdim]][i], sep = " = ")
# writeData(wb, sheet, dmheader, startCol = 1, startRow = rw)
# addStyle(wb, sheet, style = dmnameStyle, rows = rw, cols = 1);
# rw <<- rw + 1;
# writeDataTable(
# wb, sheet,
# x = as.data.frame(x[,,i]), # TODO: Generalize this to use loopdim!
# colNames = TRUE, rowNames = TRUE,
# withFilter = FALSE,
# startCol = 1, startRow = rw,
# tableStyle = tableStyle, headerStyle = headerStyle);
# if (!is.null(style)) {
# addStyle(wb, sheet, style = style, rows = rw + seq_along(rnames), cols = 1 + seq_along(cnames), gridExpand = TRUE, stack = TRUE);
# }
# cl = 1 + length(cnames) + 2;
#
# lapply(
# seq_along(comparisons),
# function(j) {
# writeData(wb, sheet, names(comparisons)[j], startRow = rw - 1, startCol = cl)
# addStyle(wb, sheet, style = dmnameStyle, rows = rw - 1, cols = cl);
#
# writeDataTable(
# wb, sheet,
# x = as.data.frame(comparisons[[j]][,,i]), # TODO: Generalize this to use loopdim!
# colNames = TRUE, rowNames = TRUE,
# withFilter = FALSE,
# startCol = cl, startRow = rw,
# tableStyle = tableStyle, headerStyle = headerStyle);
# if (!is.null(comparisonStyle)) {
# addStyle(wb, sheet, style = comparisonStyle, rows = rw + seq_along(rnames), cols = cl + seq_along(cnames), gridExpand = TRUE, stack = TRUE);
# }
# cl <<- cl + 1 + length(cnames) + 1;
# }
# )
# rw <<- rw + length(rnames) + 1 + 2; # TODO: Generalize this to use loopdim!
# }
# );
# }
# }
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
# #
# Params of the contractGridPreimium function: # Params of the contractGridPreimium function:
#' @param contractGrid (optional) existing contract grid from which to derive #' @param contractGrid (optional) existing contract grid from which to derive
#' premiums. If not given, [contractGrid] is called with all parameters, so #' premiums. If not given, [contractGrid()] is called with all parameters, so
#' \code{...} should contain an \code{axes} argument in that case. #' \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 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 #' @param .fun The function to extract the desired premium from a contract
...@@ -48,11 +48,29 @@ ...@@ -48,11 +48,29 @@
#' type of premium given in the \code{premium} parameter. One can, #' type of premium given in the \code{premium} parameter. One can,
#' however pass any other extractor function to access e.g. reserves, #' however pass any other extractor function to access e.g. reserves,
#' cash flows etc. at any desired time. #' cash flows etc. at any desired time.
#' @returns multi-dimensional array of insurance contracts (dimensions defined by the axes argument)
#' #'
#' @rdname contractGrid #' @rdname contractGrid
#' #'
#' @examples #' @examples
#' # TODO #' 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 }
#' )
#' contractGrid(
#' axes = list(
#' age = seq(20, 60, 10),
#' premiumPeriod = seq(5,30, 5)
#' ),
#' tarif = tariff,
#' sumInsured = 1000,
#' contractClosing = as.Date("2023-11-01")
#' )
#' #'
#' @export #' @export
contractGrid = function(axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, 35, 5)), YOB = NULL, observationYear = NULL, ...) { contractGrid = function(axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, 35, 5)), YOB = NULL, observationYear = NULL, ...) {
...@@ -100,6 +118,7 @@ makeContractGridDimname.default = function(value) { value } ...@@ -100,6 +118,7 @@ makeContractGridDimname.default = function(value) { value }
#' representation for the axes in the grid. #' representation for the axes in the grid.
#' #'
#' @param value the value along the axis, for which a name should be generated #' @param value the value along the axis, for which a name should be generated
#' @returns The name of the entry in the dimnames of [contractGrid()]
#' @describeIn makeContractGridDimname Create a short, human-readable dimensional name for an object (default S3 method) #' @describeIn makeContractGridDimname Create a short, human-readable dimensional name for an object (default S3 method)
#' @examples #' @examples
#' library(MortalityTables) #' library(MortalityTables)
...@@ -119,6 +138,7 @@ makeContractGridDimname = function(value) { UseMethod("makeContractGridDimname", ...@@ -119,6 +138,7 @@ makeContractGridDimname = function(value) { UseMethod("makeContractGridDimname",
#' dimnames for all entries of the axes of a [contractGrid()] by calling #' dimnames for all entries of the axes of a [contractGrid()] by calling
#' \code{makeContractGridDimname} on each of the axes' values #' \code{makeContractGridDimname} on each of the axes' values
#' @param axes the axes with all names, for which a name should be generated #' @param axes the axes with all names, for which a name should be generated
#' @returns an array of dimnames derived from the axes definitions of [contractGrid()]
#' @describeIn makeContractGridDimname Generate proper dimnames for all entries of the axes of a [contractGrid()] #' @describeIn makeContractGridDimname Generate proper dimnames for all entries of the axes of a [contractGrid()]
#' @export #' @export
makeContractGridDimnames = function(axes) { makeContractGridDimnames = function(axes) {
...@@ -148,8 +168,31 @@ makeContractGridDimnames = function(axes) { ...@@ -148,8 +168,31 @@ makeContractGridDimnames = function(axes) {
#' type of premium given in the \code{premium} parameter. One can, #' type of premium given in the \code{premium} parameter. One can,
#' however pass any other extractor function to access e.g. reserves, #' however pass any other extractor function to access e.g. reserves,
#' cash flows etc. at any desired time. #' cash flows etc. at any desired time.
#' @returns a array of premiums (or other contract-specific value) for the grid defined by the \code{axes} argument to \code{contractGrid}
#' #'
#' @rdname contractGrid #' @rdname contractGrid
#'
#' @example
#' 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")
#' )
#'
#'
#' @export #' @export
contractGridPremium = function(contractGrid = NULL, premium="written", .fun = function(cntr) { cntr$Values$premiums[[premium]] }, ...) { contractGridPremium = function(contractGrid = NULL, premium="written", .fun = function(cntr) { cntr$Values$premiums[[premium]] }, ...) {
if (missing(contractGrid) || is.null(contractGrid)) { if (missing(contractGrid) || is.null(contractGrid)) {
......
...@@ -5,7 +5,7 @@ NULL ...@@ -5,7 +5,7 @@ NULL
#' Export the example calculations of an insurance contract #' Export the example calculations of an insurance contract
#' #'
#' Export the given contract to excel (full history/timeseries of all cash #' Export the given contract to 'Excel' (full history/timeseries of all cash
#' flows, reserves, premiums, etc.) and to a text file (sample calculation #' flows, reserves, premiums, etc.) and to a text file (sample calculation
#' required by the Austrian regulation). #' required by the Austrian regulation).
#' #'
...@@ -28,6 +28,7 @@ NULL ...@@ -28,6 +28,7 @@ NULL
#' @param extraname If basename is not given, this allows a suffix to distinguish #' @param extraname If basename is not given, this allows a suffix to distinguish
#' multiple exports. #' multiple exports.
#' @param ... Further parameters (passed on to \code{\link{showVmGlgExamples}}) #' @param ... Further parameters (passed on to \code{\link{showVmGlgExamples}})
#' @returns None
#' #'
#' @examples #' @examples
#' library("MortalityTables") #' library("MortalityTables")
...@@ -42,7 +43,7 @@ NULL ...@@ -42,7 +43,7 @@ NULL
#' sumInsured = 1000, #' sumInsured = 1000,
#' contractClosing = as.Date("2016-10-01") #' contractClosing = as.Date("2016-10-01")
#' ); #' );
#' \dontrun{exportInsuranceContractExample(contract, prf = 10)} #' \donttest{exportInsuranceContractExample(contract, prf = 10, outdir = tempdir())}
#' #'
#' @export #' @export
exportInsuranceContractExample = function(contract, prf = 10, outdir = ".", basename=NULL, extraname = NULL, ...) { exportInsuranceContractExample = function(contract, prf = 10, outdir = ".", basename=NULL, extraname = NULL, ...) {
......
...@@ -846,10 +846,10 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -846,10 +846,10 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
# #
############################################################################### # ############################################################################### #
#' Export an insurance act object tocontract (object of class [InsuranceContract]) to an Excel file #' Export an insurance contract (object of class [InsuranceContract]) to an 'Excel' file
#' #'
#' @details The function \code{exportInsuranceContract.xlsx} exports an object #' @details The function \code{exportInsuranceContract.xlsx} exports an object
#' of class [InsuranceContract] to an Excel file. All basic data, as well as #' of class [InsuranceContract] to an 'Excel' file. All basic data, as well as
#' the time series of (absolute and unit) cash flows, reserves, premiums, premium #' the time series of (absolute and unit) cash flows, reserves, premiums, premium
#' composition and all profit participation scenarios are exported to the file #' composition and all profit participation scenarios are exported to the file
#' in nicely looking tables. #' in nicely looking tables.
...@@ -858,7 +858,8 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -858,7 +858,8 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
#' stored in \code{contract$Values}. #' stored in \code{contract$Values}.
#' #'
#' @param contract The insurance contract to export #' @param contract The insurance contract to export
#' @param filename Target Excel filename for export #' @param filename Target 'Excel' file name for export
#' @returns None
#' #'
#' @examples #' @examples
#' library("MortalityTables") #' library("MortalityTables")
...@@ -873,7 +874,7 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), ...@@ -873,7 +874,7 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(),
#' sumInsured = 1000, #' sumInsured = 1000,
#' contractClosing = as.Date("2016-10-01") #' contractClosing = as.Date("2016-10-01")
#' ); #' );
#' \dontrun{exportInsuranceContract.xlsx(contract, "Example_annuity_contract.xlsx")} #' \donttest{exportInsuranceContract.xlsx(contract, tempfile("Example_annuity_contract", fileext = ".xlsx"))}
#' @export #' @export
exportInsuranceContract.xlsx = function(contract, filename) { exportInsuranceContract.xlsx = function(contract, filename) {
# TODO: argument checking for contract and filename # TODO: argument checking for contract and filename
......
...@@ -82,6 +82,7 @@ calcVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, ...) { ...@@ -82,6 +82,7 @@ calcVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, ...) {
#' @param t_prf Time for which to show all values after the premium waiver #' @param t_prf Time for which to show all values after the premium waiver
#' @param file If given, outputs all information to the file rather than the console #' @param file If given, outputs all information to the file rather than the console
#' @param ... Further parameters for generating the contract for a tariff object #' @param ... Further parameters for generating the contract for a tariff object
#' @returns Name of the output file (invisible) or empty if printed to console
#' #'
#' @examples #' @examples
#' library(MortalityTables) #' library(MortalityTables)
...@@ -99,8 +100,8 @@ calcVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, ...) { ...@@ -99,8 +100,8 @@ calcVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, ...) {
#' showVmGlgExamples(contract) #' showVmGlgExamples(contract)
#' #'
#' # Optionally output to a file rather than the console: #' # Optionally output to a file rather than the console:
#' \dontrun{ #' \donttest{
#' showVmGlgExamples(contract, file = "annuity-example.txt") #' showVmGlgExamples(contract, file = tempfile("annuity-example", fileext = ".txt"))
#' } #' }
#' @export #' @export
showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "", ...) { showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "", ...) {
...@@ -169,6 +170,7 @@ showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "", ...@@ -169,6 +170,7 @@ showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "",
); );
output.str = paste(output, collapse = '\r\n') output.str = paste(output, collapse = '\r\n')
cat(output.str, file = file) cat(output.str, file = file)
invisible(file)
} }
...@@ -189,16 +191,19 @@ showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "", ...@@ -189,16 +191,19 @@ showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "",
#' @param net,Zillmer,gross,written,savings,risk,ZillmerRes,ZillmerRes.prf,VwKostenRes,VwKostenRes.prf,Bilanzreserve,Praemienuebertrag,Rueckkaufsreserve,Rueckkaufswert,Abschlusskostenruecktrag,Rueckkaufswert.prf,VS.prf Values as printed out by showVmGlgExamples #' @param net,Zillmer,gross,written,savings,risk,ZillmerRes,ZillmerRes.prf,VwKostenRes,VwKostenRes.prf,Bilanzreserve,Praemienuebertrag,Rueckkaufsreserve,Rueckkaufswert,Abschlusskostenruecktrag,Rueckkaufswert.prf,VS.prf Values as printed out by showVmGlgExamples
#' @param absTolerance If non-NULL, will ignore small floating point differences. It uses same algorithm as all.equal() #' @param absTolerance If non-NULL, will ignore small floating point differences. It uses same algorithm as all.equal()
#' @param ... Further parameters for generating the contract for a tariff object #' @param ... Further parameters for generating the contract for a tariff object
#' @returns None
#' #'
#' @examples #' @examples
#' library(MortalityTables) #' library(MortalityTables)
#' library(testthat)
#' mortalityTables.load("Austria_Annuities_AVOe2005R") #' mortalityTables.load("Austria_Annuities_AVOe2005R")
#' #'
#' \dontrun{
#' test_that("Testtarif", { #' test_that("Testtarif", {
#' # A trivial deferred annuity tariff with no costs: #' # A trivial deferred annuity tariff with no costs:
#' library(MortalityTables)
#' mortalityTables.load("Austria_Annuities")
#' tariff = InsuranceTarif$new(name="Test Annuity", type="annuity", #' tariff = InsuranceTarif$new(name="Test Annuity", type="annuity",
#' mortalityTable = AVOe2005R.unisex, i=0.01) #' mortalityTable = AVOe2005R.unisex, i = 0.01)
#' contract = InsuranceContract$new( #' contract = InsuranceContract$new(
#' tariff, #' tariff,
#' age = 35, YOB = 1981, #' age = 35, YOB = 1981,
...@@ -218,15 +223,14 @@ showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "", ...@@ -218,15 +223,14 @@ showVmGlgExamples = function(contract, prf = 10, t = 10, t_prf = 12, file = "",
#' VwKostenRes = 0.00, #' VwKostenRes = 0.00,
#' VwKostenRes.prf = 0.00, #' VwKostenRes.prf = 0.00,
#' Bilanzreserve = 9250.35, #' Bilanzreserve = 9250.35,
#' Praemienuebertrag = 212.52, #' Praemienuebertrag = 637.567,
#' Rueckkaufsreserve = 9011.40, #' Rueckkaufsreserve = 9011.40,
#' Rueckkaufswert = 9011.40, #' Rueckkaufswert = 9011.40,
#' Abschlusskostenruecktrag = 0.00, #' Abschlusskostenruecktrag = 0.00,
#' Rueckkaufswert.prf = 9205.96, #' Rueckkaufswert.prf = 9205.96,
#' VS.prf = 685.12 #' VS.prf = 684.117
#' ) #' )
#' }) #' })
#'}
#' #'
#' @export #' @export
testVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, net, Zillmer, gross, written, savings, risk, testVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, net, Zillmer, gross, written, savings, risk,
...@@ -318,6 +322,7 @@ testVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, net, Zillmer ...@@ -318,6 +322,7 @@ testVmGlgExample = function(contract, prf = 10, t = 10, t_prf = 12, net, Zillmer
#' @param prf Time of premium waiver (premium-free) #' @param prf Time of premium waiver (premium-free)
#' @param t_prf Time for which to calculated all values after the premium waiver #' @param t_prf Time for which to calculated all values after the premium waiver
#' @param ... Further parameters for generating the contract for a tariff object #' @param ... Further parameters for generating the contract for a tariff object
#' @returns None (code is printed to the console, but no value returned)
#' #'
#' @examples #' @examples
#' library(MortalityTables) #' library(MortalityTables)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
R package implementing general life insurance contracts R package implementing general life insurance contracts
This package R6 classes to model traditional life insurance This package R6 classes to model traditional life insurance
contracts like annuities, whole life insurances or endowments. All relevant contracts like annuities, whole life insurances or endowments. All relevant
quantities like premium decomposition, reserves and benefits over the whole quantities like premium decomposition, reserves and benefits over the whole
contract period are calculated and potentially exported to excel. Mortalities contract period are calculated and potentially exported to 'Excel'. Mortalities
are given using the MortalityTables package. are given using the 'MortalityTables' package.
## R CMD check results
❯ checking CRAN incoming feasibility ... NOTE
Maintainer: 'Reinhold Kainhofer <reinhold@kainhofer.com>'
New submission
0 errors ✔ | 0 warnings ✔ | 1 note ✖
* Renamed the existing LifeInsuranceContracts package to LifeInsureR
So this is not a complately new package, just a new name!
* Re-submission of the package taking into account the response of the CRAN team:
* Wrap Software and package names in quotes
* There are no external references describing the methods
* Removed Umlaute (UTF8 characters) to prevent unexecutable code on pure ANSI/ASCII machines
* replace \dontrun by \donttest wherever possible.
* Never change the options(..)
...@@ -78,10 +78,8 @@ contract.Bsp = InsuranceContract$ ...@@ -78,10 +78,8 @@ contract.Bsp = InsuranceContract$
addDynamics(t = 5, NewSumInsured = 200000, id = "Dynamik 1", i = 0.05, age = 70)$ addDynamics(t = 5, NewSumInsured = 200000, id = "Dynamik 1", i = 0.05, age = 70)$
addDynamics(t = 10, NewSumInsured = 250000, id = "Dynamik 2", i = 0.01); addDynamics(t = 10, NewSumInsured = 250000, id = "Dynamik 2", i = 0.01);
options('LIC.debug.premiumCalculation' = TRUE)
contract.Bsp$premiumWaiver(t = 13) contract.Bsp$premiumWaiver(t = 13)
options('LIC.debug.premiumCalculation' = FALSE)
# exportInsuranceContractExample(contract.Bsp, t = 5); # exportInsuranceContractExample(contract.Bsp, t = 5);
# showVmGlgExamples(contract.Bsp, t = 10) # showVmGlgExamples(contract.Bsp, t = 10)
# #
......
...@@ -560,9 +560,9 @@ given, the \code{SumInsuredDelta} will take precedence.} ...@@ -560,9 +560,9 @@ given, the \code{SumInsuredDelta} will take precedence.}
\item{\code{id}}{The identifier of the contract block describing the dynamic \item{\code{id}}{The identifier of the contract block describing the dynamic
increase. This is a free-form string that should be unique increase. This is a free-form string that should be unique
within the list of child blocks. It will be displayed in the within the list of child blocks. It will be displayed in the
Excel export feature and in the history snapshot list.} 'Excel' export feature and in the history snapshot list.}
\item{\code{...}}{Paramters to override in the dynamic block. By default, \item{\code{...}}{Parameters to override in the dynamic block. By default,
all parameters of the main contract block will be used, but all parameters of the main contract block will be used, but
they can be overridden per dynamic increase block.} they can be overridden per dynamic increase block.}
} }
...@@ -770,7 +770,7 @@ Calculate one profit scenario and store it in the contract ...@@ -770,7 +770,7 @@ Calculate one profit scenario and store it in the contract
\if{html}{\out{<div class="arguments">}} \if{html}{\out{<div class="arguments">}}
\describe{ \describe{
\item{\code{id}}{The unique ID of the profit scenario. Will be used as key \item{\code{id}}{The unique ID of the profit scenario. Will be used as key
in the list of profit scenarios and printed out in the Excel in the list of profit scenarios and printed out in the 'Excel'
export.} export.}
\item{\code{...}}{Scenario-specific profit sharing parameters, overriding \item{\code{...}}{Scenario-specific profit sharing parameters, overriding
......
...@@ -12,6 +12,9 @@ age.exactRounded(params, values) ...@@ -12,6 +12,9 @@ age.exactRounded(params, values)
\item{values}{Unused by default (already calculated values of the contract)} \item{values}{Unused by default (already calculated values of the contract)}
} }
\value{
the resulting age
}
\description{ \description{
Calculate the age of the insured based on exact age at contract closing, rounded Calculate the age of the insured based on exact age at contract closing, rounded
to the nearest birthday. to the nearest birthday.
......
...@@ -12,6 +12,9 @@ age.yearDifference(params, values) ...@@ -12,6 +12,9 @@ age.yearDifference(params, values)
\item{values}{Unused by default (already calculated values of the contract)} \item{values}{Unused by default (already calculated values of the contract)}
} }
\value{
the resulting age
}
\description{ \description{
Calculate the age of the insured based on the difference of the bith year and Calculate the age of the insured based on the difference of the bith year and
contract closing year. contract closing year.
......
...@@ -13,6 +13,9 @@ applyHook(hook, val, ...) ...@@ -13,6 +13,9 @@ applyHook(hook, val, ...)
\item{...}{optional parameters passed to the hook function (if it is a function)} \item{...}{optional parameters passed to the hook function (if it is a function)}
} }
\value{
the value with the hook function applied (if a function) or unchanged otherwiese
}
\description{ \description{
If \code{hook} is a function, apply it to \code{val}, otherwise return \code{val} unchanged If \code{hook} is a function, apply it to \code{val}, otherwise return \code{val} unchanged
} }
......
...@@ -42,6 +42,11 @@ type of premium given in the \code{premium} parameter. One can, ...@@ -42,6 +42,11 @@ type of premium given in the \code{premium} parameter. One can,
however pass any other extractor function to access e.g. reserves, however pass any other extractor function to access e.g. reserves,
cash flows etc. at any desired time.} cash flows etc. at any desired time.}
} }
\value{
multi-dimensional array of insurance contracts (dimensions defined by the axes argument)
a array of premiums (or other contract-specific value) for the grid defined by the \code{axes} argument to \code{contractGrid}
}
\description{ \description{
The function \code{contractGrid} creates a (two- or multi-dimensional) grid The function \code{contractGrid} creates a (two- or multi-dimensional) grid
of InsuranceContract objects, where each axis represents one of the insurance of InsuranceContract objects, where each axis represents one of the insurance
...@@ -75,6 +80,23 @@ human-readable representations e.g. of a tariff or a mortality table as ...@@ -75,6 +80,23 @@ human-readable representations e.g. of a tariff or a mortality table as
the dimension label. the dimension label.
} }
\examples{ \examples{
# TODO 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 }
)
contractGrid(
axes = list(
age = seq(20, 60, 10),
premiumPeriod = seq(5,30, 5)
),
tarif = tariff,
sumInsured = 1000,
contractClosing = as.Date("2023-11-01")
)
} }
...@@ -9,6 +9,9 @@ deathBenefit.annuityDecreasing(interest) ...@@ -9,6 +9,9 @@ deathBenefit.annuityDecreasing(interest)
\arguments{ \arguments{
\item{interest}{The interest rate of the loan, which is underlying the insurance.} \item{interest}{The interest rate of the loan, which is underlying the insurance.}
} }
\value{
vector of decreasing death benefits
}
\description{ \description{
The death benefit will be the full sumInsured for the first year after the The death benefit will be the full sumInsured for the first year after the
deferral period and then decrease like an annuity to 0 at the end of the policyPeriod. deferral period and then decrease like an annuity to 0 at the end of the policyPeriod.
......