#NEWLINE# def get_non_trading_days( start , end ) : #NEWLINE# #INDENT# non_trading_rules = [ ] #NEWLINE# start = canonicalize_datetime ( start ) #NEWLINE# end = canonicalize_datetime ( end ) #NEWLINE# weekends = rrule . rrule ( rrule . YEARLY , byweekday = ( rrule . SA , rrule . SU ) , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( weekends ) #NEWLINE# new_years = rrule . rrule ( rrule . MONTHLY , byyearday = 1 , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( new_years ) #NEWLINE# new_years_sunday = rrule . rrule ( rrule . MONTHLY , byyearday = 2 , byweekday = rrule . MO , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( new_years_sunday ) #NEWLINE# mlk_day = rrule . rrule ( rrule . MONTHLY , bymonth = 1 , byweekday = rrule . MO ( ( + 3 ) ) , cache = True , dtstart = datetime ( 1998 , 1 , 1 , tzinfo = pytz . utc ) , until = end ) #NEWLINE# non_trading_rules . append ( mlk_day ) #NEWLINE# presidents_day = rrule . rrule ( rrule . MONTHLY , bymonth = 2 , byweekday = rrule . MO ( 3 ) , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( presidents_day ) #NEWLINE# good_friday = rrule . rrule ( rrule . DAILY , byeaster = ( - 2 ) , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( good_friday ) #NEWLINE# memorial_day = rrule . rrule ( rrule . MONTHLY , bymonth = 5 , byweekday = rrule . MO ( ( - 1 ) ) , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( memorial_day ) #NEWLINE# july_4th = rrule . rrule ( rrule . MONTHLY , bymonth = 7 , bymonthday = 4 , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( july_4th ) #NEWLINE# july_4th_sunday = rrule . rrule ( rrule . MONTHLY , bymonth = 7 , bymonthday = 5 , byweekday = rrule . MO , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( july_4th_sunday ) #NEWLINE# july_4th_saturday = rrule . rrule ( rrule . MONTHLY , bymonth = 7 , bymonthday = 3 , byweekday = rrule . FR , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( july_4th_saturday ) #NEWLINE# labor_day = rrule . rrule ( rrule . MONTHLY , bymonth = 9 , byweekday = rrule . MO ( 1 ) , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( labor_day ) #NEWLINE# thanksgiving = rrule . rrule ( rrule . MONTHLY , bymonth = 11 , byweekday = rrule . TH ( 4 ) , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( thanksgiving ) #NEWLINE# christmas = rrule . rrule ( rrule . MONTHLY , bymonth = 12 , bymonthday = 25 , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( christmas ) #NEWLINE# christmas_sunday = rrule . rrule ( rrule . MONTHLY , bymonth = 12 , bymonthday = 26 , byweekday = rrule . MO , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( christmas_sunday ) #NEWLINE# christmas_saturday = rrule . rrule ( rrule . MONTHLY , bymonth = 12 , bymonthday = 24 , byweekday = rrule . FR , cache = True , dtstart = start , until = end ) #NEWLINE# non_trading_rules . append ( christmas_saturday ) #NEWLINE# non_trading_ruleset = rrule . rruleset ( ) #NEWLINE# for rule in non_trading_rules : #NEWLINE# #INDENT# non_trading_ruleset . rrule ( rule ) #NEWLINE# #UNINDENT# non_trading_days = non_trading_ruleset . between ( start , end , inc = True ) #NEWLINE# for day_num in range ( 11 , 17 ) : #NEWLINE# #INDENT# non_trading_days . append ( datetime ( 2001 , 9 , day_num , tzinfo = pytz . utc ) ) #NEWLINE# #UNINDENT# for day_num in range ( 29 , 31 ) : #NEWLINE# #INDENT# non_trading_days . append ( datetime ( 2012 , 10 , day_num , tzinfo = pytz . utc ) ) #NEWLINE# #UNINDENT# non_trading_days . append ( datetime ( 1994 , 4 , 27 , tzinfo = pytz . utc ) ) #NEWLINE# non_trading_days . append ( datetime ( 2004 , 6 , 11 , tzinfo = pytz . utc ) ) #NEWLINE# non_trading_days . append ( datetime ( 2007 , 1 , 2 , tzinfo = pytz . utc ) ) #NEWLINE# non_trading_days . sort ( ) #NEWLINE# return pd . DatetimeIndex ( non_trading_days )