def test_periodic_schedule(self, start_dates, end_dates, period_quantities, period_type, backward, expected_schedule, end_of_month=False): start_dates = dates.from_np_datetimes(_to_np_datetimes(start_dates)) end_dates = dates.from_np_datetimes(_to_np_datetimes(end_dates)) tenors = dates.periods.PeriodTensor(period_quantities, period_type) expected_schedule = dates.from_np_datetimes( _to_np_datetimes(expected_schedule)) actual_schedule = dates.PeriodicSchedule( start_date=start_dates, end_date=end_dates, tenor=tenors, holiday_calendar=dates.HolidayCalendar( weekend_mask=dates.WeekendMask.SATURDAY_SUNDAY, start_year=2020, end_year=2028), roll_convention=dates.BusinessDayConvention.MODIFIED_FOLLOWING, backward=backward, end_of_month=end_of_month).dates() self.assertAllEqual(expected_schedule.ordinal(), actual_schedule.ordinal())
def test_business_day_schedule(self, start_dates, end_dates, holidays, backward, expected_schedule): start_dates = dates.from_np_datetimes(_to_np_datetimes(start_dates)) end_dates = dates.from_np_datetimes(_to_np_datetimes(end_dates)) holiday_calendar = dates.create_holiday_calendar( weekend_mask=dates.WeekendMask.SATURDAY_SUNDAY, holidays=holidays, start_year=2020, end_year=2020) expected_schedule = dates.from_np_datetimes( _to_np_datetimes(expected_schedule)) actual_schedule = dates.BusinessDaySchedule( start_date=start_dates, end_date=end_dates, holiday_calendar=holiday_calendar, backward=backward).dates() self.assertAllEqual(expected_schedule.ordinal(), actual_schedule.ordinal())
def test_schedule_on_fixed_interval(self, start_dates, end_dates, period_quantities, period_type, backward, expected_schedule): start_dates = dates.from_np_datetimes(_to_np_datetimes(start_dates)) end_dates = dates.from_np_datetimes(_to_np_datetimes(end_dates)) tenors = dates.periods.PeriodTensor(period_quantities, period_type) backward = backward expected_schedule = dates.from_np_datetimes( _to_np_datetimes(expected_schedule)) actual_schedule = dates.schedule( start_dates, end_dates, tenors, dates.HolidayCalendar( weekend_mask=dates.WeekendMask.SATURDAY_SUNDAY, start_year=2020, end_year=2028), roll_convention=dates.BusinessDayConvention.MODIFIED_FOLLOWING, backward=backward) self.assertAllEqual(expected_schedule.ordinal(), actual_schedule.ordinal())
def test_create_from_np_datetimes(self): dates = test_data.test_dates y, m, d, o, datetimes = unpack_test_dates(dates) np_datetimes = np.array(datetimes, dtype=np.datetime64) date_tensor = dateslib.from_np_datetimes(np_datetimes) self.assert_date_tensor_equals(date_tensor, y, m, d, o)