Time for action – calculating the net present value
We will calculate the net present value for a randomly generated cash flow series. Perform the following steps to do so:
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 shown 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 of three percent.print "Net present value", np.npv(0.03, cashflows)
The net present value would be shown as follows:
Net present value 107.435682443
What just happened?
We computed the net present value from a randomly generated cash flow series with the NumPy npv
function (see netpresentvalue.py
).
import numpy as np cashflows = np.random.randint(100, size=5) cashflows = np.insert(cashflows, 0, -100) print "Cashflows...