pandas-market-calendars

5.3.2 · active · verified Sat Apr 11

pandas-market-calendars provides a comprehensive set of market and exchange trading calendars for use with pandas. It fills a critical gap by offering specific holiday, late open, and early close calendars for over 50 global equity and futures markets, which are not included in pandas by default. The library also includes functions to manipulate these calendars and generate pandas DatetimeIndex objects containing only market-open times. It is actively maintained with frequent updates, typically releasing new versions every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to list available calendars, get a specific market calendar (NYSE), retrieve its trading schedule for a date range, and then use that schedule to generate a DatetimeIndex of trading days. It also shows how to query specific market open/close times for a given date. Dates and times are timezone-aware.

import pandas_market_calendars as mcal
import pandas as pd

# List all available calendars
print("Available calendars:", mcal.get_calendar_names()[:5], "...")

# Create a NYSE calendar instance
nyse = mcal.get_calendar('NYSE')

# Get the market schedule for a date range
start_date = '2023-12-20'
end_date = '2024-01-10'
schedule = nyse.schedule(start_date=start_date, end_date=end_date)

print(f"\nNYSE Schedule from {start_date} to {end_date}:")
print(schedule.head())

# Get a DatetimeIndex of valid trading times (e.g., daily frequency)
trading_days = mcal.date_range(schedule, frequency='1D')
print(f"\nFirst 5 trading days in the schedule (1D frequency):")
print(trading_days.head())

# Get specific market times for a date
example_date = pd.Timestamp('2023-12-22', tz='America/New_York')
market_open_time = nyse.market_open_time(example_date)
market_close_time = nyse.market_close_time(example_date)
print(f"\nMarket open on {example_date.date()}: {market_open_time.time()}")
print(f"Market close on {example_date.date()}: {market_close_time.time()}")

view raw JSON →