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
Showing
with 84 additions and 33 deletions
......@@ -16,6 +16,9 @@ all inherited values from the tariff and the profit participation)}
\item{values}{The values calculated from the insurance contract so far}
}
\value{
vector of linearly decreasing benefits over the whole insurance coverage period
}
\description{
The death benefit will be the full sumInsured for the first year after the
deferral period and then decrease linearly to 0 at the end of the policyPeriod.
......
......@@ -2,21 +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.
......@@ -37,5 +40,5 @@ contract = InsuranceContract$new(
sumInsured = 1000,
contractClosing = as.Date("2016-10-01")
);
\dontrun{exportInsuranceContract.xlsx(contract, "Example_annuity_contract.xlsx")}
\donttest{exportInsuranceContract.xlsx(contract, tempfile("Example_annuity_contract", fileext = ".xlsx"))}
}
......@@ -32,8 +32,11 @@ multiple exports.}
\item{...}{Further parameters (passed on to \code{\link{showVmGlgExamples}})}
}
\value{
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).
}
......@@ -60,6 +63,6 @@ contract = InsuranceContract$new(
sumInsured = 1000,
contractClosing = as.Date("2016-10-01")
);
\dontrun{exportInsuranceContractExample(contract, prf = 10)}
\donttest{exportInsuranceContractExample(contract, prf = 10, outdir = tempdir())}
}
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -15,6 +15,9 @@ freqCharge(monthly = 0, quarterly = 0, semiannually = 0, yearly = 0)
\item{yearly}{Surcharge for yearly premium payments (optiona, default is no surcharge)}
}
\value{
a named list of surcharges for names 1 (yearly), 2 (semiannually), 4 (quarterly) and 12 (monthly) payments
}
\description{
Tariffs are typically calculated with yearly premium installments. When
premiums are paid more often then one a year (in advance), the insurance
......
......@@ -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{
......
......@@ -11,6 +11,9 @@ isRegularPremiumContract(params, values)
\item{values}{Unused by default (already calculated values of the contract)}
}
\value{
TRUE or FALSE, indicating a contract with regular premiums
}
\description{
Regular premium contracts are identified by the parameter \code{premiumPeriod > 1}.
}
......@@ -11,6 +11,9 @@ isSinglePremiumContract(params, values)
\item{values}{Unused by default (already calculated values of the contract)}
}
\value{
TRUE or FALSE, indicating a single-premium contract or not
}
\description{
Single premium contracts are identified by the parameter \code{premiumPeriod = 1}.
}
......@@ -14,6 +14,11 @@ makeContractGridDimnames(axes)
\item{axes}{the axes with all names, for which a name should be generated}
}
\value{
The name of the entry in the dimnames of \code{\link[=contractGrid]{contractGrid()}}
an array of dimnames derived from the axes definitions of \code{\link[=contractGrid]{contractGrid()}}
}
\description{
The function \code{makeContractGridDimname} generates a short, human-readable
dimension label for the entries along the axes of a \code{\link[=contractGrid]{contractGrid()}}.
......
......@@ -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.
......
......@@ -12,6 +12,9 @@ all inherited values from the tariff and the profit participation)}
\item{values}{The values calculated from the insurance contract so far}
}
\value{
The length of the premium refund period (deferral period for deferred contracts, contract period otherwise)
}
\description{
If a premium refund is set for the tariff, the default is the full contract
period, except for deferred contracts (typically deferred life annuities),
......
......@@ -19,6 +19,9 @@ showVmGlgExamples(contract, prf = 10, t = 10, t_prf = 12, file = "", ...)
\item{...}{Further parameters for generating the contract for a tariff object}
}
\value{
Name of the output file (invisible) or empty if printed to console
}
\description{
Display the values of the example calculation of the given insurance contract
as required by the Austrian regulation (LV-VMGLV, "LV
......@@ -40,7 +43,7 @@ contract = InsuranceContract$new(
showVmGlgExamples(contract)
# Optionally output to a file rather than the console:
\dontrun{
showVmGlgExamples(contract, file = "annuity-example.txt")
\donttest{
showVmGlgExamples(contract, file = tempfile("annuity-example", fileext = ".txt"))
}
}
......@@ -45,6 +45,9 @@ testVmGlgExample(
\item{...}{Further parameters for generating the contract for a tariff object}
}
\value{
None
}
\description{
Check the values of the example calculation of the given insurance contract
as required by the Austrian regulation (LV-VMGLV, "LV
......@@ -57,13 +60,15 @@ The easiest way to write unit-tests is using the function \code{vmGlgExample.gen
}
\examples{
library(MortalityTables)
library(testthat)
mortalityTables.load("Austria_Annuities_AVOe2005R")
\dontrun{
test_that("Testtarif", {
# A trivial deferred annuity tariff with no costs:
library(MortalityTables)
mortalityTables.load("Austria_Annuities")
tariff = InsuranceTarif$new(name="Test Annuity", type="annuity",
mortalityTable = AVOe2005R.unisex, i=0.01)
mortalityTable = AVOe2005R.unisex, i = 0.01)
contract = InsuranceContract$new(
tariff,
age = 35, YOB = 1981,
......@@ -83,14 +88,13 @@ test_that("Testtarif", {
VwKostenRes = 0.00,
VwKostenRes.prf = 0.00,
Bilanzreserve = 9250.35,
Praemienuebertrag = 212.52,
Praemienuebertrag = 637.567,
Rueckkaufsreserve = 9011.40,
Rueckkaufswert = 9011.40,
Abschlusskostenruecktrag = 0.00,
Rueckkaufswert.prf = 9205.96,
VS.prf = 685.12
VS.prf = 684.117
)
})
}
}
......@@ -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}
}
......
......@@ -19,6 +19,9 @@ values is generated.}
\item{...}{Further parameters for generating the contract for a tariff object}
}
\value{
None (code is printed to the console, but no value returned)
}
\description{
This function calculates the required reference values for the given
insurance contract as required by the Austrian regulation (LV-VMGLV, "LV
......
......@@ -28,20 +28,20 @@ test_that("Extend contract by $addExtension", {
# premium-free extension
ContractB = ContractA$clone()$addExtension(id = "Verlängerung1", contractPeriod = 5, premiumPeriod = 0)
expect_equal(ContractB$blocks$Verlängerung1$Parameters$ContractData$sumInsured, 15117.03896)
ContractB = ContractA$clone()$addExtension(id = "Verlaengerung1", contractPeriod = 5, premiumPeriod = 0)
expect_equal(ContractB$blocks$Verlaengerung1$Parameters$ContractData$sumInsured, 15117.03896)
# extension with given sumInsured resulting in 0 premiums
ContractC = ContractA$clone()$addExtension(id = "Verlängerung1", contractPeriod = 5, sumInsured = 15117.03896)
expect_equal(ContractC$blocks$Verlängerung1$Values$premiums[["gross"]], 0, tolerance = 1e-06)
ContractC = ContractA$clone()$addExtension(id = "Verlaengerung1", contractPeriod = 5, sumInsured = 15117.03896)
expect_equal(ContractC$blocks$Verlaengerung1$Values$premiums[["gross"]], 0, tolerance = 1e-06)
# extension with increased sumInsured: real premiums are charged, reserves start from the existing reserve:
ContractD = ContractA$clone()$addExtension(id = "Verlängerung1", contractPeriod = 5, sumInsured = 20000)
expect_equal(ContractD$blocks$Verlängerung1$Values$premiums[["written"]], 315.109)
expect_equal(ContractD$blocks$Verlängerung1$Values$reserves[["0", "contractual"]], 10000)
ContractD = ContractA$clone()$addExtension(id = "Verlaengerung1", contractPeriod = 5, sumInsured = 20000)
expect_equal(ContractD$blocks$Verlaengerung1$Values$premiums[["written"]], 315.109)
expect_equal(ContractD$blocks$Verlaengerung1$Values$reserves[["0", "contractual"]], 10000)
# extension with increased sumInsured and different tariff: check whether interest rate has really changed
ContractE = ContractA$clone()$addExtension(id = "Verlängerung1", contractPeriod = 5, sumInsured = 20000, tarif = Tarif.EndowmentB)
ContractE = ContractA$clone()$addExtension(id = "Verlaengerung1", contractPeriod = 5, sumInsured = 20000, tarif = Tarif.EndowmentB)
expect_equal(unname(ContractE$Values$basicData[c(1,20,30,40), "InterestRate"]), c(0.03, 0.03, 0.01, 0.01))
})
......@@ -29,7 +29,6 @@ library(LifeInsureR)
library(dplyr)
library(tibble)
library(lubridate)
options(scipen=5)
library(pander)
```
......@@ -103,9 +102,8 @@ to validate the official numbers in the financial statements).
## Steps to implement batch-testing a whole (sub-)portfolio
1. Implement the corresponding products in the files in the `R/`
subdirectory. Use the LifeInsureR documentation for further details and guidance.
<!-- available at -->
<!-- <https://cran.r-project.org/package=LifeInsureR/vignettes/using-the-lifeinsurer-package.html> -->
subdirectory. Use the (LifeInsureR documentation)<using-the-lifeinsurer-package.html>
for further details and guidance.
2. Install the package (using the "Install" button in RStudio's "Build"
pane)
3. Set up the mapping of the columns of the contract data source to the
......
......@@ -28,7 +28,6 @@ library(LifeInsureR)
library(dplyr)
library(tibble)
library(lubridate)
options(scipen=5)
library(pander)
......@@ -1505,25 +1504,25 @@ ContractA = InsuranceContract$new(
# premium-free extension
ContractB = ContractA$clone()$
addExtension(id = "Verlängerung1", contractPeriod = 5, premiumPeriod = 0)
addExtension(id = "Verlaengerung1", contractPeriod = 5, premiumPeriod = 0)
# sumInsured calculated from existing reserve:
ContractB$blocks$Verlängerung1$Parameters$ContractData$sumInsured
ContractB$blocks$Verlaengerung1$Parameters$ContractData$sumInsured
ContractB$Values$basicData
# extension with given sumInsured resulting in 0 (gross) premiums
ContractC = ContractA$clone()$
addExtension(id = "Verlängerung1", contractPeriod = 5, sumInsured = 10723.07973354)
ContractC$blocks$Verlängerung1$Values$premiums[["gross"]]
addExtension(id = "Verlaengerung1", contractPeriod = 5, sumInsured = 10723.07973354)
ContractC$blocks$Verlaengerung1$Values$premiums[["gross"]]
ContractC$Values$basicData
# extension with increased sumInsured: real premiums are charged, reserves start from the existing reserve:
ContractD = ContractA$clone()$
addExtension(id = "Verlängerung1", contractPeriod = 5, sumInsured = 20000)
addExtension(id = "Verlaengerung1", contractPeriod = 5, sumInsured = 20000)
ContractD$Values$basicData
# extension with regular premiums, which are given: sumInsured is calculated from it, reserves start from the existing reserve:
ContractD = ContractA$clone()$
addExtension(id = "Verlängerung1", contractPeriod = 5, premium = 597.8771)
addExtension(id = "Verlaengerung1", contractPeriod = 5, premium = 597.8771)
ContractD$Values$basicData
```
......