Skip to content

exchange-calendars-extensions

A Python package that transparently extends the exchange-calendars package with additional features.

Features

Adds the following features to exchange calendars.

All exchanges:

  • Aggregate calendars that combine regular and ad-hoc holidays, special open days, and special close days into a single calendar, respectively.
  • Calendars for the last and last regular trading session of each month.
  • Calendars for weekend and week days.
  • API for runtime modifications to any exchange calendar.
  • Attach and query arbitrary tags to days.

Select exchanges:

  • Calendars for monthly and quarterly expiry days (quadruple witching); see supported exchanges.

Installation

The package is available on PyPI and can be installed via uv, pip, Poetry, or any other Python dependency manager.

uv add exchange-calendars-extensions
pip install exchange-calendars-extensions
poetry add exchange-calendars-extensions

Quick start

Tip

All code examples in this documentation are self-contained and can be executed in a fresh Python interpreter.

Adding extensions

To apply the extensions, import exchange_calendars_extensions and register the extended calendar classes:

import exchange_calendars_extensions as ecx

ecx.apply_extensions()  # (1)!
  1. You only need to run this once per session.

This replaces the default classes with their extended versions.

Obtain an exchange calendar instance and verify that it is the extended version.

import exchange_calendars as ec
import exchange_calendars_extensions as ecx

ecx.apply_extensions()

calendar = ec.get_calendar("XLON")

# Still a regular exchange calendar.
assert isinstance(calendar, ec.ExchangeCalendar)

# But also an extended exchange calendar…
assert isinstance(calendar, ecx.ExtendedExchangeCalendar)

# …that implements the extended protocol.
assert isinstance(calendar, ecx.ExchangeCalendarExtensions)

Extended calendars are subclasses of ecx.ExtendedExchangeCalendar, which inherits from both ec.ExchangeCalendar and the protocol class ecx.ExchangeCalendarExtensions.

You can now use extended calendars.

import exchange_calendars as ec
import exchange_calendars_extensions as ecx

ecx.apply_extensions()

calendar = ec.get_calendar("XLON")
print(
    calendar.holidays_all.holidays(
        start="2020-01-01", end="2020-12-31", return_name=True
    )
)

Removing extensions

The original, unextended classes can be restored at any time:

import exchange_calendars as ec
import exchange_calendars_extensions as ecx

ecx.apply_extensions()

...

ecx.remove_extensions()

calendar = ec.get_calendar("XLON")

# A regular exchange calendar.
assert isinstance(calendar, ec.ExchangeCalendar)

# No longer an extended calendar.
assert not isinstance(calendar, ecx.ExtendedExchangeCalendar)
assert not isinstance(calendar, ecx.ExchangeCalendarExtensions)

Note

After applying or removing the extensions, exchange calendars must be re-created via ec.get_calendar() for the changes to be visible. Previously created instances retain their properties.

What's next?

  • Dates & Times — Specify dates and times conveniently.
  • Extended properties — Aggregate calendars, expiry days, last trading days, and more.
  • Calendar changes — Modify any day at runtime: add holidays, change open/close times, and more.
  • Changesets — Apply, inspect, and serialise bulk modifications.
  • Tags — Attach and query arbitrary labels on days.
  • Supported exchanges — Exchanges with monthly/quarterly expiry support.
  • Advanced usage — Extend new exchanges and merge holiday calendars safely.