Calculating net present value-npv using Python and numpy

Net present value calculation involves finding the present value of each cash flow at the specific discount rate and summing them together. The Python example uses numpy.npv() function to examine and decide whether an investment is profitable.

NumPy Updated 20 Mar 2019 1 min read

Overview

  • Net Present Value is a tool for selecting among multiple investment avenues.
  • The rule of Net Present Value is to select an investment with a maximum positive NPV and reject the investments that warrant negative NPV or lesser NPVs.
  • The formula for NPV is

NPV Formula

CFt - Net cash flow at time t

N - Total number of Periods

r - Discount rate or rate of return

  • Given a series of cash flows the numpy.npv() method returns the Net Present Value of the cash flows.

Example 1: Calculating the NPV for an investment

python
import numpy as np

cashflows       = [-500, 200, 147, 128, 130, 235]; # t0, t1, t2, t3, t4, t5

discountRate    = 0.9; # Nine percent per annum

npv             = np.npv(discountRate, cashflows);

print("Net present value of the investment:%3.2f"%npv);

Output

Output
Net present value of the investment:-315.89