Discounting cash flows
You can use numpy's net present value function numpy.npv(rate, values)
to calculate the net present value of a series of cash flows. You can create these cash flows by using a numpy.array([...])
of values.
Compute the NPV of the same cash flows from the following project, but assuming different discount rates:
Year | Cash Flow |
---|---|
1 | $100 |
2 | $100 |
3 | $100 |
4 | $100 |
5 | $100 |
This is a part of the course
“Introduction to Financial Concepts in Python”
Exercise instructions
- Calculate the net present value of the investment with
cash_flows
at a discount rate of 3% per year, and assign it toinvestment_1
. - Repeat the process with a discount rate of 5% per year, and assign it to
investment_2
. - Repeat the process with a discount rate of 7% per year, and assign it to
investment_3
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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")