開始使用免費開始

定期 vs 終身

最後,請幫 Cynthia 撰寫一個「定期先付終身年金」的函式,付款期間受時間限制。第一次付款發生在時間點 0,最後一次在時間點 n-1。

life_table 與 R 函式 life_annuity_due 仍在你的工作空間中可用。

本練習屬於課程

以 R 估值人壽保險商品

檢視課程

練習說明

  • life_annuity_due() 的程式碼為起點,定義函式 temporary_life_annuity_due(),使其可計算定期先付終身年金的 EPV。此函式多了一個參數 n,代表付款次數。因此 kpxdiscount_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(___, ___, ___, ___)
編輯並執行程式碼