Programmatically determine trading dates using the pandas_market_calendars library for NYSE, CME, CBOE, NASDAQ, and other exchanges.
# 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