@@ -904,29 +904,72 @@ def npv(rate, values):
904
904
905
905
906
906
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.
908
914
909
915
Parameters
910
916
----------
911
917
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.
915
920
finance_rate : scalar
916
- Interest rate paid on the cash flows
921
+ Interest rate paid on the cash flows.
917
922
reinvest_rate : scalar
918
- Interest rate received on the cash flows upon reinvestment
923
+ Interest rate received on the cash flows upon reinvestment.
919
924
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.
924
928
925
929
Returns
926
930
-------
927
931
out : float
928
932
Modified internal rate of return
929
933
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
+
930
973
"""
931
974
values = np .asarray (values )
932
975
n = values .size
0 commit comments