Skip to content

Commit f202ec3

Browse files
authored
Merge pull request #86 from RVitalii/iss76
Updating mirr docstring [issue 76]
2 parents b22892e + 4fa06ed commit f202ec3

File tree

1 file changed

+53
-10
lines changed

1 file changed

+53
-10
lines changed

numpy_financial/_financial.py

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -904,29 +904,72 @@ def npv(rate, values):
904904

905905

906906
def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False):
907-
r"""Return the modified internal rate of return.
907+
r"""
908+
Return the Modified Internal Rate of Return (MIRR).
909+
910+
MIRR is a financial metric that takes into account both the cost of
911+
the investment and the return on reinvested cash flows. It is useful
912+
for evaluating the profitability of an investment with multiple cash
913+
inflows and outflows.
908914
909915
Parameters
910916
----------
911917
values : array_like
912-
Cash flows (must contain at least one positive and one negative
913-
value) or nan is returned. The first value is considered a sunk
914-
cost at time zero.
918+
Cash flows, where the first value is considered a sunk cost at time zero.
919+
It must contain at least one positive and one negative value.
915920
finance_rate : scalar
916-
Interest rate paid on the cash flows
921+
Interest rate paid on the cash flows.
917922
reinvest_rate : scalar
918-
Interest rate received on the cash flows upon reinvestment
923+
Interest rate received on the cash flows upon reinvestment.
919924
raise_exceptions: bool, optional
920-
Flag to raise an exception when the mirr cannot be computed due to
921-
having all cashflows of the same sign (NoRealSolutionException).
922-
Set to False as default, thus returning NaNs in the previous
923-
case.
925+
Flag to raise an exception when the MIRR cannot be computed due to
926+
having all cash flows of the same sign (NoRealSolutionException).
927+
Set to False as default,thus returning NaNs in the previous case.
924928
925929
Returns
926930
-------
927931
out : float
928932
Modified internal rate of return
929933
934+
Notes
935+
-----
936+
The MIRR formula is as follows:
937+
938+
.. math::
939+
940+
MIRR =
941+
\\left( \\frac{{FV_{positive}}}{{PV_{negative}}} \\right)^{\\frac{{1}}{{n-1}}}
942+
* (1+r) - 1
943+
944+
where:
945+
- \(FV_{positive}\) is the future value of positive cash flows,
946+
- \(PV_{negative}\) is the present value of negative cash flows,
947+
- \(n\) is the number of periods.
948+
- \(r\) is the reinvestment rate.
949+
950+
Examples
951+
--------
952+
>>> import numpy_financial as npf
953+
954+
Consider a project with an initial investment of -$100
955+
and projected cash flows of $50, -$60, and $70 at the end of each period.
956+
The project has a finance rate of 10% and a reinvestment rate of 12%.
957+
958+
>>> npf.mirr([-100, 50, -60, 70], 0.10, 0.12)
959+
-0.03909366594356467
960+
961+
Now, let's consider the scenario where all cash flows are negative.
962+
963+
>>> npf.mirr([-100, -50, -60, -70], 0.10, 0.12)
964+
nan
965+
966+
Finally, let's explore the situation where all cash flows are positive,
967+
and the `raise_exceptions` parameter is set to True.
968+
969+
>>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True)
970+
NoRealSolutionError: No real solution exists for MIRR since all
971+
cashflows are of the same sign.
972+
930973
"""
931974
values = np.asarray(values)
932975
n = values.size

0 commit comments

Comments
 (0)