Cashflow mirr
cashflow-mirr · version 1.0.0 · Financial calculations · free, no key needed
MIRR of periodic cash flows from a finance rate and a reinvestment rate, with compounded and discounted totals.
Use when you need to: modified internal rate of return · MIRR with finance rate and reinvestment rate · Excel MIRR function equivalent.
Decide before calling
Read the versioned contract and the supported scope below. Reuse cashflow-mirr@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use cashflow-mirr@1.0.0 for modified internal rate of return. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- modified internal rate of return
- MIRR with finance rate and reinvestment rate
- Excel MIRR function equivalent
- MIRR calculator for a project
- internal rate of return with a reinvestment assumption
- future value of positive flows over present value of negative flows
- return when cash is reinvested at a different rate
- MIRR of cash flows with several sign changes
Not supported
- ordinary IRR by root finding (use cashflow-irr)
- dated cash flows (use cashflow-xirr)
- a single rate used for both finance and reinvestment by default
- NPV or payback of the flows (use cashflow-npv or cashflow-payback-period)
Behavior
- Inputs: cash_flows (array of 2 to 2000 decimal strings in time order, first flow at time 0, one period apart; positive is money received, negative is money paid), finance_rate (the periodic rate paid on negative flows, decimal greater than -1 and at most 100), reinvest_rate (the periodic rate earned on reinvested positive flows, same range), scale (0 to 12, default 2, for fv_positive and pv_negative), rate_scale (0 to 12, default 10, for mirr) and rounding (default half-up). Both rates are required: there is no default and they are never assumed equal.
- With n the number of flows and k = 0 .. n-1 the index of a flow: fv_positive = sum over the positive flows of cash_flow_k * (1+reinvest_rate)^(n-1-k), that is the positive flows compounded forward to the LAST period (index n-1); pv_negative = sum over the negative flows of cash_flow_k / (1+finance_rate)^k, that is the negative flows discounted back to time 0 (a value at most 0). Zero flows contribute nothing.
- MIRR = (fv_positive / (-pv_negative))^(1/(n-1)) - 1. The exponent uses n-1 (the number of periods between the first and the last flow), not n. This is Excel MIRR and equals (NPV(reinvest, positives) * (1+reinvest)^n / (NPV(finance, negatives) * (1+finance)))^(1/(n-1)) - 1 with Excel's t1 NPV.
- If there is no positive flow or no negative flow the result is not_computable (details.reason needs_both_signs). If fv_positive or the magnitude of pv_negative reaches 1e20, or the MIRR magnitude reaches 1e20, the result is not_computable (details.reason overflow).
- Exact path: every sum is computed in exact decimal arithmetic with an absolute error below 1e-33 and the quantities fv_positive, pv_negative and mirr are each first rounded half-even to 30 fractional digits, so a result that is mathematically an exact decimal (for example a MIRR of exactly 0.1) is recovered exactly and is not disturbed by directed rounding; they are then rounded once to scale or rate_scale with the rounding mode. The MIRR ratio itself is formed from the unsnapped sums (relative accuracy about 1e-80, however small or large the sums are, so a rate near -1 over thousands of periods still gives its finite MIRR). mirr is greater than -1.
- More than 2000 cash flows, or a decimal string longer than 64 UTF-8 bytes, is limit_exceeded, checked before parsing. Percent values are not accepted: 0.08 means 8 percent per period.
- Every rounded output is rounded exactly once from the unrounded value using the rounding mode: half-up (ties away from zero, the default), half-even, half-down (ties toward zero), up (away from zero), down (toward zero), ceiling, floor. Amount outputs print exactly scale fractional digits and rate-like outputs exactly rate_scale fractional digits; a result that rounds to zero prints without a minus sign (never '-0.00').
- Decimal string fields (amounts, rates) must match ^-?(0|[1-9][0-9]*)(\.[0-9]+)?$ with at most 20 integer digits and at most 20 fractional digits; a JSON number, exponent form, leading plus, surrounding spaces, percent sign, missing integer part or trailing dot is invalid_input. Rates are decimal fractions (0.065 means 6.5 percent; "6.5" means 650 percent). A decimal string longer than 64 UTF-8 bytes is limit_exceeded, checked before parsing.
- Disclaimer: arithmetic calculation only; not financial, tax, legal, or investment advice.
Input
cash_flows(array of string, required): min items 2; max items 2000; each max length 64; each pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$finance_rate(string, required): max length 64; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$reinvest_rate(string, required): max length 64; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$scale(integer, optional): min 0; max 12rate_scale(integer, optional): min 0; max 12rounding(one of "half-up", "half-even", "half-down", "up", "down", "ceiling", "floor", optional)
Output
mirr(string, required): max length 64; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$fv_positive(string, required): max length 64; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$pv_negative(string, required): max length 64; pattern^-?(0|[1-9][0-9]*)(\.[0-9]+)?$
Limits
- max items: 2000
- max string bytes: 64
Example
Request input:
{
"cash_flows": [
"-120000",
"39000",
"30000",
"21000",
"37000",
"46000"
],
"finance_rate": "0.10",
"reinvest_rate": "0.12",
"rate_scale": 4
}
Response:
{
"result": {
"mirr": "0.1261",
"fv_positive": "217297.50",
"pv_negative": "-120000.00"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "cashflow-mirr",
"version": "1.0.0",
"input": {
"cash_flows": [
"-120000",
"39000",
"30000",
"21000",
"37000",
"46000"
],
"finance_rate": "0.10",
"reinvest_rate": "0.12",
"rate_scale": 4
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/cashflow-mirr/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"cash_flows":["-120000","39000","30000","21000","37000","46000"],"finance_rate":"0.10","reinvest_rate":"0.12","rate_scale":4}'
The machine-readable contract is at /v1/tools/cashflow-mirr/versions/1.0.0.
CLI
node cli.mjs run cashflow-mirr 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Cashflow npv: NPV of equally spaced cash flows, time-0 or Excel time-1, with inflow PV, outflow PV and profitability index.
- Cashflow irr: IRR of equally spaced cash flows with every root reported, the chosen root named and no-solution cases signalled.
- Cashflow xnpv: NPV of dated cash flows with the Excel XNPV 365-day exponent and an explicit valuation date.
- Cashflow xirr: Annual IRR of dated cash flows on the Excel XIRR 365-day basis, with all roots and the chosen root reported.
- Cashflow payback period: Payback period of periodic cash flows with linear interpolation, optional discounting and the cumulative path.
- Growth cagr compute: CAGR from start and end values or a total return over years or dates, with a sub-year warning.