定期与终身
最后,您能帮助 Cynthia 编写一个「定期即付生命年金」函数吗?该年金的给付在时间上受限:第一次给付发生在时间 $0$,最后一次给付发生在时间 $n-1$。
life_table 和 R 函数 life_annuity_due 仍在您的工作区中可用。
本练习是课程的一部分
用 R 评估人寿保险产品
练习说明
- 以
life_annuity_due()的代码为起点,定义函数temporary_life_annuity_due(),使其计算定期即付生命年金的 EPV。该函数新增参数n,表示给付次数。因此kpx与discount_factors的总长度都应为n。 - 使用
temporary_life_annuity_due(),基于 1999 年女性的定期寿命表,按 2% 利率计算 (20) 的 10 年即付生命年金的 EPV。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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(___, ___, ___, ___)