def movedatebymonth(your_date, no_of_month=1, business_day='No Adjustment', holidays=[]): bdc = np.busdaycalendar(weekmask='1111100', holidays=holidays) start_m = dt64(your_date, 'M') day = _datediff(dt64(start_m, 'D'), dt64(your_date, 'D') ) end_m = nb_movedatebymonth(start_m, td64(no_of_month,'M')) next_m = end_m + 1 days_in_end_m = _datediff(dt64(end_m, 'D'), dt64(next_m, 'D')) if days_in_end_m > day: enddate = dt64(end_m, 'D') + day else: enddate = dt64(end_m, 'D') + days_in_end_m - 1 if business_day == 'No Adjustment' or business_day is None: return enddate elif business_day == 'Following': return np.busday_offset(enddate, 0, roll='forward', busdaycal=bdc) elif business_day == 'Preceeding': return np.busday_offset(enddate, 0, roll='backward', busdaycal=bdc) elif business_day == 'Modified Following': new_date = np.busday_offset(enddate, 0, roll='forward', busdaycal=bdc) if dt64(new_date, 'M') > end_m: return np.busday_offset(enddate, 0, roll='backward', busdaycal=bdc) else: return new_date
def adjustdates(months, dates, business_day, holidays=[]): bdc = np.busdaycalendar(weekmask='1111100', holidays=holidays) datalen = len(dates) newdates = [] for i in range(datalen): month = months[i] dmonth = dt64(dates[i], 'M') if dmonth == month: if business_day == 'Following': dates[i] = np.busday_offset(dates[i], 0, roll='forward', busdaycal=bdc) elif business_day == 'Preceeding': dates[i] = np.busday_offset(dates[i], 0, roll='backward', busdaycal=bdc) elif business_day == 'Modified Following': new_date = np.busday_offset(dates[i], 0, roll='forward', busdaycal=bdc) if dt64(new_date, 'M') > month: dates[i] = np.busday_offset(dates[i], 0, roll='backward', busdaycal=bdc) elif dmonth > month: #print(month,dmonth) nextmonth = month + td64(1, 'M') nextmonthdate = dt64(nextmonth, 'D') days = _datediff(dt64(month, 'D'), nextmonthdate) dates[i] = dt64(month, 'D') + days - 1 if business_day == 'Following': dates[i] = np.busday_offset(dates[i], 0, roll='forward', busdaycal=bdc) elif business_day == 'Preceeding': dates[i] = np.busday_offset(dates[i], 0, roll='backward', busdaycal=bdc) elif business_day == 'Modified Following': new_date = np.busday_offset(dates[i], 0, roll='forward', busdaycal=bdc) if dt64(new_date, 'M') > month: dates[i] = np.busday_offset(dates[i], 0, roll='backward', busdaycal=bdc)
for i in range(size): a = date2[i] - date1[i] return a start0 = time.perf_counter() nbdates1 = numpy.fromiter((date1 for x in range(t)), '<M8[D]') nbdates2 = numpy.fromiter((date2 for x in range(t)), '<M8[D]') test2 = numba_differences4(nbdates1, nbdates2) end0 = time.perf_counter() print(f"Time taken for test4 is {end0-start0} seconds: result {test2}") datemonth = dt64('2021-01-05', 'M') month = td64(6, 'M') @numba.njit(numba.types.NPDatetime('M')(numba.types.NPDatetime('M'), numba.types.NPTimedelta('M')), cache=True) #@numba.jit def movedatebymonth(date1, month): return date1 + (month) @numba.njit(numba.types.NPDatetime('M')(numba.types.NPDatetime('M'), numba.types.int64), cache=True) #@numba.jit def movedatebymonth2(date1, month):