The XIRR Formula

XIRR is the rate r that makes the net present value of all cash flows equal to zero. Here's the math.

The equation

Σ  Pᵢ / (1 + r)^((dᵢ - d₀) / 365)  =  0

where:
  Pᵢ   = cash flow i (negative for investments, positive for receipts)
  dᵢ   = date of cash flow i
  d₀   = date of the first cash flow
  r    = annualised rate (what we're solving for)

Solving for r

There's no closed-form solution — it's a polynomial in r of arbitrary degree. Excel and our calculator use Newton-Raphson iteration:

rₙ₊₁ = rₙ - f(rₙ) / f'(rₙ)

Starting from a guess (commonly 10%), we iterate until |f(r)| < tolerance. If Newton's method fails to converge — usually due to extreme returns or ill-conditioned cash flows — we fall back to bisection, which is slower but guaranteed to converge if a root exists.

Why 365 days?

XIRR uses a 365-day year convention (actual/365). This is the Excel-compatible standard and avoids the complications of leap years and day-count quirks. The difference vs actual/actual is <0.001% in practice.

Implementation in JavaScript

function xnpv(rate, flows) {
  const t0 = flows[0].date.getTime();
  return flows.reduce((sum, f) => {
    const years = (f.date.getTime() - t0) / (1000 * 60 * 60 * 24 * 365);
    return sum + f.amount / Math.pow(1 + rate, years);
  }, 0);
}

function xirr(flows, guess = 0.1) {
  let r = guess;
  for (let i = 0; i < 100; i++) {
    const f  = xnpv(r, flows);
    const df = dxnpv(r, flows);
    const next = r - f / df;
    if (Math.abs(next - r) < 1e-7) return next;
    r = next;
  }
}

Our open implementation lives in src/lib/xirr.ts. It matches Excel to ≥4 decimal places on every test case we've tried.

Ready to run the formula? Open the XIRR calculator.

XIRR Formula — FAQs

Everything investors usually ask about XIRR, SIPs and return calculations.

Related Tools

Free calculators built for serious investors.