Skip to content
All library documents

Mapping Days to Standard Maturity Tenor Buckets

Article Quant Q&A · Author: Whitebeard13

Summary

The document addresses converting a day count to maturity into a standard tenor label, such as mapping a short period to one month or a longer period to two years. The answer argues that no universal automatic convention is appropriate because users may want different tenor sets and assignment rules, including backward, forward, or interpolated mappings.

It offers a simple Python approach: define ordered day thresholds paired with tenor labels, then assign an observation to the first threshold it falls below. The examples map the stated day counts to one month and two years. This method is easy to customize, but the example’s final case shows that values beyond the largest threshold are returned as that last tenor, which can silently mislabel very long maturities. Users should define boundary behavior, ensure thresholds are ordered, and select conventions appropriate to the instrument and analysis.

Key ideas

  • Tenor assignment depends on the required bucket set and mapping convention.
  • A threshold map can assign day counts to the first tenor threshold above them.
  • Users can implement the desired mapping directly when package conventions do not fit.
  • Values beyond the largest threshold need explicit handling to avoid incorrect labels.

Tags

Full text
# Allocation of time to maturity day difference into standard tenor buckets in python


# Allocation of time to maturity day difference into standard tenor buckets in python












I was wondering if there is a quick way, e.g. via quantlib or any other python package/module, to allocate or to correspond time to maturity day differences to standard tenor buckets. In other words, is there any already developed automation which would give me the following 1M and 2Y results after feeding it with the 21 and 567 figures, respectively?

```
reference_date  maturity_date   difference  tenor
31-05-2024      21-06-2024      21          1M
31-05-2024      19-12-2025      567         2Y
```

## Answer by Attack68 (score 4, accepted)

https://quant.stackexchange.com/a/80062

I think the reason that this does not exist is because it is so subjective that any package owner would not want to impart their own definition on users. What are the required tenors? Is is backwards, forwards or linearly interpolated? It is also fairly straightforward for a user to code exactly the subjectivity they desire into a Python function.

```
def get_tenor(days, tenor_map):
    for k, v in tenor_map.keys():
        if days < k:
            return v
    return v

TENOR_MAP = {30: "1m", 60: "2m", 91: "3m", 182: "6m", 365: "1y", 730: "2y"}

get_tenor(21, TENOR_MAP)  # "1m"
get_tenor(567, TENOR_MAP)  # "2y"
get_tenor(2045, TENOR_MAP)  # "2y"
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.