Skip to content
All library documents

Converting IMM Month Codes into Quarterly Futures Dates

Article Quant Q&A · Author: rvictordelta

Summary

The document presents a Python method for converting a two-character IMM futures code into a calendar date. It maps the first character to a delivery month, derives a candidate year from the current year and the code’s final digit, then calculates the third Wednesday of that month. If that date has already passed, the method advances the year prefix and recalculates.

The example demonstrates the intended date convention and notes that the function could be adapted to longer symbols for historical dates. Its year inference is tied to the current date and only uses a single year digit, so it may be ambiguous across decade boundaries or unsuitable for arbitrary historical contracts without modification. The document offers code but no tests or discussion of exchange-specific exceptions.

Key ideas

  • IMM month letters map contract symbols to calendar months.
  • The described convention uses the third Wednesday of the coded month.
  • The method infers a candidate year from the current year and the symbol’s final digit.
  • Its current-date logic can be ambiguous across decades and needs modification for reliable historical lookup.

Tags

Full text
# How to get the IMM dates in Python for a given symbol?


# How to get the IMM dates in Python for a given symbol?












How can I get an IMM date from its 2 character symbol (eg. "U6", "Z8") in python?

I have not been able to install the quantlib addin (it's hard if you aren't tech savy), so please don't point me in that direction..

## Answer by rvictordelta (score 5, accepted)

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

This does the trick. Given "U8", function will get the IMM date for Sep 2018. Given "U4", function gets the IMM date for Sep 2024 (or it will until we've passed that date). Could be easily modified to also pull historical IMMs from a given longer symbol eg. "U2014".

```
def getIMMDate(IMMcode):

'''Takes 2 digit IMM code and returns effective date as datetime object'''
from datetime import datetime, timedelta

monthcodes = [[1, 'F'], [2, 'G'], [3, 'H'], [4, 'J'], [5, 'K'], [6, 'M'], [7, 'N'], [8, 'Q'],
              [9, 'U'], [10, 'V'], [11, 'X'], [12, 'Z']]
month = [pair[0] for pair in monthcodes if pair[1] == IMMcode[0].upper()][0]

year_prefix = str(datetime.now().year)[:3]
year = int(year_prefix + IMMcode[1])

the_date = datetime(year, month, 1)
temp = the_date.replace(day=1)
nth_week = 3
week_day = 2
adj = (week_day - temp.weekday()) % 7
temp += timedelta(days=adj)
temp += timedelta(weeks=nth_week - 1)

if temp < datetime.now():
    year_prefix = str(int(str(datetime.now().year)[:3]) + 1)
    year = int(year_prefix + IMMcode[1])

    the_date = datetime(year, month, 1)
    temp = the_date.replace(day=1)
    nth_week = 3
    week_day = 2
    adj = (week_day - temp.weekday()) % 7
    temp += timedelta(days=adj)
    temp += timedelta(weeks=nth_week - 1)

return datetime.strftime(temp, "%m/%d/%Y")
```

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.