A function to price a life annuity
Cynthia's internship supervisor does not have much experience with R. He asks her to write an R function that calculates the EPV of a (whole) life annuity due on \((x)\) for a given constant interest rate \(i\) and life table.
Since the benefit is constant at 1 EUR, there is no need to take it explicitly into account in the calculations.
This exercise is part of the course
Life Insurance Products Valuation in R
Exercise instructions
- Write a function
life_annuity_due()
that calculates the EPV of a whole life annuity due for input argumentsage
, interest ratei
andlife_table
. - Apply
life_annuity_due()
to compute the EPV of a life annuity due for (20) at rate 2%. Use the 1999 Belgian period life table for females which is preloaded aslife_table
. - Find out how the EPV changes if the interest rate increases to 5% (keeping the age at 20). And what if the age changes to 65 (keeping the interest rate at 2%)?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Function to compute the EPV of a whole life annuity due for a given age, interest rate i and life table
life_annuity_due <- function(age, i, life_table) {
px <- ___
kpx <- c(___, ___(px[(___):length(px)]))
discount_factors <- (___) ^ - (0:(___))
sum(discount_factors * kpx)
}
# EPV of a whole life annuity due for (20) at interest rate 2% using life_table
life_annuity_due(___, ___, ___)
# EPV of a whole life annuity due for (20) at interest rate 5% and for (65) at interest rate 2% using life_table
life_annuity_due(___, ___, ___)
life_annuity_due(___, ___, ___)