Files
gridcraft/docs
Harrison BoothandClaude Opus 5.5 8d90b1ea03 fix(functions): XIRR and IRR follow Excel's solvers
XIRR returned the exact root (Newton with fallbacks and a bracketing
search), so it differed from Excel at about 1e-8 and converged where Excel
gives #NUM!. It now follows Excel's solver as reconstructed by observing
Excel with synthetic inputs: a sign-only search that brackets the root from
the guess (doubling; bisecting towards 0, halving towards 0 or stepping
halfway to -100% when the root is lower), then bisection with the midpoint
taken from the upper end, stopping when half the bracket is under
1e-8 * (|rate| + 0.5) and |XNPV| is under 2e-8 * |first value|, at most 100
XNPV evaluations. Dates before the first are allowed as in Excel; a guess at
or below -1 is #NUM!. Answers match Excel bit for bit in 888 of 910
synthetic cases with an answer; 97.7% agreement on 1,283 cases.

IRR now uses Newton on the discount factor 1/(1+rate), at most 100 steps,
stopping at a step under 1e-8, which agrees with Excel's #NUM! cases far
better (IRR of -100, 19 zeros, 1E-5 is #NUM!) and with its values to about
1e-12. A guess at or below -1 is #VALUE! like Excel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 00:07:34 -05:00
..
2026-10-13 00:09:07 -04:00