Class Irr
- 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:
- Wikipedia on IRR, Excel IRR
-
-
Constructor Summary
Constructors Constructor Description Irr()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ValueEval
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 using the Newton-Raphson Method.
-
-
-
Method Detail
-
evaluate
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
- Specified by:
evaluate
in interfaceFunction
- Parameters:
args
- the evaluated function arguments. Empty values are represented withBlankEval
orMissingArgEval
, nevernull
.srcRowIndex
- row index of the cell containing the formula under evaluationsrcColumnIndex
- column index of the cell containing the formula under evaluation- Returns:
- The evaluated result, possibly an
ErrorEval
, nevernull
. Note - Excel uses the error code #NUM! instead of IEEE NaN, so when numeric functions evaluate toDouble.NaN
be sure to translate the result toErrorEval.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 using the Newton-Raphson Method.Starting with the guess, the method cycles through the calculation until the result is accurate within 0.00001 percent. If IRR can't find a result that works after 1000 tries, the
Double.NaN
is returned.The implementation is inspired by the NewtonSolver from the Apache Commons-Math library,
- Parameters:
values
- the income values.guess
- the initial guess of irr.- Returns:
- the irr value. The method returns
Double.NaN
if the maximum iteration count is exceeded - See Also:
- http://commons.apache.org, http://en.wikipedia.org/wiki/Internal_rate_of_return#Numerical_solution, http://en.wikipedia.org/wiki/Newton%27s_method
-
-