In [1]:
import sys
sys.path.append("../")
from datetime import time
import pandas as pd
import pandas_market_calendars as mcal
In [2]:
nyse = mcal.get_calendar('NYSE')
Get the time zone
In [3]:
nyse.tz.zone
Out[3]:
Get the AbstractHolidayCalendar object
In [4]:
holidays = nyse.holidays()
holidays.holidays[-5:]
Out[4]:
Get the valid open exchange business dates between a start and end date. Note that Dec 26 (Christmas), Jan 2 (New Years) and all weekends are missing
In [5]:
nyse.valid_days(start_date='2016-12-20', end_date='2017-01-10')
Out[5]:
In [6]:
schedule = nyse.schedule(start_date='2016-12-30', end_date='2017-01-10')
schedule
Out[6]:
In [7]:
# with early closes
early = nyse.schedule(start_date='2012-07-01', end_date='2012-07-10')
early
Out[7]:
In [8]:
nyse.early_closes(schedule=early)
Out[8]:
In [9]:
nyse.open_at_time(early, pd.Timestamp('2012-07-03 12:00', tz='America/New_York'))
Out[9]:
In [10]:
nyse.open_at_time(early, pd.Timestamp('2012-07-03 16:00', tz='America/New_York'))
Out[10]:
In [11]:
mcal.date_range(early, frequency='1D')
Out[11]:
In [12]:
mcal.date_range(early, frequency='1H')
Out[12]:
In [13]:
cal = mcal.get_calendar('NYSE', open_time=time(10, 0), close_time=time(14, 30))
print('open, close: %s, %s' % (cal.open_time, cal.close_time))
In [14]:
# NYSE Calendar
nyse = mcal.get_calendar('NYSE')
schedule_nyse = nyse.schedule('2015-12-20', '2016-01-06')
schedule_nyse
Out[14]:
In [15]:
# LSE Calendar
lse = mcal.get_calendar('LSE')
schedule_lse = lse.schedule('2015-12-20', '2016-01-06')
schedule_lse
Out[15]:
In [16]:
mcal.merge_schedules(schedules=[schedule_nyse, schedule_lse], how='inner')
Out[16]:
In [17]:
mcal.merge_schedules(schedules=[schedule_nyse, schedule_lse], how='outer')
Out[17]:
In [ ]: