diff --git a/DESCRIPTION b/DESCRIPTION index 917d935be700798a6e7dd2e61d81736c8e948bf4..c8d65dfcccf534c777b1340eea66eb6731d174c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: LifeInsureR Type: Package -Version: 1.0.0 -Date: 2023-10-20 -Title: Framework for Traditional Life Insurance Contracts +Version: 0.0.0.9999 +Date: 2023-10-27 +Title: Modelling Traditional Life Insurance Contracts Description: R6 classes to model traditional life insurance contracts like annuities, whole life insurances or endowments. Such life insurance contracts provide a guaranteed interest and are not directly linked @@ -14,8 +14,8 @@ Description: R6 classes to model traditional life insurance waivers). All relevant quantities like premium decomposition, reserves and benefits over the whole contract period are calculated and potentially 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")) -Author: Reinhold Kainhofer [aut, cre] +Authors@R: c(person("Reinhold", "Kainhofer", role=c("aut", "cre", "cph"), email="reinhold@kainhofer.com")) +Author: Reinhold Kainhofer [aut, cre, cph] Maintainer: Reinhold Kainhofer <reinhold@kainhofer.com> Encoding: UTF-8 Imports: @@ -43,7 +43,6 @@ Collate: 'ProfitParticipation.R' 'InsuranceTarif.R' 'InsuranceContract.R' - 'addDataTableWorksheet.R' 'contractGrid.R' 'create_LIR_project.R' 'exportInsuranceContract_xlsx.R' diff --git a/R/HelperFunctions.R b/R/HelperFunctions.R index d955c81b3aaae1e18378c95dc726df4dc3e812d3..bd0764c4dd077a314b64f146847a1893a01835ea 100644 --- a/R/HelperFunctions.R +++ b/R/HelperFunctions.R @@ -765,6 +765,7 @@ head0 = function(v, start = 0, value.start = 0) { #' #' @param v the vector to pad by repeating the last element #' @param ... arguments passed through to \code{pad0} +#' @returns vector padded to the correct length #' #' @examples #' padLast(1:5, 7) # 5 is repeated twice @@ -793,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 firstBack if \code{TRUE}, leading NAs are replaced by the first non-NA #' value in the vector, otherwise leading NAs are left untouched. +#' @returns vector with NAs properly replaced #' #' @export fillNAgaps <- function(x, firstBack=FALSE) { @@ -832,6 +834,8 @@ fillNAgaps <- function(x, firstBack=FALSE) { #' If \code{val} is a function, evaluate it, otherwise return \code{val} #' @param val Function or value #' @param ... Argument passed to \code{val} if it is a function +#' @returns the value, potentially with the given function applied +#' #' @examples #' valueOrFunction(3) # returns 3 #' valueOrFunction(`+`, 1, 2) # also returns 3 @@ -850,6 +854,8 @@ valueOrFunction = function(val, ...) { #' @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 ... 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 #' applyHook(NULL, 3) # returns 3 unchanged #' applyHook(function(x) 2*x, 3) # applies the function, returns 6 @@ -862,6 +868,7 @@ applyHook = function(hook, val, ...) { val } else { warning("Hook function", hook, "is neither a function nor NULL. Please provide a function or leave it empty!") + val } } @@ -876,6 +883,7 @@ applyHook = function(hook, val, ...) { #' #' @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} +#' @returns updated fields list #' #' @export fillFields = function(fields, valuelist) { @@ -892,6 +900,7 @@ fillFields = function(fields, valuelist) { #' in fields are inserted #' @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 +#' @return fields with missing values filled from the fallback data #' @export fallbackFields = function(fields, valuelist) { keepFields = !sapply(fields, is.null); diff --git a/R/InsuranceContract.R b/R/InsuranceContract.R index 65680abc9b86bb45c821a72d9c7cd58372c0b3c8..d2225c39b180044c4258f6e154bcc3648be02d3d 100644 --- a/R/InsuranceContract.R +++ b/R/InsuranceContract.R @@ -456,8 +456,8 @@ InsuranceContract = R6Class( #' @param id The identifier of the contract block describing the dynamic #' increase. This is a free-form string that should be unique #' within the list of child blocks. It will be displayed in the - #' Excel export feature and in the history snapshot list. - #' @param ... Paramters to override in the dynamic block. By default, + #' 'Excel' export feature and in the history snapshot list. + #' @param ... Parameters to override in the dynamic block. By default, #' all parameters of the main contract block will be used, but #' they can be overridden per dynamic increase block. #' @@ -951,7 +951,7 @@ InsuranceContract = R6Class( #' profit scenarios. #' #' @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. #' @param ... Scenario-specific profit sharing parameters, overriding #' the default values. Typically, adjusted profit rates are required diff --git a/R/InsuranceParameters.R b/R/InsuranceParameters.R index 31d188e962ad53514f7af9f994834000e0595d49..fd6e178de152314cfc5478c5a2f6bddb674c3b03 100644 --- a/R/InsuranceParameters.R +++ b/R/InsuranceParameters.R @@ -70,6 +70,8 @@ setCost = function(costs, type, basis = "SumInsured", frequency = "PolicyPeriod" #' even if the insured has already dies (for term-fix insurances) #' @param unitcosts Unit costs (absolute monetary amount, during premium period) #' @param unitcosts.PolicyPeriod Unit costs (absolute monetary amount, during full contract period) +#' +#' @returns an insurance cost structure (multi-dimensional matrix) #' #' @examples #' # empty cost structure (only 0 costs) diff --git a/R/exportInsuranceContractExample.R b/R/exportInsuranceContractExample.R index f67f04f8823a282422ee5b221df82d2cf7b674a7..e1f31a1dc7a7a8a295097a8ccc5e39c538f81abe 100644 --- a/R/exportInsuranceContractExample.R +++ b/R/exportInsuranceContractExample.R @@ -43,7 +43,7 @@ NULL #' sumInsured = 1000, #' contractClosing = as.Date("2016-10-01") #' ); -#' \donttest{exportInsuranceContractExample(contract, prf = 10)} +#' \donttest{exportInsuranceContractExample(contract, prf = 10, outdir = tempdir())} #' #' @export exportInsuranceContractExample = function(contract, prf = 10, outdir = ".", basename=NULL, extraname = NULL, ...) { diff --git a/R/exportInsuranceContract_xlsx.R b/R/exportInsuranceContract_xlsx.R index 6c8ed15efc9f1fa93ceafa5ded298d38c095e2a6..288c82efcc731240eceecb017c4fab8cb55f35b8 100644 --- a/R/exportInsuranceContract_xlsx.R +++ b/R/exportInsuranceContract_xlsx.R @@ -874,7 +874,7 @@ exportCFTable = function(wb, sheet, contract, ccol = 1, crow = 1, styles = c(), #' sumInsured = 1000, #' contractClosing = as.Date("2016-10-01") #' ); -#' \donttest{exportInsuranceContract.xlsx(contract, "Example_annuity_contract.xlsx")} +#' \donttest{exportInsuranceContract.xlsx(contract, tempfile("Example_annuity_contract", fileext = ".xlsx"))} #' @export exportInsuranceContract.xlsx = function(contract, filename) { # TODO: argument checking for contract and filename diff --git a/man/InsuranceContract.Rd b/man/InsuranceContract.Rd index 6c44951ab005960ab47abccd6253f0c0a84b7993..33a1fc98eee426382b3c0259e9fea26f7b17a787 100644 --- a/man/InsuranceContract.Rd +++ b/man/InsuranceContract.Rd @@ -560,9 +560,9 @@ given, the \code{SumInsuredDelta} will take precedence.} \item{\code{id}}{The identifier of the contract block describing the dynamic increase. This is a free-form string that should be unique 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 they can be overridden per dynamic increase block.} } @@ -770,7 +770,7 @@ Calculate one profit scenario and store it in the contract \if{html}{\out{<div class="arguments">}} \describe{ \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.} \item{\code{...}}{Scenario-specific profit sharing parameters, overriding diff --git a/man/applyHook.Rd b/man/applyHook.Rd index e1e336d0ee8e0bddb6153f5256402fa622ff14a9..b6bf2df4ef8e656fbd7acb010a374f30172e3e40 100644 --- a/man/applyHook.Rd +++ b/man/applyHook.Rd @@ -13,6 +13,9 @@ applyHook(hook, val, ...) \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{ If \code{hook} is a function, apply it to \code{val}, otherwise return \code{val} unchanged } diff --git a/man/exportInsuranceContract.xlsx.Rd b/man/exportInsuranceContract.xlsx.Rd index bd442647cc3d3023225b9bcd8e1f0e71f6f2ecea..049605ce968b42fdfbf558172a13e5888a5506b0 100644 --- a/man/exportInsuranceContract.xlsx.Rd +++ b/man/exportInsuranceContract.xlsx.Rd @@ -2,24 +2,24 @@ % Please edit documentation in R/exportInsuranceContract_xlsx.R \name{exportInsuranceContract.xlsx} \alias{exportInsuranceContract.xlsx} -\title{Export an insurance act object tocontract (object of class \link{InsuranceContract}) to an Excel file} +\title{Export an insurance contract (object of class \link{InsuranceContract}) to an 'Excel' file} \usage{ exportInsuranceContract.xlsx(contract, filename) } \arguments{ \item{contract}{The insurance contract to export} -\item{filename}{Target Excel filename for export} +\item{filename}{Target 'Excel' file name for export} } \value{ None } \description{ -Export an insurance act object tocontract (object of class \link{InsuranceContract}) to an Excel file +Export an insurance contract (object of class \link{InsuranceContract}) to an 'Excel' file } \details{ The function \code{exportInsuranceContract.xlsx} exports an object -of class \link{InsuranceContract} to an Excel file. All basic data, as well as +of class \link{InsuranceContract} to an 'Excel' file. All basic data, as well as the time series of (absolute and unit) cash flows, reserves, premiums, premium composition and all profit participation scenarios are exported to the file in nicely looking tables. @@ -40,5 +40,5 @@ contract = InsuranceContract$new( sumInsured = 1000, contractClosing = as.Date("2016-10-01") ); -\donttest{exportInsuranceContract.xlsx(contract, "Example_annuity_contract.xlsx")} +\donttest{exportInsuranceContract.xlsx(contract, tempfile("Example_annuity_contract", fileext = ".xlsx"))} } diff --git a/man/exportInsuranceContractExample.Rd b/man/exportInsuranceContractExample.Rd index b434fc521473738441bc03e77a6e2d4e99ff9061..61fab63e291fb53dac0b0e3757aa66909407a443 100644 --- a/man/exportInsuranceContractExample.Rd +++ b/man/exportInsuranceContractExample.Rd @@ -36,7 +36,7 @@ multiple exports.} None } \description{ -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 required by the Austrian regulation). } @@ -63,6 +63,6 @@ contract = InsuranceContract$new( sumInsured = 1000, contractClosing = as.Date("2016-10-01") ); -\donttest{exportInsuranceContractExample(contract, prf = 10)} +\donttest{exportInsuranceContractExample(contract, prf = 10, outdir = tempdir())} } diff --git a/man/fallbackFields.Rd b/man/fallbackFields.Rd index 6cde187fefd0f19ae14e823342f8482836b0c827..22932e1fcdc8102f8b844d7150c906349b080612 100644 --- a/man/fallbackFields.Rd +++ b/man/fallbackFields.Rd @@ -11,6 +11,9 @@ fallbackFields(fields, valuelist) \item{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} } +\value{ +fields with missing values filled from the fallback data +} \description{ Replace all missing values in fields (either missing or NA) with their corresponding values from fallback. Members in fallback that are missing diff --git a/man/fillFields.Rd b/man/fillFields.Rd index 3845bfdbc4bb8967c8b2008d0d4f706c3a79b584..94c6fd2cac0cacbb805c946b96be7c233af4b8e0 100644 --- a/man/fillFields.Rd +++ b/man/fillFields.Rd @@ -11,6 +11,9 @@ fillFields(fields, valuelist) \item{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}} } +\value{ +updated fields list +} \description{ Overwrite all existing fields in the first argument with values given in valuelist. Members of valuelist that are not yet in diff --git a/man/fillNAgaps.Rd b/man/fillNAgaps.Rd index c330f85cc0d4019be8163f8461239a29ae952dfb..de0826a78c34290ac9551ec13411150c8ca8569a 100644 --- a/man/fillNAgaps.Rd +++ b/man/fillNAgaps.Rd @@ -12,6 +12,9 @@ fillNAgaps(x, firstBack = FALSE) \item{firstBack}{if \code{TRUE}, leading NAs are replaced by the first non-NA value in the vector, otherwise leading NAs are left untouched.} } +\value{ +vector with NAs properly replaced +} \description{ Sometimes one has a vector with some gaps (\code{NA}) values, which cause problems for several numeric functions. This function \code{fillNAgaps} fills diff --git a/man/initializeCosts.Rd b/man/initializeCosts.Rd index 4d7772acc7abfe9eeb9337bf4e6811171bcf8344..7af16f692ef135e973313c566c5af72452850a96 100644 --- a/man/initializeCosts.Rd +++ b/man/initializeCosts.Rd @@ -54,6 +54,9 @@ even if the insured has already dies (for term-fix insurances)} \item{unitcosts.PolicyPeriod}{Unit costs (absolute monetary amount, during full contract period)} } +\value{ +an insurance cost structure (multi-dimensional matrix) +} \description{ Initialize a cost matrix with dimensions: \{CostType, Basis, Period\}, where: \describe{ diff --git a/man/padLast.Rd b/man/padLast.Rd index 7997f186a1fcc58a5cc2e145365f6ef03ad5e7aa..8fb78b89ae83595b4b058c3825d4fbf996d69cb7 100644 --- a/man/padLast.Rd +++ b/man/padLast.Rd @@ -12,6 +12,9 @@ padLast(v, ...) \item{...}{arguments passed through to \code{pad0}} } +\value{ +vector padded to the correct length +} \description{ This function is just a trivial wrapper around \code{pad0} and only calls \code{\link[=pad0]{pad0()}} with the last element of the vector as padding value instead of the default 0. diff --git a/man/valueOrFunction.Rd b/man/valueOrFunction.Rd index 9b09a76bd5f4b7e80cca8049dd1c8605d7f4d188..d9a348d71eaecd7bde82bc41ab0e18ce57b69a03 100644 --- a/man/valueOrFunction.Rd +++ b/man/valueOrFunction.Rd @@ -11,6 +11,9 @@ valueOrFunction(val, ...) \item{...}{Argument passed to \code{val} if it is a function} } +\value{ +the value, potentially with the given function applied +} \description{ If \code{val} is a function, evaluate it, otherwise return \code{val} }