Skip to main content

Using Market Calendar (mcal) to Identify Trading Dates

When retrieving market data, it is beneficial to programmatically determine which dates represent actual trading dates. The Market Calendar (mcal) library enables this functionality.

US Stock Market Calendars

Market Calendar supports multiple US exchanges including NYSE, CME, CBOE, and NASDAQ.

Implementation Example

# Get NYSE Schedule for date range
# Documentation: https://pandas-market-calendars.readthedocs.io/en/latest/usage.html

start_date = '2024-01-01'
end_date = '2024-06-01'

import pandas as pd
import pandas_market_calendars as mcal

nyse = mcal.get_calendar('NYSE')
schedule = nyse.schedule(start_date=start_date, end_date=end_date)
schedule

schedule.market_open.iloc[0]   # open time first date
schedule.market_close.iloc[0]  # close time first date
schedule.market_open.iloc[-1]  # open time last date
schedule.market_close.iloc[-1] # close time last date

schedlist = list(schedule.index)
schedlist
Although mcal is generally extremely reliable, it is an external library and has on occasion missed a market holiday. Implement defensive coding practices and verify results independently.
The library demonstrates strong reliability for US market holidays but cannot be vouched for with equal confidence regarding international markets.

Resources