Temporary vs lifelong
Finally, can you assist Cynthia in writing a function for a temporary life annuity due in which the payments are restricted in time? The first payment takes place at time \(0\) and the last at time \(n-1\).
Both life_table
and the R function life_annuity_due
are still available in your workspace.
This exercise is part of the course
Life Insurance Products Valuation in R
Exercise instructions
- Define the function
temporary_life_annuity_due()
starting from thelife_annuity_due()
code such that the EPV is computed for a temporary life annuity due. The function now has an extra argumentn
which indicates the number of payments. Bothkpx
anddiscount_factors
should hence have a total length ofn
. - Use
temporary_life_annuity_due()
to calculate the EPV of a 10-year life annuity due for (20) at rate 2% using the 1999 period life table for females.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# EPV of a whole life annuity due for (20) at interest rate 2% using life_table
life_annuity_due(20, 0.02, life_table)
# Function to compute the EPV of a temporary life annuity due for a given age, period of n years, interest rate i and life table
temporary_life_annuity_due <- function(age, n, i, life_table) {
px <- 1 - life_table$qx
kpx <- c(1, cumprod(px[(___):(___)]))
discount_factors <- (1 + i) ^ - (0:(___))
___
}
# EPV of a temporary life annuity due for (20) over 10 years at interest rate 2% using life_table
temporary_life_annuity_due(___, ___, ___, ___)