Skip to main content

finance dates

Fast date ranges, holiday calendars, and trading hours for financial markets

Build Status codecov License PyPI

Overview

finance-dates provides calendar-aware date utilities for the finance-* stack. The Rust core handles holiday-rule expansion, weekend observance, early closes, and DST-aware regular and extended trading sessions; the Python package exposes a compact API for date series, exchange calendars, and open/close timestamps.

The library is useful when you need to answer questions like:

  • What are the valid trading dates for NYSE between two dates?
  • Which dates in a range are holidays or otherwise invalid for a venue?
  • Is a UTC timestamp inside a market session after DST and early closes?
  • What are the UTC open/close datetimes for regular and extended trading windows?

Quick start

from datetime import date, datetime, timezone

from finance_dates import Calendar
from finance_enums import EnergyType, ExchangeCode, UnderlyingAssetClass

c = Calendar.from_range(start=date(2024, 1, 1), end=date(2024, 1, 5))

# Inclusive plain calendar dates.
c.days()

# Mon-Fri only, holiday-blind.
c.business_days()

# Exchange-aware calendar with holidays, sessions, and early closes.
nyse = Calendar.from_exchange("XNYS")
nyse.business_days(date(2024, 7, 1), date(2024, 7, 5))
nyse.holidays(date(2024, 7, 1), date(2024, 9, 30))
nyse.sessions(date(2024, 7, 1), date(2024, 7, 5))
nyse.extended_sessions(date(2024, 7, 1), date(2024, 7, 5))
nyse.is_open(datetime(2024, 3, 11, 13, 30, tzinfo=timezone.utc))

gas = Calendar.from_asset(
  ExchangeCode.XNYM,
  UnderlyingAssetClass.Commodity,
  subclass=EnergyType.NaturalGas,
)
gas.regular_sessions

For US equity calendars, regular_sessions contains the standard 09:30-16:00 New York session template, while extended_hours includes pre_open and after_close templates. On early-close days, the after-close window begins at the early close.

Calendars with lunch breaks expose multiple regular session templates. For example, Tokyo (XTKS) currently returns separate 09:00-11:30 and 12:30-15:30 local sessions, and sessions() returns one UTC open/close pair per regular interval. Tokyo is date-effective around the 2024-11-05 close-time extension, so historical dates before that change close at 15:00 local while current dates close at 15:30.

Commodity futures can also use split sessions. Prefer Calendar.from_asset() with finance-enums exchange and asset/subclass enum members, or their string values, when you know the instrument vocabulary; for example ExchangeCode.XNYM plus EnergyType.NaturalGas resolves to the NYMEX energy template without requiring synthetic names like NYMEX_ENERGY. Synthetic product-group codes such as CBOT_GRAINS and product mnemonics such as CL or ZC remain accepted by from_exchange() for lower-level calendar inspection and compatibility.

Exchange and country calendars

Calendars cover US equities, options, bonds, and futures alongside major international equity venues across the Americas, Europe, the Middle East, Africa, and Asia-Pacific. Each international venue has a dedicated national holiday rule set, including lunar (China, Hong Kong, Korea, Taiwan), Islamic (Saudi Arabia, Turkey, UAE), and Hebrew (Israel) calendars, plus computed rules such as the Japanese equinoxes.

Calendars can be resolved by exchange/MIC code or by ISO country code:

from finance_dates import Calendar
from finance_enums import EnergyType, ExchangeCode, UnderlyingAssetClass

Calendar.from_exchange("XLON")   # London Stock Exchange
Calendar.from_exchange("XTKS")   # Tokyo Stock Exchange, split lunch sessions
Calendar.from_exchange("XKRX")   # Korea Exchange, lunar holidays
Calendar.from_exchange("XCME")   # CME futures-style overnight sessions
Calendar.from_exchange("CBOT_GRAINS")  # CBOT grain/oilseed futures sessions
Calendar.from_exchange("CME_ENERGY")  # Globex energy-category alias
Calendar.from_asset(ExchangeCode.XNYM, UnderlyingAssetClass.Commodity, subclass=EnergyType.NaturalGas)
Calendar.from_product("ICE_US", "Sugar")  # ICE US product-specific template
Calendar.from_exchange("FOREX")  # 24x5 FX family
Calendar.from_region("US")       # representative US equity calendar

