def AddHoliday(cal, newHolDate): ''' Input: cal -- calendar对象 newHolDate -- 新节假日 Output: 新的calendar对象 ''' newHolDate = pd.Timestamp(newHolDate) calDate = __parsePYDate__(newHolDate) cal.addHoliday(calDate) return cal
def RemoveHoliday(cal, targetHolDate): ''' Input: cal -- calendar对象 targetHolDate -- 旧节假日 Output: 新的calendar对象 ''' targetHolDate = pd.Timestamp(targetHolDate) calDate = __parsePYDate__(targetHolDate) cal.removeHoliday(calDate) return cal
def HolDatesList(cal, startDate, endDate): ''' Input: cal -- calendar对象 startDate -- 参考时间段起始 enDate -- 参考时间段结束 Output: 节假日列表 ''' totalDateRange = pd.date_range(startDate, endDate) holDates = [] for sampleDate in totalDateRange[:-1]: calDate = __parsePYDate__(sampleDate) if not cal.isBusinessDay(calDate): holDates.append(sampleDate) return holDates
def AdvanceDate(cal, todayDate, period, convention, endOfMonth = False): periodObj = PeriodParser.parse(period) todayDate = pd.Timestamp(todayDate) calDate = __parsePYDate__(todayDate) res = cal.advance(calDate, periodObj.length(), periodObj.units(), convention, endOfMonth) return __parseCALDate__(res)
def IsMonthEnd(cal, testDate): testDate = pd.Timestamp(testDate) calDate = __parsePYDate__(testDate) return cal.isEndOfMonth(calDate)
def IsHoliday(cal, testDate): testDate = pd.Timestamp(testDate) calDate = __parsePYDate__(testDate) return cal.isHoliday(calDate)
def IsBizDay(cal, testDate): testDate = pd.Timestamp(testDate) calDate = __parsePYDate__(testDate) return cal.isBusinessDay(calDate)