Here is a simple template that you can use in order to calculate the IRR using numpy:
import numpy as np irr = np.irr([initial investment in negative terms, cash flows each year separated by commas]) print (irr)
Steps to calculate the IRR using Numpy
Step 1: Install the numpy package
If you haven’t already done so, install the numpy package using:
pip install numpy
Step 2: Calculate the IRR using numpy
To calculate the IRR using numpy, you’ll need to use this template:
import numpy as np irr = np.irr([initial investment in negative terms, cash flows each year separated by commas]) print (irr)
Let’s now review an example to see how to use this template in practice.
Imagine that you have the following information about a project:
- The initial investment is $1700
- The project is expected to generate:
- $500 in year-1
- $750 in year-2
- $800 in year-3
What is the IRR?
To calculate the IRR using numpy, you’ll need to apply this code in Python:
import numpy as np irr = np.irr([-1700,500,750,800]) print(irr)
And if you run this code, you’ll get the IRR of 0.09236 (or 9.236%).