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

import numpy as np npv = np.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: Gather your data

To start, you’ll need to gather the data for the NPV calculation.

For example, I gathered 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 2: Calculate the NPV using Numpy

Next, use the following template to derive the NPV:

import numpy as np npv = np.npv(discount rate,[initial investment in negative terms, cash flow for each year separated by comma]) print (npv)

The is how the full Python code would look like in the context of our example:

import numpy as np npv = np.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 invest in the project.

You may want to check the following source that includes a tool to calculate the NPV using Python.