/** * Gets the holiday calendar that will be applied to the result. * <p> * This adjustment may contain more than one holiday calendar. * This method returns the calendar used last. * As such, the adjusted date will always be valid according to this calendar. * * @return the result holiday calendar */ public HolidayCalendarId getResultCalendar() { HolidayCalendarId cal = adjustment.getCalendar(); if (cal == HolidayCalendarIds.NO_HOLIDAYS) { cal = calendar; } return cal; }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(BusinessDayAdjustment beanToCopy) { this.convention = beanToCopy.getConvention(); this.calendar = beanToCopy.getCalendar(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 2039569265: // convention return ((BusinessDayAdjustment) bean).getConvention(); case -178324674: // calendar return ((BusinessDayAdjustment) bean).getCalendar(); } return super.propertyGet(bean, propertyName, quiet); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.settlementDateOffset == null && builder.paymentSchedule != null) { builder.settlementDateOffset = DaysAdjustment.ofBusinessDays(3, builder.paymentSchedule.getBusinessDayAdjustment().getCalendar()); } }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.settlementDateOffset == null && builder.paymentSchedule != null) { builder.settlementDateOffset = DaysAdjustment.ofBusinessDays(3, builder.paymentSchedule.getBusinessDayAdjustment().getCalendar()); } }
public void test_noAdjust_constant() { BusinessDayAdjustment test = BusinessDayAdjustment.NONE; assertEquals(test.getConvention(), BusinessDayConventions.NO_ADJUST); assertEquals(test.getCalendar(), NO_HOLIDAYS); assertEquals(test.toString(), "NoAdjust"); }
/** * Normalizes the adjustment. * <p> * If the number of days is zero, the calendar is set no 'NoHolidays'. * If the number of days is non-zero and the calendar equals the adjustment calendar, * the adjustment is removed. * * @return the normalized adjustment */ public DaysAdjustment normalized() { if (days == 0) { if (calendar != HolidayCalendarIds.NO_HOLIDAYS) { return DaysAdjustment.ofCalendarDays(days, adjustment); } return this; } if (calendar.equals(adjustment.getCalendar())) { return DaysAdjustment.ofBusinessDays(days, calendar); } return this; }
public void test_basics() { BusinessDayAdjustment test = BusinessDayAdjustment.of(MODIFIED_FOLLOWING, SAT_SUN); assertEquals(test.getConvention(), MODIFIED_FOLLOWING); assertEquals(test.getCalendar(), SAT_SUN); assertEquals(test.toString(), "ModifiedFollowing using calendar Sat/Sun"); }
public void test_noAdjust_factory() { BusinessDayAdjustment test = BusinessDayAdjustment.of(BusinessDayConventions.NO_ADJUST, NO_HOLIDAYS); assertEquals(test.getConvention(), BusinessDayConventions.NO_ADJUST); assertEquals(test.getCalendar(), NO_HOLIDAYS); assertEquals(test.toString(), "NoAdjust"); }
@Test(dataProvider = "floatLeg") public void test_holiday_calendars_match(FixedIborSwapConvention convention, IborIndex floatLeg) { assertEquals( convention.getFixedLeg().getAccrualBusinessDayAdjustment().getCalendar(), floatLeg.getMaturityDateOffset().getAdjustment().getCalendar()); }
/** * Adjusts the date, adding the period and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link PeriodAdditionConvention#adjust(LocalDate, Period, HolidayCalendar)} to add the period. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
/** * Resolves this adjustment using the specified reference data, returning an adjuster. * <p> * This returns a {@link DateAdjuster} that performs the same calculation as this adjustment. * It binds the holiday calendar, looked up from the reference data, into the result. * As such, there is no need to pass the reference data in again. * * @param refData the reference data, used to find the holiday calendar * @return the adjuster, bound to a specific holiday calendar */ @Override public DateAdjuster resolve(ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return date -> bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
public void test_noAdjust_normalized() { BusinessDayAdjustment test = BusinessDayAdjustment.of(BusinessDayConventions.NO_ADJUST, SAT_SUN); assertEquals(test.getConvention(), BusinessDayConventions.NO_ADJUST); assertEquals(test.getCalendar(), SAT_SUN); assertEquals(test.toString(), "NoAdjust using calendar Sat/Sun"); }
@Test(dataProvider = "calendar") public void test_calendar(ImmutableFxSwapConvention convention, HolidayCalendarId cal) { assertEquals(convention.getSpotDateOffset().getCalendar(), cal); assertEquals(convention.getBusinessDayAdjustment().getCalendar(), cal); }
/** * Resolves this adjustment using the specified reference data, returning an adjuster. * <p> * This returns a {@link DateAdjuster} that performs the same calculation as this adjustment. * It binds the holiday calendar, looked up from the reference data, into the result. * As such, there is no need to pass the reference data in again. * * @param refData the reference data, used to find the holiday calendar * @return the adjuster, bound to a specific holiday calendar */ @Override public DateAdjuster resolve(ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); Period period = tenor.getPeriod(); return date -> bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
/** * Adjusts the date, adding the tenor and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link PeriodAdditionConvention#adjust(LocalDate, Period, HolidayCalendar)} to add the period. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return bda.adjust(additionConvention.adjust(date, tenor.getPeriod(), holCal), holCal); }
public void coverage_builder() { BusinessDayAdjustment test = BusinessDayAdjustment.builder() .convention(MODIFIED_FOLLOWING) .calendar(SAT_SUN) .build(); assertEquals(test.getConvention(), MODIFIED_FOLLOWING); assertEquals(test.getCalendar(), SAT_SUN); }
paymentScheduleBuilder.paymentDateOffset(DaysAdjustment.ofCalendarDays(period.getDays(), payAdjustment)); } else { paymentScheduleBuilder.paymentDateOffset(DaysAdjustment.ofBusinessDays(period.getDays(), payAdjustment.getCalendar()));
/** * Resolves this adjustment using the specified reference data, returning an adjuster. * <p> * This returns a {@link DateAdjuster} that performs the same calculation as this adjustment. * It binds the holiday calendar, looked up from the reference data, into the result. * As such, there is no need to pass the reference data in again. * <p> * The resulting adjuster will be {@link #normalized() normalized}. * * @param refData the reference data, used to find the holiday calendar * @return the adjuster, bound to a specific holiday calendar */ @Override public DateAdjuster resolve(ReferenceData refData) { HolidayCalendar holCalAdj = adjustment.getCalendar().resolve(refData); if (calendar == HolidayCalendarIds.NO_HOLIDAYS) { BusinessDayConvention adjustmentConvention = adjustment.getConvention(); return date -> adjustmentConvention.adjust(LocalDateUtils.plusDays(date, days), holCalAdj); } HolidayCalendar holCalAdd = calendar.resolve(refData); BusinessDayConvention adjustmentConvention = adjustment.getConvention(); return date -> adjustmentConvention.adjust(holCalAdd.shift(date, days), holCalAdj); }
resolvedDate = bda1.adjust(baseDate.plus(period), refData); } else { LocalDate datePlusBusDays = bda1.getCalendar().resolve(refData).shift(baseDate, period.getDays()); resolvedDate = bda1.adjust(datePlusBusDays, refData);