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:

  1. 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]
    
  2. 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", cashflows

print "Net present value", np.npv(0.03, cashflows)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.216.163