w3resource

NumPy Financial functions: irr() function

numpy.irr() function

The irr() function is used to get the Internal Rate of Return (IRR).

This is the "average" periodically compounded rate of return that gives a net present value of 0.0; for a more complete explanation, see Notes below.

decimal.Decimal type is not supported.

Syntax:

numpy.irr(values)

Version: 1.15.0

Parameter:

Name Description Required /
Optional
values Input cash flows per time period. By convention, net "deposits" are negative and net "withdrawals" are positive.
Thus, for example, at least the first element of values, which represents the initial investment, will typically be negative.
array_like, shape(N,)
Required

Returns: out : float

Internal Rate of Return for periodic input values.

Notes:

The IRR is perhaps best understood through an example (illustrated using np.irr in the Examples section below).
Suppose one invests 200 units and then makes the following withdrawals at regular (fixed) intervals: 78, 118, 111, 40.
Assuming the ending value is 0, one's 200 unit investment yields 347 units; however,
due to the combination of compounding and the periodic withdrawals, the "average" rate of return is neither simply 0.73/4 nor (1.73)^0.25-1.
Rather, it is the solution (for r) of the equation:

-200 + \frac{78}{1+r} + \frac{118}{(1+r)^2} + \frac{110}{(1+r)^3} + 
\frac{40}{(1+r)^4} = 0

In general, for values = [v_0, v_1, ... v_M], irr is the solution of the equation: [G]

\sum_{t=0}^M{\frac{v_t}{(1+irr)^{t}}} = 0

NumPy.irr() method Example-1:

>>> import numpy as np
>>> round(np.irr([-200, 78, 118, 111, 40]), 5)

Output:

0.28239

NumPy.irr() method Example-2:

>>> import numpy as np
>>> round(np.irr([-200, 0, 0, 74]), 4)

Output:

-0.2821

NumPy.irr() method Example-3:

>>> import numpy as np
>>> round(np.irr([-200, 200, 0, -7]), 4)

Output:

-0.0378

NumPy.irr() method Example-4:

>>> import numpy as np
>>> round(np.irr([-200, 200, 0, 7]), 4)

Output:

0.0328

NumPy.irr() method Example-5:

>>> import numpy as np
>>> round(irr([-5, 10.5, 1, -8, 1]), 5)

Output:

0.0886

(Compare with the Example given for numpy.lib.financial.npv)

Python - NumPy Code Editor:

Previous: ipmt() function
Next: mirr() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/numpy/financial-functions/irr.php