Skip to content

Commit b04ad78

Browse files
author
RVitalii
committed
Updating mirr docstring v2 [issue76]
1 parent d59958b commit b04ad78

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

numpy_financial/_financial.py

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -904,29 +904,71 @@ 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 = \\left( \\frac{{FV_{positive}}}{{PV_{negative}}} \\right)^{\\frac{{1}}{{n-1}}}
941+
* (1+r) - 1
942+
943+
where:
944+
- \(FV_{positive}\) is the future value of positive cash flows,
945+
- \(PV_{negative}\) is the present value of negative cash flows,
946+
- \(n\) is the number of periods.
947+
- \(r\) is the reinvestment rate.
948+
949+
Examples
950+
--------
951+
>>> import numpy_financial as npf
952+
953+
Consider a project with an initial investment of -$100
954+
and projected cash flows of $50, -$60, and $70 at the end of each period.
955+
The project has a finance rate of 10% and a reinvestment rate of 12%.
956+
957+
>>> npf.mirr([-100, 50, -60, 70], 0.10, 0.12)
958+
-0.03909366594356467
959+
960+
Now, let's consider the scenario where all cash flows are negative.
961+
962+
>>> npf.mirr([-100, -50, -60, -70], 0.10, 0.12)
963+
nan
964+
965+
Finally, let's explore the situation where all cash flows are positive,
966+
and the `raise_exceptions` parameter is set to True.
967+
968+
>>> npf.mirr([100, 50, 60, 70], 0.10, 0.12, raise_exceptions=True)
969+
NoRealSolutionError: No real solution exists for MIRR since all
970+
cashflows are of the same sign.
971+
930972
"""
931973
values = np.asarray(values)
932974
n = values.size

0 commit comments

Comments
 (0)