Calendar.from_exchange() accepts additional resolver-only calendar aliases such as CBOT_GRAINS, CME_ENERGY, CL, and ZC; those are documented in the Calendars page.

Polars integration

When Polars is installed, importing finance_dates registers a .fdates namespace on expressions and series for business-day shifting, business-day alignment, and day-count fractions. The top-level period_grid() helper buckets a date column into period boundaries.

import polars as pl
from finance_dates import period_grid

df = pl.DataFrame({"trade": [date(2024, 7, 3), date(2024, 12, 24)]})
df.with_columns(
    settle=pl.col("trade").fdates.shift_business_days(2, exchange="XNYS"),
    bucket=period_grid(pl.col("trade"), "1mo"),
)

Documentation

See the Calendars page for supported concepts, market families, date-series patterns, and trading-hours conventions. See the API page for the public Python API and recipes.

Rust crate

The Rust library crate is published as finance-dates and imported as finance_dates in Rust code:

[dependencies]
finance-dates = "0.4.0"
use finance_dates::{calendar_for_exchange, date_range};

Metadata

Release files for finance-dates 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finance-dates 0.5.1
File Size Uploaded Provenance Actions
finance_dates-0.5.1.tar.gz 95.2 kB Without provenance Details for finance_dates-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for finance-dates 0.5.1
File Actions
finance_dates-0.5.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for finance_dates-0.5.1-cp311-abi3-win_amd64.whl
finance_dates-0.5.1-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for finance_dates-0.5.1-cp311-abi3-manylinux_2_28_x86_64.whl
finance_dates-0.5.1-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for finance_dates-0.5.1-cp311-abi3-manylinux_2_28_aarch64.whl
finance_dates-0.5.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for finance_dates-0.5.1-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 2.4 MB

Release files / finance_dates-0.5.1.tar.gz

Download URL finance_dates-0.5.1.tar.gz
Size 95.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1b305da00529fdb183c2286f3bb468efcc8f2e4d2fea891398c0bb86a1b29d0e
BLAKE2b-256 checksum
How to use checksums
81269182d1ba4c88d16efc8a346468fc2397e99d7e9285b045cb1f475ad8cf80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / finance_dates-0.5.1-cp311-abi3-win_amd64.whl

Download URL finance_dates-0.5.1-cp311-abi3-win_amd64.whl
Size 459.8 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
10377c79548bdad8ffba06798c12a43ca33bebd97f856f40ff18e70036505e87
BLAKE2b-256 checksum
How to use checksums
0d6a8e1d9c99c16ec2aa652756b41a1d7d2a8d14410cc7de5863c2c8995bc0f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / finance_dates-0.5.1-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL finance_dates-0.5.1-cp311-abi3-manylinux_2_28_x86_64.whl
Size 648.7 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
121fe072975f7631a261b29dfce80ec761496dc078c4bf8ebae5c24bbcedffab
BLAKE2b-256 checksum
How to use checksums
3f508a3ce7b570e05ceed59a421bf98b2e0db1dd5d8e9de19d18e5c6b3843ffd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / finance_dates-0.5.1-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL finance_dates-0.5.1-cp311-abi3-manylinux_2_28_aarch64.whl
Size 649.0 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
6adc0cfabdb90e81783d01feb521abdd81182ae873020b55541364765e5a85da
BLAKE2b-256 checksum
How to use checksums
3dc4a28be9ebe65a0e0b0ba399b35cfc2879e6aef397e5a14fa0a077c9c9c4e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / finance_dates-0.5.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL finance_dates-0.5.1-cp311-abi3-macosx_11_0_arm64.whl
Size 551.9 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
20f9feeb373a281a3da3b7b1ef3100aba5b89b12777db41da9424e027562db59
BLAKE2b-256 checksum
How to use checksums
1b675471a336629165d127f63277b4f91a7799c9d68c47545934878a65e39f67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for finance-dates 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page