初始專案成本
numpy.npv(rate, values) 函式很強大,因為它允許你同時傳入正值與負值。
在這個練習中,你要計算兩個潛在專案在不同現金流下的淨現值:
| Year | Project 1 | Project 2 |
|---|---|---|
| 1 | -$250(初始投資) | -$250(初始投資) |
| 2 | $100 現金流 | $300 現金流 |
| 3 | $200 現金流 | -$250(淨投資) |
| 4 | $300 現金流 | $300 現金流 |
| 5 | $400 現金流 | $300 現金流 |
在這個例子中,project 1 只需要 $250 的初始投資,接下來 4 年會逐步增加現金流。
相對地,project 2 在第 1 年需要 $250 的初始投資,並在第 3 年再投入 $250。然而,project 2 之後持續產生較大的現金流。
假設兩個專案在第 5 年後都不再產生現金流,你會選擇哪一個專案?最好的做法是比較兩個專案的 NPV。
本練習屬於課程
Python 金融概念入門
練習說明
- 建立 project 1 的現金流
numpy陣列並指定給cash_flows_1,再為 project 2 做相同的事,指定給cash_flows_2。 - 在通膨率為 3% 的假設下,計算兩個專案的淨現值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Create an array of cash flows for project 1
cash_flows_1 = np.array(____)
# Create an array of cash flows for project 2
cash_flows_2 = np.array(____)
# Calculate the net present value of project 1
investment_1 = np.npv(rate=____, values=____)
print("The net present value of Investment 1 is worth $" + str(round(investment_1, 2)) + " in today's dollars")
# Calculate the net present value of project 2
investment_2 = np.npv(rate=____, values=____)
print("The net present value of Investment 2 is worth $" + str(round(investment_2, 2)) + " in today's dollars")