How to Calculate NPV using numpy_financial

You can use the following template to calculate the NPV using numpy_financial:

import numpy_financial as npf

npv = npf.npv(discount rate, [initial investment in negative terms, cash flow for each year separated by comma])

print(npv)

Let’s now review a simple example with the steps to calculate the NPV.

Steps to Calculate the NPV using Numpy

Step 1: Install the numpy_financial package

Install the numpy_financial package using:

pip install numpy_financial

Step 2: Gather your data

Now you’ll need to gather the data for the NPV calculation.

For example, let’s suppose that you have the following data about a project:

  • The initial investment is $1100
  • The project is expected to generate:
    • $300 in year-1
    • $450 in year-2
    • $800 in year-3
  • The discount rate is 5%

Step 3: Calculate the NPV

To calculate the NPV using numpy_financial:

import numpy_financial as npf

npv = npf.npv(0.05, [-1100, 300, 450, 800])

print(npv)

Run the code in Python and you’ll get the NPV of 284.947

Since the NPV is positive, you should consider to invest in the project.