# XIRR calculator

> Compute the Extended Internal Rate of Return (XIRR) for irregular series of dated cash flows.

Live HTML: https://plaintools.io/finance/xirr-calculator

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

You have a series of investments and returns on specific calendar dates and need the annualized internal rate of return.

## When not to

Periodic annuities with identical intervals (use standard IRR instead); cash flows with all positive or all negative signs.

## Inputs

- **cashFlows:** Array of items with ISO date (YYYY-MM-DD) and non-zero amount. Negative for investments/outflows, positive for returns/inflows.

## Outputs

- **rateFormatted:** Annualized XIRR as formatted percentage (e.g. +14.25%).
- **totalInvested:** Sum of negative cash flows.
- **totalReturned:** Sum of positive cash flows.
- **netProfit:** totalReturned - totalInvested.
- **durationDays:** Calendar days between first and last cash flow.

## Steps

1. Validate at least two cash flows, at least one negative flow, and at least one positive flow.
2. Sort cash flows by date ascending. Compute yearsFromStart = (timestamp_i - timestamp_0) / (365 * 86400000).
3. Define Net Present Value NPV(r) = sum(amount_i / (1 + r)^yearsFromStart_i) and derivative dNPV(r).
4. Find root r where NPV(r) = 0 using Newton-Raphson starting at r = 0.10.
5. If Newton-Raphson does not converge within 60 iterations, fall back to bracketed search and bisection across r in [-0.999, 100].
6. Format annualized rate as percentage (rate * 100) with two decimal places.

## FAQs

### What is XIRR and how does it differ from regular IRR?

Standard IRR assumes cash flows occur at equal, periodic intervals (such as every month or every year). XIRR (Extended Internal Rate of Return) accounts for exact calendar dates and calculates the true annualized rate of return across irregular investment contributions, capital calls, dividends, and distributions.

### Why do some cash flows need to be negative and others positive?

Cash flows represent money entering or leaving your pocket. Negative numbers represent cash outflows (money you invested, purchase price, or capital additions). Positive numbers represent cash inflows (dividends received, cash distributions, or current portfolio valuation at exit).

### How does this calculator solve for XIRR in the browser?

The calculator calculates the discount rate r where Net Present Value (NPV) equals zero. It uses the Newton-Raphson iterative algorithm. If the derivative vanishes or oscillations occur, it automatically falls back to a bracketed bisection search.

### What causes an XIRR calculation to show an error?

XIRR requires at least two cash flows spanning at least two different calendar days. There must be at least one negative amount (investment) and at least one positive amount (return/valuation). If all numbers share the same sign, NPV can never cross zero and no rate of return exists.

### Can I use this for SIPs, mutual funds, and stock portfolios?

Yes. Enter each purchase date with a negative amount and your current portfolio value as of today's date as a positive amount. The resulting percentage is your annualized return (CAGR adjusted for cash flow timing).

### How is XIRR calculated without this page?

Given cash flows (d_i, C_i) for i = 0..n-1, let t_i = (d_i − d_0) / 365. Find rate r > −1 such that NPV(r) = sum(C_i / (1 + r)^t_i) = 0. Compute derivative dNPV(r) = sum(−t_i × C_i / (1 + r)^(t_i + 1)). Start with initial guess r_0 = 0.10. Iterate r_{k+1} = r_k − NPV(r_k) / dNPV(r_k) until |NPV(r)| < 1e-7. If Newton diverges, find bracket [a, b] where NPV(a) × NPV(b) ≤ 0 and bisect.

## Related tools

- [Seller financing calculator](https://plaintools.io/finance/seller-financing-calculator.md) — HTML: https://plaintools.io/finance/seller-financing-calculator
- [Owner financing calculator](https://plaintools.io/finance/owner-financing-calculator.md) — HTML: https://plaintools.io/finance/owner-financing-calculator
- [Pool financing calculator](https://plaintools.io/finance/pool-financing-calculator.md) — HTML: https://plaintools.io/finance/pool-financing-calculator
- [Break-even calculator](https://plaintools.io/finance/break-even-calculator.md) — HTML: https://plaintools.io/finance/break-even-calculator
- [Retirement corpus calculator](https://plaintools.io/finance/retirement-corpus-calculator.md) — HTML: https://plaintools.io/finance/retirement-corpus-calculator
- [GST calculator](https://plaintools.io/finance/gst-calculator.md) — HTML: https://plaintools.io/finance/gst-calculator
