Time for action – calculating the net present value
We will calculate the net present value for a random generated cash flow series:
- Generate five random values for the cash flow series. Insert
-100
as the start value:cashflows = np.random.randint(100, size=5) cashflows = np.insert(cashflows, 0, -100) print("Cashflows", cashflows)
The cash flows would be as follows:
Cashflows [-100 38 48 90 17 36]
- Call the
npv()
function to calculate the net present value from the cash flow series we generated in the previous step. Use a rate of3
percent:print("Net present value", np.npv(0.03, cashflows))
The net present value:
Net present value 107.435682443
What just happened?
We computed the net present value from a random generated cash flow series with the ...
Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.