numpy_financial.mirr#

numpy_financial.mirr(values: _CanArrayAndLen[floating[Any] | integer[Any] | bool | object_] | _NestedSequence[float | Decimal | floating[Any] | integer[Any] | bool | object_], finance_rate: float | Decimal | floating[Any] | integer[Any] | bool | object_, reinvest_rate: float | Decimal | floating[Any] | integer[Any] | bool | object_, *, raise_exceptions: bool = False) → float#
numpy_financial.mirr(values: _CanArrayAndLen[floating[Any] | integer[Any] | bool | object_] | _NestedSequence[float | Decimal | floating[Any] | integer[Any] | bool | object_], finance_rate: _CanArrayAndLen[floating[Any] | integer[Any] | bool | object_] | Sequence[float | Decimal | floating[Any] | integer[Any] | bool | object_], reinvest_rate: _CanArrayAndLen[floating[Any] | integer[Any] | bool | object_] | Sequence[float | Decimal | floating[Any] | integer[Any] | bool | object_], *, raise_exceptions: bool = False) → NDArray[float64]
numpy_financial.mirr(values: ArrayLike | _NestedSequence[Decimal] | Decimal, finance_rate: ArrayLike | _NestedSequence[Decimal] | Decimal, reinvest_rate: ArrayLike | _NestedSequence[Decimal] | Decimal, *, raise_exceptions: bool = False) → Any

Return the Modified Internal Rate of Return (MIRR).

MIRR is a financial metric that takes into account both the cost of the investment and the return on reinvested cash flows. It is useful for evaluating the profitability of an investment with multiple cash inflows and outflows.

Parameters:
valuesarray_like, 1D or 2D

Cash flows, where the first value is considered a sunk cost at time zero. It must contain at least one positive and one negative value.

finance_ratescalar or 1D array

Interest rate paid on the cash flows.

reinvest_ratescalar or D array

Interest rate received on the cash flows upon reinvestment.

raise_exceptions: bool, optional

Flag to raise an exception when the MIRR cannot be computed due to having all cash flows of the same sign (NoRealSolutionException). Set to False as default,thus returning NaNs in the previous case.

Returns:
outfloat or 2D array

Modified internal rate of return

Notes

The MIRR formula is as follows:

\[\begin{split}MIRR = \\left( \\frac{{FV_{positive}}}{{PV_{negative}}} \\right)^{\\frac{{1}}{{n-1}}} * (1+r) - 1\end{split}\]
where:
  • (FV_{positive}) is the future value of positive cash flows,

  • (PV_{negative}) is the present value of negative cash flows,

  • (n) is the number of periods.

  • (r) is the reinvestment rate.

Examples

>>> import numpy_financial as npf

Consider a project with an initial investment of -$100 and projected cash flows of $50, -$60, and $70 at the end of each period. The project has a finance rate of 10% and a reinvestment rate of 12%.

>>> npf.mirr([-100, 50, -60, 70], 0.10, 0.12)
-0.03909366594356467

It is also possible to supply multiple cashflows or pairs of finance and reinvstment rates, note that in this case the number of elements in each of the rates arrays must match.

>>> values = [
...             [-4500, -800, 800, 800, 600],
...             [-120000, 39000, 30000, 21000, 37000],
...             [100, 200, -50, 300, -200],
...         ]
>>> finance_rate = [0.05, 0.08, 0.10]
>>> reinvestment_rate = [0.08, 0.10, 0.12]
>>> npf.mirr(values, finance_rate, reinvestment_rate)
array([[-0.1784449 , -0.17328716, -0.1684366 ],
       [ 0.04627293,  0.05437856,  0.06252201],
       [ 0.35712458,  0.40628857,  0.44435295]])

Now, let’s consider the scenario where all cash flows are negative.

>>> npf.mirr([-100, -50, -60, -70], 0.10, 0.12)
nan

Finally, let’s explore the situation where all cash flows are positive, and the raise_exceptions parameter is set to True.

>>> npf.mirr([
...    100, 50, 60, 70],
...    0.10, 0.12,
...    raise_exceptions=True
... )
Traceback (most recent call last):
    ...
numpy_financial._financial.NoRealSolutionError:
No real solution exists for MIRR since  all cashflows are of the same sign.