1
0
mirror of https://github.com/bspeice/metrik synced 2024-11-05 06:58:12 -05:00
metrik/metrik/trading_days.py
Bradlee Speice f2390ba34f Get command-line tools up and running
I now have something that actually gets stuff done.
2016-08-22 21:34:54 -04:00

28 lines
903 B
Python

from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday, \
nearest_workday, USMartinLutherKingJr, USPresidentsDay, GoodFriday, \
USMemorialDay, USLaborDay, USThanksgivingDay
from pandas.tseries.offsets import CustomBusinessDay
from pandas import date_range
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())
def is_trading_day(date):
return bool(len(date_range(date, date, freq=TradingDay(1))))