java.lang.Object
org.apache.poi.ss.formula.functions.Irr
All Implemented Interfaces:
Function

public final class Irr extends Object implements Function
Calculates the internal rate of return. Syntax is IRR(values) or IRR(values,guess)
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Irr()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
     
    static double
    irr(double[] income)
    Computes the internal rate of return using an estimated irr of 10 percent.
    static double
    irr(double[] values, double guess)
    Calculates IRR in two stages.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Irr

      public Irr()
  • Method Details

    • evaluate

      public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
      Specified by:
      evaluate in interface Function
      Parameters:
      args - the evaluated function arguments. Empty values are represented with BlankEval or MissingArgEval, never null.
      srcRowIndex - row index of the cell containing the formula under evaluation
      srcColumnIndex - column index of the cell containing the formula under evaluation
      Returns:
      The evaluated result, possibly an ErrorEval, never null. Note - Excel uses the error code #NUM! instead of IEEE NaN, so when numeric functions evaluate to Double.NaN be sure to translate the result to ErrorEval.NUM_ERROR.
    • irr

      public static double irr(double[] income)
      Computes the internal rate of return using an estimated irr of 10 percent.
      Parameters:
      income - the income values.
      Returns:
      the irr.
    • irr

      public static double irr(double[] values, double guess)
      Calculates IRR in two stages. First, plain Newton-Raphson from the guess; for compatibility this is exactly the historical algorithm, so every cash flow it already solved keeps its bit-identical result. If it fails to converge (as in bug #64137, where the iteration overshoots to a rate just above -100% and cannot recover) or converges to a meaningless rate at or below -100%, the method falls back to a bracketed Newton-Raphson (the classic "rtsafe" safeguard): the NPV function is bracketed between two rates of opposite NPV sign, then Newton-Raphson steps are taken as long as they stay inside the bracket and converge fast enough, with bisection otherwise. The fallback cannot diverge and cannot return a rate at or below -100%.
      Parameters:
      values - the income values.
      guess - the initial guess of irr.
      Returns:
      the irr value. The method returns Double.NaN if no rate with zero NPV could be found
      See Also: