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.

POSTGEThttps://apibox.io.vn/v1/cashflow-calc

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

NameInTypeRequiredDefault
cashflowsbodyarraynoNumbers per period (first = t 0) or { date, amount } objects. Required unless inflows / outflows or type=bond.
ratebodynumbernoDiscount rate (10, "10%" or 0.1) or an array, one per period.
finance_ratebodynumbernoMIRR finance rate (default = rate).
reinvest_ratebodynumbernoMIRR reinvestment rate (default = rate).
inflowsbodyarraynoInflows per period (with outflows), for B/C and sensitivity on each side.
outflowsbodyarraynoOutflows per period (positive numbers).
sensitivitybodyarraynoPercent steps (default [-20, -10, 0, 10, 20]).
guessbodynumbernoIRR / XIRR picked closest to this rate when several exist (default 10%).
typebodystringnoprojectproject or bond.
settlementbodystringnoBond: settlement date.
maturitybodystringnoBond: maturity date.
coupon_ratebodynumbernoBond: annual coupon rate.
yieldbodynumbernoBond: yield to maturity (to get the price).
pricebodynumbernoBond: clean price per 100 (to get the yield).
frequencybodynumberno1Bond: coupons per year (1, 2, 4, 12).
basisbodynumberno0Bond: Excel day-count basis 0–4.
formatbodystringnojsonjson 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}'

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

Start with 1,000 free requests every month. Get free API key →