開始使用免費開始

現值(Present value)

幸運的是,numpy 模組提供了許多函式,能讓你在處理金融數值時輕鬆許多。

例如 .pv(rate, nper, pmt, fv) 函式,可以用幾個簡單的參數,像先前一樣計算投資的現值:

  • rate: 投資的報酬率
  • nper: 投資的存續期間(期數)
  • pmt: 每期期初或期末的固定付款(在本例中為 0)
  • fv: 投資的未來價值

這個公式有很多用法。例如,你可以用它把未來的投資折算成以今天幣值計算的現值。

本練習屬於課程

Python 金融概念入門

檢視課程

練習說明

  • 匯入 numpy 並命名為 np
  • 使用 NumPy 的 .pv() 函式,計算一項投資在 15 年後可得到 $10,000、且年通膨率為 3% 時的現值,並指派給 investment_1
  • 計算相同投資但期間僅 10 年、年通膨率為 5% 的現值,並指派給 investment_2

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import numpy as np
____

# Calculate investment_1
investment_1 = ____(rate=____, nper=____, pmt=____, fv=10000)

# Note that the present value returned is negative, so we multiply the result by -1
print("Investment 1 is worth " + str(round(-investment_1, 2)) + " in today's dollars")

# Calculate investment_2
investment_2 = ____
print("Investment 2 is worth " + str(round(-investment_2, 2)) + " in today's dollars")
編輯並執行程式碼