mirror of
https://github.com/bspeice/metrik
synced 2024-11-05 06:58:12 -05:00
f2390ba34f
I now have something that actually gets stuff done.
28 lines
903 B
Python
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))))
|