折现现金流
您可以使用 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")