1
0
mirror of https://github.com/bspeice/metrik synced 2024-11-05 06:58:12 -05:00
metrik/metrik/trading_days.py
2016-08-16 16:06:59 -04:00

21 lines
777 B
Python

from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday, \
nearest_workday, USMartinLutherKingJr, USPresidentsDay, GoodFriday,\
USMemorialDay, USLaborDay, USThanksgivingDay
from pandas.tseries.offsets import CustomBusinessDay
class USTradingCalendar(AbstractHolidayCalendar):
rules = [
Holiday('NewYearsDay', month=1, day=1, observance=nearest_workday),
USMartinLutherKingJr,
USPresidentsDay,
GoodFriday,
USMemorialDay,
Holiday('USIndependenceDay', month=7, day=4, observance=nearest_workday),
USLaborDay,
USThanksgivingDay,
Holiday('Christmas', month=12, day=25, observance=nearest_workday)
]
def TradingDay(n):
return CustomBusinessDay(n, calendar=USTradingCalendar())