Skip to content
Snippets Groups Projects
Commit 8abb125b authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Add commutationNumbers function to calculate commutation numbers lx, dx, Dx,...

Add commutationNumbers function to calculate commutation numbers lx, dx, Dx, Nx, Sx, Cx, Mx, Rx  for a given mortality table or vector of death probabilities
parent c6107537
Branches
Tags
No related merge requests found
...@@ -34,6 +34,8 @@ Collate: ...@@ -34,6 +34,8 @@ Collate:
'ages.R' 'ages.R'
'baseTable.R' 'baseTable.R'
'baseYear.R' 'baseYear.R'
'pensionTable.R'
'commutationNumbers.R'
'mortalityTable.improvementFactors.R' 'mortalityTable.improvementFactors.R'
'mortalityTable.trendProjection.R' 'mortalityTable.trendProjection.R'
'deathProbabilities.R' 'deathProbabilities.R'
...@@ -51,7 +53,6 @@ Collate: ...@@ -51,7 +53,6 @@ Collate:
'mortalityTable.jointLives.R' 'mortalityTable.jointLives.R'
'mortalityTables.list.R' 'mortalityTables.list.R'
'mortalityTables.load.R' 'mortalityTables.load.R'
'pensionTable.R'
'plot.mortalityTable.R' 'plot.mortalityTable.R'
'plotMortalityTableComparisons.R' 'plotMortalityTableComparisons.R'
'plotMortalityTables.R' 'plotMortalityTables.R'
......
...@@ -43,6 +43,7 @@ exportMethods(ages) ...@@ -43,6 +43,7 @@ exportMethods(ages)
exportMethods(baseTable) exportMethods(baseTable)
exportMethods(baseYear) exportMethods(baseYear)
exportMethods(calculateImprovements) exportMethods(calculateImprovements)
exportMethods(commutationNumbers)
exportMethods(deathProbabilities) exportMethods(deathProbabilities)
exportMethods(getCohortTable) exportMethods(getCohortTable)
exportMethods(getOmega) exportMethods(getOmega)
......
#' @include mortalityTable.R pensionTable.R
NULL
#' Calculate the commutation numbers for the given parameters, using the mortality table and an interest rate
#'
#' @param object The life table object (class inherited from mortalityTable)
#' @param ... Other parameters to be passed to the deathProbabilities call (e.g. YOB)
#' @param i Interest rate used for the calculation of the commutation numbers
#'
#' @examples
#' mortalityTables.load("Austria_Annuities")
#' commutationNumbers(AVOe2005R.male, i = 0.03, YOB = 1975)
#'
#' @exportMethod commutationNumbers
setGeneric("commutationNumbers", function(object, ..., i = 0.03) standardGeneric("commutationNumbers"));
#' @describeIn commutationNumbers Calculate the commutation numbers for the given
#' parameters, using the mortality table and an interest rate
setMethod("commutationNumbers", "mortalityTable",
function(object, ..., i = 0.03) {
ages = ages(object, ...)
qx = deathProbabilities(object, ...)
commutationNumbers(qx, ages, i)
})
#' @describeIn commutationNumbers Calculate the commutation numbers for the given
#' death probabilities (passed as a numeric vector with argument
#' name "object"), ages and an interest rate
#' Return value is a list of data frames
setMethod("commutationNumbers", "numeric",
function(object, ages, i = 0.03) {
v = 1/(1 + i)
lx = cumprod(c(100000, 1 - object[-length(object)]))
dx = -diff(c(lx, 0))
Dx = v^ages * lx
Nx = rev(cumsum(rev(Dx))) # Nx is sum of Dx from x to omega
Sx = rev(cumsum(rev(Nx))) # Sx is sum of Nx from x to omega
Cx = qx * v * Dx
Mx = rev(cumsum(rev(Cx)))
Rx = rev(cumsum(rev(Mx)))
data.frame(age = ages, qx, lx, dx, Dx, Nx, Sx, Cx, Mx, Rx)
})
#' @describeIn commutationNumbers Calculate the commutation numbers for the given
#' parameters, using the pension table and an interest rate
#' Return value is a list of data frames
setMethod("commutationNumbers", "pensionTable",
function(object, ..., i = 0.03) {
probs = transitionProbabilities(object, ...)
ages = probs$x
list(
q = commutationNumbers(probs$q, ages = ages, i = i),
qi = commutationNumbers(probs$qi, ages = ages, i = i),
qp = commutationNumbers(probs$qp, ages = ages, i = i),
qw = commutationNumbers(probs$qw, ages = ages, i = i),
qg = commutationNumbers(probs$qg, ages = ages, i = i)
)
})
# commutationNumbers(deathProbabilities(AVOe2008P.male@qpx, YOB = 1982), ages(AVOe2008P.male@qpx), i = 0.06)
# commutationNumbers(AVOe2008P.male@qpx, i = 0.06, YOB = 1982) %>% View
# AVOe2008P.male.Comm = commutationNumbers(AVOe2008P.male, i = 0.06, YOB = 1982)
# AVOe2008P.male.Comm[["q"]] %>% View
# AVOe2008P.male.Comm[["qi"]] %>% View
# AVOe2008P.male.Comm[["qp"]] %>% View
# AVOe2008P.male.Comm[["qw"]] %>% View
# AVOe2008P.male.Comm[["qg"]] %>% View
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/commutationNumbers.R
\docType{methods}
\name{commutationNumbers}
\alias{commutationNumbers}
\alias{commutationNumbers,mortalityTable-method}
\alias{commutationNumbers,numeric-method}
\alias{commutationNumbers,pensionTable-method}
\title{Calculate the commutation numbers for the given parameters, using the mortality table and an interest rate}
\usage{
commutationNumbers(object, ..., i = 0.03)
\S4method{commutationNumbers}{mortalityTable}(object, ..., i = 0.03)
\S4method{commutationNumbers}{numeric}(object, ages, i = 0.03)
\S4method{commutationNumbers}{pensionTable}(object, ..., i = 0.03)
}
\arguments{
\item{object}{The life table object (class inherited from mortalityTable)}
\item{...}{Other parameters to be passed to the deathProbabilities call (e.g. YOB)}
\item{i}{Interest rate used for the calculation of the commutation numbers}
}
\description{
Calculate the commutation numbers for the given parameters, using the mortality table and an interest rate
}
\section{Methods (by class)}{
\itemize{
\item \code{mortalityTable}: Calculate the commutation numbers for the given
parameters, using the mortality table and an interest rate
\item \code{numeric}: Calculate the commutation numbers for the given
death probabilities (passed as a numeric vector with argument
name "object"), ages and an interest rate
Return value is a list of data frames
\item \code{pensionTable}: Calculate the commutation numbers for the given
parameters, using the pension table and an interest rate
Return value is a list of data frames
}}
\examples{
mortalityTables.load("Austria_Annuities")
commutationNumbers(AVOe2005R.male, i = 0.03, YOB = 1975)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment