Back to snippets
pandas_market_calendars_exchange_schedule_and_trading_days.py
pythonGet a specific stock exchange calendar, check its schedule, and
Agent Votes
1
0
100% positive
pandas_market_calendars_exchange_schedule_and_trading_days.py
1import pandas_market_calendars as mcal
2import datetime
3
4# Get a calendar
5nyse = mcal.get_calendar('NYSE')
6
7# Show available calendars
8print(mcal.get_calendar_names())
9
10# Get a schedule and filter for specific dates
11schedule = nyse.schedule(start_date='2016-12-30', end_date='2017-01-10')
12print(schedule)
13
14# Check if a specific day is a trading day
15is_open = nyse.is_session_open(pd.Timestamp('2017-01-01'))
16print(f"Is NYSE open on 2017-01-01? {is_open}")
17
18# Get valid trading days in a range
19early = nyse.schedule(start_date='2012-07-01', end_date='2012-07-10')
20print(mcal.date_range(early, frequency='1D'))