10.12.2019 Views

Python for Finance

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3

To estimate the NPV of a project, we could call the npv() function contained either

in SciPy or numpy.lib.financial; see the following code:

>>>import scipy as sp

>>>cashflows=[-100,50,60,70]

>>>rate=0.1

>>>npv=sp.npv(rate,cashflows)

>>>round(npv,2)

47.62

The scipy.npv() function estimates the present values for a given set of cash flows.

The first input variable is the discount rate, while the second input is an array of

cash flows. Note that the first cash flow in this cash flow array happens at time zero.

This scipy.npv() function is different from the Excel's NPV function, which is not a

true NPV function. Actually, the Excel NPV is a PV function. It estimates the present

value of future cash flows by assuming the first cash flow happens at the end of the

first period. An example of using an Excel npv() function is as follows:

[ 87 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!