curatedapi
Browse the docs

Guides

Finance

Excel functions

Late payments

E-invoices

Accounting

Number checks

VAT and GST

Billing and pricing

Money and currencies

Dates and time

Math

Unit conversion

Everyday

Health

Excel MDURATION function: modified duration of a bond API

The modified Macaulay duration of a bond with periodic coupons, as Excel's MDURATION: the percentage change in price for a change in yield.

POST https://api.curatedapi.com/v1/calc/excel/mduration

MDURATION(settlement, maturity, coupon, yld, frequency, [basis]): the modified duration for an assumed par value of 100, which is DURATION divided by 1 + yld/frequency. A modified duration of 5.7 means the price falls by about 5.7% when the yield rises by one percentage point.

Formula

DURATION(settlement, maturity, coupon, yld, frequency, basis) ÷ (1 + yld/frequency)
  • Between coupon dates, the time to each coupon is counted as in PRICE: the days from settlement to the next coupon divided by the days in the coupon period, plus whole periods. Microsoft does not publish this detail. On a coupon date it is the textbook formula and gives Microsoft's documented examples exactly.
  • Arguments are named and ordered as in Excel. Excel computes in binary floating point; this API computes the exact value of the same formula and rounds it once, so it agrees with Excel to the digits Excel can show, and where Excel's own rounding error reaches the 15th digit this answer is the correct one.
  • Dates are ISO 8601 (YYYY-MM-DD) from 1900-03-01 to 9999-12-31, so Excel's fictional 29 February 1900 never comes into play. Each date result also gives Excel's serial number (1900 date system).

Inputs

Send numbers as strings to keep every digit. options sets precision and rounding (see numbers and rounding).

InputTypeDescription
settlement required date (YYYY-MM-DD) Settlement date (when the buyer gets the bond).
maturity required date (YYYY-MM-DD) Maturity date.
coupon required decimal (string) Annual coupon rate as a decimal. A ratio of two decimals such as "0.08/12" is accepted. Allowed: >= 0 and <= 100.
yld required decimal (string) Annual yield as a decimal. A ratio of two decimals such as "0.08/12" is accepted. Allowed: >= 0 and <= 100.
frequency required integer Coupons per year: 1, 2 or 4. Allowed: >= 1 and <= 4.
basis integer
default 0
Day count basis: 0 US (NASD) 30/360; 1 Actual/actual; 2 Actual/360; 3 Actual/365; 4 European 30/360. Allowed: >= 0 and <= 4.
options.rounding half_even | half_up | half_down | up | down | ceiling | floor Rounding mode applied once to each result. Default half_even.
options.decimals integer Round results to this many digits after the decimal point.
options.significant_digits integer Round results to this many significant digits.

Result

Under result in the answer, next to exactness, precision, inputs, formula, references and warnings.

ResultTypeDescription
mdurationdecimal (string)Modified duration in years.
coupons_remainingintegerCoupons from settlement to maturity (N).

Examples

Microsoft's example: 8% coupon, 9% yield, 2008 to 2016, actual/actual

Requestcurl
curl https://api.curatedapi.com/v1/calc/excel/mduration \
  -H "Authorization: Bearer $CURATEDAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "settlement": "2008-01-01",
    "maturity": "2016-01-01",
    "coupon": "0.08",
    "yld": "0.09",
    "frequency": 2,
    "basis": 1,
    "options": {"decimals": 3}
  }'
200 OKResponse
{
  "calculator": "excel/mduration@1",
  "result": {
    "mduration": "5.736",
    "coupons_remaining": 16
  },
  "exactness": {
    "mduration": "rounded"
  },
  "precision": {
    "rounding": "half_even",
    "decimals": 3
  },
  "inputs": {
    "settlement": "2008-01-01",
    "maturity": "2016-01-01",
    "coupon": "0.08",
    "yld": "0.09",
    "frequency": 2,
    "basis": 1
  },
  "formula": "DURATION(settlement, maturity, coupon, yld, frequency, basis) ÷ (1 + yld/frequency)",
  "references": [
    {
      "title": "Microsoft Excel MDURATION function",
      "url": "https://support.microsoft.com/en-us/excel/functions/mduration-function"
    }
  ],
  "warnings": []
}

References

Results follow each calculator's documented rules and the sources listed. They are not financial, tax or legal advice. Check that the rules fit your case before you rely on a result. See the terms.

Errors share one format; see errors. Billing, retries and batches work the same for every endpoint.