現金流折現
你可以使用 numpy 的淨現值函式 numpy.npv(rate, values) 來計算一系列現金流的淨現值。你可以用 numpy.array([...]) 建立這些現金流的數值。
在不同折現率下,計算下列專案相同現金流的 NPV:
| Year | Cash Flow |
|---|---|
| 1 | $100 |
| 2 | $100 |
| 3 | $100 |
| 4 | $100 |
| 5 | $100 |
本練習屬於課程
Python 金融概念入門
練習說明
- 以每年 3% 的折現率,使用
cash_flows計算投資的淨現值,並指定給investment_1。 - 以每年 5% 的折現率重複上述步驟,並指定給
investment_2。 - 以每年 7% 的折現率重複上述步驟,並指定給
investment_3。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Predefined array of cash flows
cash_flows = np.array([100, 100, 100, 100, 100])
# Calculate investment_1
investment_1 = np.npv(rate=____, values=____)
print("Investment 1's net present value is $" + str(round(investment_1, 2)) + " in today's dollars")
# Calculate investment_2
investment_2 = np.npv(rate=____, values=____)
print("Investment 2's net present value is $" + str(round(investment_2, 2)) + " in today's dollars")
# Calculate investment_3
investment_3 = np.npv(rate=____, values=____)
print("Investment 3's net present value is $" + str(round(investment_3, 2)) + " in today's dollars")