def is_trading_day(self, timestamp): """Tests whether markets are open on a given day.""" # Markets are closed on holidays. if timestamp in UnitedStates(): self.logs.debug("Identified holiday: %s" % timestamp) return False # Markets are closed on weekends. if timestamp.weekday() in [5, 6]: self.logs.debug("Identified weekend: %s" % timestamp) return False # Otherwise markets are open. return True
def fPreviousNBizDay(c, N): newDate = c + relativedelta(bdays=-N, holidays=UnitedStates()) return newDate
'Noon':[12], 'Afternoon':[13,14,15,16], 'Evening':[17,18], 'Night':[0,1,2,3,4,19,20,21,22,23]} CONSTANT_CLASS_WEEKDAYMAP = {'Monday':'0_Mon', 'Tuesday':'1_Tue', 'Wednesday':'2_Wed', 'Thursday':'3_Thu', 'Friday':'4_Fri', 'Saturday':'5_Sat', 'Sunday':'6_Sun'} LOCALHOLIDAYS = UnitedStates() #Methods def datestr2datetime(date): """ #input: date string (yyyymmdd). e.g., 20171130 #output: datetime """ year = int(date[0:4]) month = int(date[4:6]) day = int(date[6:8]) y = datetime(year,month,day,23,59,59) return y