Skip to content

Commit a0564a4

Browse files
committed
DOC: Documented new parameter for IRR function
Documented addition of IRR selection logic function. The new function contains default logic for selection of IRR Values. User may enter their own function with custom logic if required.
1 parent b765948 commit a0564a4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

numpy_financial/_financial.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,9 @@ def rate(
708708
rn[~close] = np.nan
709709
return rn
710710

711+
711712
# default selection logic for IRR function when there are > 2 real solutions
712-
def irr_default_selection(eirr):
713+
def _irr_default_selection(eirr):
713714
# check sign of all IRR solutions
714715
same_sign = np.all(eirr > 0) if eirr[0] > 0 else np.all(eirr < 0)
715716

@@ -727,7 +728,8 @@ def irr_default_selection(eirr):
727728
abs_eirr = np.abs(eirr)
728729
return eirr[np.argmin(abs_eirr)]
729730

730-
def irr(values, *, raise_exceptions=False, selection_logic=irr_default_selection):
731+
732+
def irr(values, *, raise_exceptions=False, selection_logic=_irr_default_selection):
731733
r"""Return the Internal Rate of Return (IRR).
732734
733735
This is the "average" periodically compounded rate of return
@@ -749,6 +751,11 @@ def irr(values, *, raise_exceptions=False, selection_logic=irr_default_selection
749751
having reached the maximum number of iterations (IterationsExceededException).
750752
Set to False as default, thus returning NaNs in the two previous
751753
cases.
754+
selection_logic: function, optional
755+
Function for selection logic when more than 1 real solutions is found. User may
756+
insert their own customised function for selection of IRR values.
757+
The function should accept a one-dimensional array of numbers and return a number.
758+
752759
753760
Returns
754761
-------

0 commit comments

Comments
 (0)