{
  "category": "Financial functions",
  "display_name": "DURATION",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.DURATION",
  "implementation_state": {
    "answer_bank": {
      "excel_builds": [
        "20131",
        "20228",
        "?"
      ],
      "larger_numeric": 0,
      "last_bit": 333,
      "matched": 7551,
      "other_mismatch": 0,
      "refused": 0,
      "rows": 7884,
      "unread": 0,
      "worst_ulp": 3
    },
    "detail": "Everything else matches (7,884 in the answer bank and 6 workbook cells). Last-bit means a finite number within 16 ULP of Excel's.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "close",
    "state_label": "Close: last-bit deviations remain",
    "summary": "Close: 335 of 7,890 recorded answers differ in the last bits, worst 3 ULP",
    "workbook_corpus": {
      "cells": 6,
      "last_bit": 2,
      "matched": 4,
      "worst_ulp": 1
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/bonds.rs#L137-L140"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/bonds::or",
        "catalogue/bonds::bond_out",
        "catalogue/financial::date_1900",
        "locale::days_from_civil",
        "locale::civil_from_days",
        "locale::excel_serial_from_ymd",
        "locale::ymd_from_excel_serial",
        "ported/bond_core_family::max_serial",
        "ported/bond_core_family::derr",
        "ported/bond_core_family::dyear",
        "ported/bond_core_family::dim",
        "ported/bond_core_family::act",
        "ported/bond_core_family::basis",
        "ported/bond_core_family::freq",
        "ported/bond_core_family::dser",
        "ported/bond_core_family::rate",
        "ported/bond_core_family::addm",
        "ported/bond_core_family::d360eu",
        "ported/bond_core_family::dc",
        "ported/bond_core_family::ctx",
        "ported/bond_core_family::period",
        "ported/bond_core_family::excel_bond_pow",
        "ported/bond_core_family::duration_kernel",
        "ported/bond_core_family::last_day_of_feb",
        "ported/bond_core_family::diff360_us",
        "ported/bond_core_family::days_between_num",
        "ported/bond_core_family::map_bond_core_error_to_ws",
        "ported/excel_numeric::binary_with",
        "ported/excel_numeric::excel_pow_chain",
        "ported/excel_numeric::excel_x87_mul",
        "ported/excel_numeric/x87::mul",
        "ported/excel_numeric/x87_chains::pow2_positive",
        "ported/excel_numeric/x87_chains::pow2",
        "ported/excel_numeric/x87_chains::exp_ext",
        "ported/excel_numeric/x87_chains::exp_with",
        "ported/excel_numeric/x87_chains::excel_exp",
        "ported/excel_numeric/x87_chains::log_with",
        "ported/excel_numeric/x87_chains::excel_log"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/bonds.rs#L137-L140",
      "state": "close",
      "suite": null,
      "summary": "Close: 335 of 7,890 recorded answers differ in the last bits, worst 3 ULP"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.DURATION.json",
  "name": "DURATION",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n- **[MDURATION](FUNC.MDURATION.md)** — modified duration, defined as `DURATION/(1 + yld/frequency)`.\n  Same arguments, same errors, one extra division. If you want a price-sensitivity number, that is\n  the one.\n- **`PRICE`** — the denominator of the duration quotient *is* the dirty price. The two functions\n  share their coupon schedule, their day counts and their discount ladder, so a `DURATION`\n  discrepancy and a `PRICE` discrepancy on the same bond are usually the same bug seen twice.\n- **`YIELD`** — the inverse of `PRICE`, and the usual source of the `yld` argument. Note the loop:\n  compute `yld` from a market price with `YIELD`, feed it to `DURATION`, and any day-count\n  disagreement enters twice.\n- **`COUPNUM` / `COUPDAYBS` / `COUPDAYS` / `COUPDAYSNC`** — the schedule quantities `DURATION`\n  computes internally. They are the right instruments for localizing a disagreement: if `COUPDAYBS`\n  differs, the duration will differ, and you have found the day count rather than the discounting.\n- **`ACCRINT`** — accrued interest, which uses the same accrual span as the fractional offset.\n- **Confused with**: the everyday sense of \"duration\" as time to maturity. For a coupon bond\n  duration is always *less* than time to maturity, and a reader who expects the two to match will\n  read every answer as wrong.\n- There is **no convexity function** in Excel. The second-order term has to be built by hand.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n`DURATION` is a short sum of well-scaled terms, and the numerator and denominator are both positive\nand of similar magnitude, so the reduction itself is benign — no cancellation, no overflow for any\nrealistic bond. The difficulty is entirely in the *schedule* and in the *discount factor*.\n\n**The schedule is integer calendar arithmetic and is unforgiving.** Coupon dates are generated by\nmonth arithmetic backwards from maturity, with an end-of-month rule: a bond maturing on 31 August\npays on 28/29 February, and a naive \"same day number\" step lands on the wrong date. Every discount\nexponent depends on that schedule, so a single mis-stepped coupon date moves the answer far beyond\nany rounding concern.\n\n**The discount factor is a `pow`, and `pow` is not one function.** The exponents are integers when\nsettlement falls exactly on a coupon date and fractional otherwise. Integer exponents can be\nevaluated by binary exponentiation (square-and-multiply on plain multiplies) or by `exp(y·ln x)`,\nand the two differ in the last bits. Fractional exponents can be evaluated through a modern\ncorrectly-rounded `pow` or through a legacy `exp(ln)` chain, and those differ too. The reference\nengine deliberately implements both staging cases and documents that it selects them to match\nobserved Excel behaviour. The Handbook does **not** assert what Excel does internally; what it can\nsay is that this is the axis on which careful implementations of bond math disagree, and that any\nclaim of agreement that has not distinguished on-coupon from off-coupon settlement has not tested\nthe interesting half.\n\nFor the underlying mathematics, Macaulay's weighted-average-time construction and the\n`dP/dy = −D_mod·P` link are standard; any fixed-income text develops them, and the discrete-schedule\nform used by spreadsheet functions is the one in the market conventions literature rather than in\nthe continuous-time treatment.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number` — a duration in **years**, not in periods and not in days.\n\n- **`settlement ≥ maturity`** is a domain error, not a zero or negative duration.\n- **Zero coupon** is admissible (`coupon = 0`) and gives time to maturity in years.\n- **Zero yield** is admissible and makes every discount factor 1, so `D` becomes the simple\n  cash-flow-weighted average time.\n- **Non-integer `frequency` and `basis`** are truncated toward zero before the range check, so\n  `frequency = 2.9` reads as `2`.\n- Empty, missing and error arguments follow the shared call model; see\n  [The value universe](../model/01-value-universe.md) and\n  [Coercion and lifting](../model/02-coercion-and-lifting.md).\n\n\n\n### Errors\n\n\nAs documented on Microsoft's `DURATION` page:\n\n| Error | Condition |\n|---|---|\n| `#VALUE!` | `settlement` or `maturity` is not a valid serial date number |\n| `#NUM!` | `coupon < 0` or `yld < 0` |\n| `#NUM!` | `frequency` is any number other than 1, 2 or 4 |\n| `#NUM!` | `basis < 0` or `basis > 4` |\n| `#NUM!` | `settlement ≥ maturity` |\n\n",
    "sources": "- Microsoft, \"DURATION function\" —\n  <https://support.microsoft.com/en-us/office/duration-function-b254ea57-eadc-4602-a86a-c8e369334038>\n  (syntax, argument meanings, the frequency values, the day-count basis table, the truncation\n  remarks, and the documented `#VALUE!` and `#NUM!` conditions).\n- Handbook, [MDURATION](FUNC.MDURATION.md) — the modified-duration sibling and the exact relation.\n- Handbook, [The value universe](../model/01-value-universe.md) and\n  [Coercion and lifting](../model/02-coercion-and-lifting.md).\n- Handbook projections `data/functions/FUNC.DURATION.json` and `data/presence/FUNC.DURATION.json`\n  (arity, classification axes, implementing module and the bond-family sibling set).\n\n",
    "version-differences": "The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.\n\n| Excel 16.0 build | Platform and CPU | Captured inputs |\n|---|---|---:|\n| 20131 | Windows, bitness not recorded, AMD Ryzen 7 4800H with Radeon Graphics | 7,620 |\n\nThe record contains no same-input comparison between these environments. Reading different inputs on different builds does not establish either a version change or cross-build agreement.\n\n[Recorded environments and comparison details](https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.DURATION.json).",
    "what-it-does": "\n`DURATION(settlement, maturity, coupon, yld, frequency, [basis])` returns the **Macaulay duration**\nof a coupon bond with an assumed par value of 100, expressed in **years**.\n\nMacaulay duration is the present-value-weighted average time to receipt of a security's cash flows:\n\n    D = ( Σ t_k · C_k · v^(t_k) ) / ( Σ C_k · v^(t_k) )        with  v = (1 + y/f)^(−f)\n\nwhere `t_k` is the time in years from settlement to cash flow `k`, `C_k` the cash flow (a coupon of\n`100·coupon/f`, plus 100 at maturity), `y` the annual yield and `f` the coupon frequency. The\ndenominator is the dirty price; the numerator is that price with each term weighted by its own\nmaturity. So **duration is a weighted mean of times, and it carries units of years** — that is the\nwhole content of the definition, and it is why a zero-coupon bond's duration is exactly its time to\nmaturity.\n\nTwo identities are worth holding on to:\n\n1. **Zero coupon.** With `coupon = 0` the only cash flow is the redemption, so `D` is the time to\n   maturity in years. This is the sanity check that catches most implementation errors.\n2. **The price-sensitivity link.** With `P(y)` the price,\n\n       dP/dy = −(D / (1 + y/f)) · P\n\n   which is why the *modified* duration `D/(1 + y/f)` — see [MDURATION](FUNC.MDURATION.md) — is the\n   number risk desks actually quote. Macaulay duration is the time; modified duration is the\n   sensitivity.\n\nBehaviour in the limits: `D` increases with maturity, decreases with coupon rate, and decreases\nwith yield. For a perpetual-style long bond `D` approaches `(1 + y/f)/y` from below rather than\ngrowing without bound, which is why a 30-year and a 100-year bond have far more similar durations\nthan their maturities suggest. As `y → −f` the discount base `1 + y/f` approaches zero and the\nexpression has a pole; the admissible domain excludes it (see Errors).\n\n### How Excel measures the time axis\n\nThe one place where a textbook formula and a spreadsheet function part company is the *time* axis.\nExcel does not measure `t_k` from settlement in calendar years. It works in **coupon periods**:\n\n- the coupon schedule is generated backwards from `maturity` at `12/frequency`-month steps until\n  the first date at or before `settlement`, giving `n` remaining coupons;\n- the settlement's position inside the current coupon period is expressed as a fraction, and the\n  exponent for the `k`-th remaining coupon is that fraction plus `k`;\n- the final quotient is divided by `frequency` to convert periods into years.\n\nThe fractional offset is the accrual measurement, and it depends on `basis`. This is why two calls\nthat differ only in `basis` can differ in the third decimal of the answer: the day count is not a\npresentational choice, it changes the exponent on every discount factor.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Default |\n|---|---|---|\n| `settlement` | The settlement date — when the security trades to the buyer. Required. | — |\n| `maturity` | The maturity date — when the security expires. Required. | — |\n| `coupon` | The security's **annual** coupon rate, as a decimal fraction. Required. | — |\n| `yld` | The security's **annual** yield, as a decimal fraction. Required. | — |\n| `frequency` | Coupon payments per year: `1` annual, `2` semi-annual, `4` quarterly. Required. | — |\n| `basis` | The day-count basis. Optional. | 0 |\n\nThe day-count basis values are the standard five: `0` or omitted = US (NASD) 30/360, `1` =\nActual/actual, `2` = Actual/360, `3` = Actual/365, `4` = European 30/360.\n\nThree argument traps, in decreasing order of how often they bite:\n\n1. **`coupon` and `yld` are annual rates even when `frequency` is 2 or 4.** A 6% semi-annual bond is\n   `coupon = 0.06`, `frequency = 2` — not `0.03`. The function divides by `frequency` internally.\n2. **`frequency` admits only 1, 2 and 4.** There is no monthly bond here; `frequency = 12` is an\n   error, not a slow path.\n3. **Dates and `basis` are truncated to integers**, as documented for the whole bond family. There\n   is no `issue` date argument: `DURATION` assumes settlement falls inside a regular coupon period.\n   Odd first or last periods need `ODDFPRICE`-family thinking, and `DURATION` will not tell you it\n   was the wrong function.\n\n\n"
  },
  "signature": {
    "display": "DURATION(settlement, maturity, coupon, yld, frequency, [basis])",
    "parameters": [
      {
        "description": null,
        "name": "settlement",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "maturity",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "coupon",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "yld",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "frequency",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "basis",
        "optional": true,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 6,
        "min": 5
      },
      "category": "Financial functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "Macaulay duration of a security with periodic coupons, in years",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the annual duration of a security with periodic interest payments",
        "microsoft_url": "https://support.microsoft.com/en-us/office/duration-function-b254ea57-eadc-4602-a86a-c8e369334038"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "DURATION"
        },
        {
          "locale": "bg-BG",
          "name": "DURATION"
        },
        {
          "locale": "cs-CZ",
          "name": "DURATION"
        },
        {
          "locale": "da-DK",
          "name": "VARIGHED"
        },
        {
          "locale": "de-DE",
          "name": "DURATION"
        },
        {
          "locale": "el-GR",
          "name": "DURATION"
        },
        {
          "locale": "en-AU",
          "name": "DURATION"
        },
        {
          "locale": "en-GB",
          "name": "DURATION"
        },
        {
          "locale": "en-US",
          "name": "DURATION"
        },
        {
          "locale": "es-ES",
          "name": "DURACIÓN"
        },
        {
          "locale": "et-EE",
          "name": "DURATION"
        },
        {
          "locale": "fi-FI",
          "name": "KESTO"
        },
        {
          "locale": "fr-FR",
          "name": "DURÉE"
        },
        {
          "locale": "he-IL",
          "name": "DURATION"
        },
        {
          "locale": "hr-HR",
          "name": "DURATION"
        },
        {
          "locale": "hu-HU",
          "name": "KAMATÉRZ"
        },
        {
          "locale": "id-ID",
          "name": "DURATION"
        },
        {
          "locale": "it-IT",
          "name": "DURATION"
        },
        {
          "locale": "ja-JP",
          "name": "期間"
        },
        {
          "locale": "ko-KR",
          "name": "지속 시간"
        },
        {
          "locale": "lt-LT",
          "name": "DURATION"
        },
        {
          "locale": "lv-LV",
          "name": "DURATION"
        },
        {
          "locale": "nb-NO",
          "name": "VARIGHET,"
        },
        {
          "locale": "nl-NL",
          "name": "DUUR"
        },
        {
          "locale": "pl-PL",
          "name": "ROCZ.PRZYCH"
        },
        {
          "locale": "pt-BR",
          "name": "DURAÇÃO"
        },
        {
          "locale": "pt-PT",
          "name": "DURAÇÃO"
        },
        {
          "locale": "ro-RO",
          "name": "DURATION"
        },
        {
          "locale": "ru-RU",
          "name": "ДЛИТ"
        },
        {
          "locale": "sk-SK",
          "name": "DURATION"
        },
        {
          "locale": "sl-SI",
          "name": "DURATION"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "TRAJANJE"
        },
        {
          "locale": "sv-SE",
          "name": "LÖPTID"
        },
        {
          "locale": "th-TH",
          "name": "DURATION"
        },
        {
          "locale": "tr-TR",
          "name": "SÜRE işlevi"
        },
        {
          "locale": "uk-UA",
          "name": "DURATION"
        },
        {
          "locale": "vi-VN",
          "name": "DURATION"
        },
        {
          "locale": "zh-CN",
          "name": "持续时间"
        },
        {
          "locale": "zh-HK",
          "name": "DURATION"
        },
        {
          "locale": "zh-TW",
          "name": "DURATION"
        }
      ],
      "signature": {
        "display": "DURATION(settlement, maturity, coupon, yld, frequency, [basis])",
        "parameters": [
          {
            "description": null,
            "name": "settlement",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "maturity",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "coupon",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "yld",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "frequency",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "basis",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "DURATION",
      "version_marker": null,
      "xlcall": {
        "code": "458",
        "symbol": "xlfDuration"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/duration-function-b254ea57-eadc-4602-a86a-c8e369334038"
  },
  "try_it": {
    "formula": "=DURATION(DATE(2024,1,1),DATE(2028,1,1),0.05,0.06,2)"
  },
  "url": "https://handbook.dnacalc.com/functions/DURATION.html",
  "variants": [],
  "versions": [
    {
      "behaviour": "7,620 captured inputs are indexed for this environment. Capture dates: 2026-07-20 to 2026-07-20. This is a reading count, not a comparison with another build.",
      "excel_build": "16.0 build 20131",
      "platform": "Windows, bitness not recorded, AMD Ryzen 7 4800H with Radeon Graphics",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.DURATION.json"
      ]
    }
  ]
}