0
$\begingroup$

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
$\endgroup$

1 Answer 1

4
$\begingroup$

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"
$\endgroup$
1
  • $\begingroup$ Clarified. Thank you @Attack68. Also thank you for the code sample. $\endgroup$ Commented Jul 19 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.