Cash Flow Calculator (NPV, IRR, XIRR, Bonds) API
NPV, IRR (all roots), MIRR, XNPV / XIRR, payback, B/C ratio and sensitivity for a cash-flow series, plus bond price ↔ yield and duration, matching Excel.
Send cashflows (the investment as a negative number first, e.g. [-10000, 3000, 4200, 6800], or objects { "date", "amount" } for dated flows) and a discount rate (10, "10%" or 0.1; or one rate per period). The answer gives NPV (first flow at t = 0) and excel_npv (Excel's NPV over all flows), IRR (every root when the flows change sign several times, with a warning), MIRR with finance_rate / reinvest_rate, simple and discounted payback, present values of inflows and outflows, benefit / cost ratio, profitability index and a sensitivity table of NPV when inflows and outflows move by ±x%. Dated flows give XNPV / XIRR (actual days / 365 like Excel) and the payback date. Optional break-even from fixed costs, unit price and unit variable cost.
type=bond prices a bond from its yield or solves the yield from a clean price (Excel PRICE / YIELD conventions, day-count basis 0–4, annual / semi-annual / quarterly coupons) and returns accrued interest, dirty price, coupon dates and Macaulay / modified duration. Results reproduce the examples in the Excel documentation (NPV 1,188.44; IRR 8.66%; XIRR 37.34%; MIRR 12.61%; PRICE 94.6344).
format=xlsx returns a workbook with live Excel formulas (NPV, IRR, MIRR, XIRR, XNPV) so you can check the numbers. Up to 10,000 flows.
Markdown · OpenAPI · Postman · llms.txt
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
cashflows | body | array | no | Numbers per period (first = t 0) or { date, amount } objects. Required unless inflows / outflows or type=bond. | |
rate | body | number | no | Discount rate (10, "10%" or 0.1) or an array, one per period. | |
finance_rate | body | number | no | MIRR finance rate (default = rate). | |
reinvest_rate | body | number | no | MIRR reinvestment rate (default = rate). | |
inflows | body | array | no | Inflows per period (with outflows), for B/C and sensitivity on each side. | |
outflows | body | array | no | Outflows per period (positive numbers). | |
sensitivity | body | array | no | Percent steps (default [-20, -10, 0, 10, 20]). | |
guess | body | number | no | IRR / XIRR picked closest to this rate when several exist (default 10%). | |
type | body | string | no | project | project or bond. |
settlement | body | string | no | Bond: settlement date. | |
maturity | body | string | no | Bond: maturity date. | |
coupon_rate | body | number | no | Bond: annual coupon rate. | |
yield | body | number | no | Bond: yield to maturity (to get the price). | |
price | body | number | no | Bond: clean price per 100 (to get the yield). | |
frequency | body | number | no | 1 | Bond: coupons per year (1, 2, 4, 12). |
basis | body | number | no | 0 | Bond: Excel day-count basis 0–4. |
format | body | string | no | json | json or xlsx (projects). |
Example
curl -X POST "https://apibox.io.vn/v1/cashflow-calc" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cashflows":[-10000,3000,4200,6800],"rate":10,"finance_rate":10,"reinvest_rate":12}'const res = await fetch('https://apibox.io.vn/v1/cashflow-calc', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"cashflows": [
-10000,
3000,
4200,
6800
],
"rate": 10,
"finance_rate": 10,
"reinvest_rate": 12
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/cashflow-calc",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"cashflows": [-10000, 3000, 4200, 6800], "rate": 10, "finance_rate": 10, "reinvest_rate": 12},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/cashflow-calc');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"cashflows":[-10000,3000,4200,6800],"rate":10,"finance_rate":10,"reinvest_rate":12}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"type": "project",
"flows": 4,
"total_inflows": 14000,
"total_outflows": -10000,
"net": 4000,
"irr": 0.1634056007,
"irr_percent": 16.34056,
"payback_periods": 2.411764705882353,
"rate": 0.1,
"npv": 1307.287754,
"excel_npv": 1188.443412,
"discounted_payback_periods": 2.7441176470588236,
"pv_inflows": 11307.287754,
"pv_outflows": 10000,
"benefit_cost_ratio": 1.130729,
"profitability_index": 1.130729,
"decision": "accept (NPV > 0)",
"mirr": 0.15147133664676304,
"mirr_percent": 15.147134,
"finance_rate": 0.1,
"reinvest_rate": 0.12,
"notes": []
}
Use cases
- Appraise an investment project (NPV, IRR, payback) in a bank or consulting workflow
- Compute XIRR of an irregular investment or rental property
- Price a corporate or government bond and its yield to maturity
- Teach or check finance homework against Excel
FAQ
Why does NPV differ from Excel's NPV()?
Excel's NPV discounts the first value by one period. This API treats the first flow as t = 0 (the usual textbook NPV) and also returns excel_npv for comparison.
What if there are several IRRs?
When the flows change sign more than once, all roots are returned in irr_all with a warning; use NPV or MIRR to decide.
Which day count does the bond calculation use?
Excel's basis codes: 0 US 30/360 (default), 1 actual/actual, 2 actual/360, 3 actual/365, 4 European 30/360.
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.