任何時間、任何地點?
回顧自己的消費模式,Cynthia 想知道,如果不把錢花在下載和演唱會門票上,而是存進銀行帳戶,她最後能領到多少錢。為此,你將使用合適的貼現函數,計算在未來某個時間點的現金流價值。
上圖顯示了 Cynthia 的消費模式。你在第一個練習中定義的 cash_flows 向量已預先載入到你的工作環境。利率仍為 2%。
本練習屬於課程
以 R 估值人壽保險商品
練習說明
- 定義函式
discount(),用來計算在時間 \(t\) 支付 1 EUR,在時間 \(s\) 的價值。 - 使用
discount()計算cash_flows在時間 0 到 5 的現值。結果應與你先前的答案相同,也就是 444.93 EUR。 - 印出當 Cynthia 在 6 年後年滿 18 歲時,現金流向量的價值。
- 用另一種方式計算在時間 6 的累積價值。這次把時間 0 的
present_value轉換為時間 6 的價值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define the discount function v
discount <- function(s, t, i = 0.02) {
(1 + ___) ^ - (___ - ___)
}
# Calculate the present value
present_value <- sum(cash_flows * discount(___, ___))
present_value
# Calculate the value at time 6
sum(cash_flows * discount(___, ___))
# Calculate the value at time 6, starting from present_value
present_value * discount(___, ___)