parameters: (values)
return_statement: return rate
docstring: Return the Internal Rate of Return (IRR).
  
      .. deprecated:: 1.18
  
         `irr` is deprecated; for details, see NEP 32 [1]_.
         Use the corresponding function in the numpy-financial library,
         https://pypi.org/project/numpy-financial.
  
      This is the "average" periodically compounded rate of return
      that gives a net present value of 0.0; for a more complete explanation,
      see Notes below.
  
      :class:`decimal.Decimal` type is not supported.
  
      Parameters
      ----------
      values : array_like, shape(N,)
          Input cash flows per time period.  By convention, net "deposits"
          are negative and net "withdrawals" are positive.  Thus, for
          example, at least the first element of `values`, which represents
          the initial investment, will typically be negative.
  
      Returns
      -------
      out : float
          Internal Rate of Return for periodic input values.
  
      Notes
      -----
      The IRR is perhaps best understood through an example (illustrated
      using np.irr in the Examples section below).  Suppose one invests 100
      units and then makes the following withdrawals at regular (fixed)
      intervals: 39, 59, 55, 20.  Assuming the ending value is 0, one's 100
      unit investment yields 173 units; however, due to the combination of
      compounding and the periodic withdrawals, the "average" rate of return
      is neither simply 0.73/4 nor (1.73)^0.25-1.  Rather, it is the solution
      (for :math:`r`) of the equation:
  
      .. math:: -100 + \\frac{39}{1+r} + \\frac{59}{(1+r)^2}
       + \\frac{55}{(1+r)^3} + \\frac{20}{(1+r)^4} = 0
  
      In general, for `values` :math:`= [v_0, v_1, ... v_M]`,
      irr is the solution of the equation: [2]_
  
      .. math:: \\sum_{t=0}^M{\\frac{v_t}{(1+irr)^{t}}} = 0
  
      References
      ----------
      .. [1] NumPy Enhancement Proposal (NEP) 32,
         https://numpy.org/neps/nep-0032-remove-financial-functions.html
      .. [2] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
         Addison-Wesley, 2003, pg. 348.
  
      Examples
      --------
      >>> round(np.irr([-100, 39, 59, 55, 20]), 5)
      0.28095
      >>> round(np.irr([-100, 0, 0, 74]), 5)
      -0.0955
      >>> round(np.irr([-100, 100, 0, -7]), 5)
      -0.0833
      >>> round(np.irr([-100, 100, 0, 7]), 5)
      0.06206
      >>> round(np.irr([-5, 10.5, 1, -8, 1]), 5)
      0.0886
docstring_summary: Return the Internal Rate of Return (IRR).
docstring_tokens: Return the Internal Rate of Return ( IRR ) .
function: def irr(values):
      """
      Return the Internal Rate of Return (IRR).
  
      .. deprecated:: 1.18
  
         `irr` is deprecated; for details, see NEP 32 [1]_.
         Use the corresponding function in the numpy-financial library,
         https://pypi.org/project/numpy-financial.
  
      This is the "average" periodically compounded rate of return
      that gives a net present value of 0.0; for a more complete explanation,
      see Notes below.
  
      :class:`decimal.Decimal` type is not supported.
  
      Parameters
      ----------
      values : array_like, shape(N,)
          Input cash flows per time period.  By convention, net "deposits"
          are negative and net "withdrawals" are positive.  Thus, for
          example, at least the first element of `values`, which represents
          the initial investment, will typically be negative.
  
      Returns
      -------
      out : float
          Internal Rate of Return for periodic input values.
  
      Notes
      -----
      The IRR is perhaps best understood through an example (illustrated
      using np.irr in the Examples section below).  Suppose one invests 100
      units and then makes the following withdrawals at regular (fixed)
      intervals: 39, 59, 55, 20.  Assuming the ending value is 0, one's 100
      unit investment yields 173 units; however, due to the combination of
      compounding and the periodic withdrawals, the "average" rate of return
      is neither simply 0.73/4 nor (1.73)^0.25-1.  Rather, it is the solution
      (for :math:`r`) of the equation:
  
      .. math:: -100 + \\frac{39}{1+r} + \\frac{59}{(1+r)^2}
       + \\frac{55}{(1+r)^3} + \\frac{20}{(1+r)^4} = 0
  
      In general, for `values` :math:`= [v_0, v_1, ... v_M]`,
      irr is the solution of the equation: [2]_
  
      .. math:: \\sum_{t=0}^M{\\frac{v_t}{(1+irr)^{t}}} = 0
  
      References
      ----------
      .. [1] NumPy Enhancement Proposal (NEP) 32,
         https://numpy.org/neps/nep-0032-remove-financial-functions.html
      .. [2] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
         Addison-Wesley, 2003, pg. 348.
  
      Examples
      --------
      >>> round(np.irr([-100, 39, 59, 55, 20]), 5)
      0.28095
      >>> round(np.irr([-100, 0, 0, 74]), 5)
      -0.0955
      >>> round(np.irr([-100, 100, 0, -7]), 5)
      -0.0833
      >>> round(np.irr([-100, 100, 0, 7]), 5)
      0.06206
      >>> round(np.irr([-5, 10.5, 1, -8, 1]), 5)
      0.0886
  
      """
      # `np.roots` call is why this function does not support Decimal type.
      #
      # Ultimately Decimal support needs to be added to np.roots, which has
      # greater implications on the entire linear algebra module and how it does
      # eigenvalue computations.
      res = np.roots(values[::-1])
      mask = (res.imag == 0) & (res.real > 0)
      if not mask.any():
          return np.nan
      res = res[mask].real
      # NPV(rate) = 0 can have more than one solution so we return
      # only the solution closest to zero.
      rate = 1/res - 1
      rate = rate.item(np.argmin(np.abs(rate)))
      return rate
function_tokens: def irr ( values ) : # `np.roots` call is why this function does not support Decimal type. # # Ultimately Decimal support needs to be added to np.roots, which has # greater implications on the entire linear algebra module and how it does # eigenvalue computations. res = np . roots ( values [ : : - 1 ] ) mask = ( res . imag == 0 ) & ( res . real > 0 ) if not mask . any ( ) : return np . nan res = res [ mask ] . real # NPV(rate) = 0 can have more than one solution so we return # only the solution closest to zero. rate = 1 / res - 1 rate = rate . item ( np . argmin ( np . abs ( rate ) ) ) return rate