public void test_of_LocalDateEomTrue() { PeriodicSchedule test = PeriodicSchedule.of(JUN_04, SEP_17, P1M, BDA, SHORT_FINAL, true); assertEquals(test.getStartDate(), JUN_04); assertEquals(test.getEndDate(), SEP_17); assertEquals(test.getFrequency(), P1M); assertEquals(test.getBusinessDayAdjustment(), BDA); assertEquals(test.getStartDateBusinessDayAdjustment(), Optional.empty()); assertEquals(test.getEndDateBusinessDayAdjustment(), Optional.empty()); assertEquals(test.getStubConvention(), Optional.of(SHORT_FINAL)); assertEquals(test.getRollConvention(), Optional.of(EOM)); assertEquals(test.getFirstRegularStartDate(), Optional.empty()); assertEquals(test.getLastRegularEndDate(), Optional.empty()); assertEquals(test.getOverrideStartDate(), Optional.empty()); assertEquals(test.calculatedRollConvention(), DAY_4); assertEquals(test.calculatedFirstRegularStartDate(), JUN_04); assertEquals(test.calculatedLastRegularEndDate(), SEP_17); assertEquals(test.calculatedStartDate(), AdjustableDate.of(JUN_04, BDA)); assertEquals(test.calculatedEndDate(), AdjustableDate.of(SEP_17, BDA)); }
/** * Resolves this schedule using the specified reference data. * <p> * Calling this method binds the reference data and roll convention, returning a * function that can convert a {@code SchedulePeriod} to an {@code FxReset}. * <p> * The reset schedule is created within the bounds of the specified accrual period. * The reset frequency is added repeatedly to the unadjusted start date of the period * in order to generate the schedule, potentially leaving a short final stub. * The dates are adjusted using the specified roll convention and the business * day adjustment of this class. * * @param rollConvention the applicable roll convention * @param refData the reference data to use when resolving * @return the reset schedule * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data * @throws RuntimeException if the schedule is invalid */ Function<SchedulePeriod, Schedule> createSchedule(RollConvention rollConvention, ReferenceData refData) { return accrualPeriod -> accrualPeriod.subSchedule( resetFrequency, rollConvention, StubConvention.SHORT_FINAL, businessDayAdjustment).createSchedule(refData); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(PeriodicSchedule beanToCopy) { this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.frequency = beanToCopy.getFrequency(); this.businessDayAdjustment = beanToCopy.getBusinessDayAdjustment(); this.startDateBusinessDayAdjustment = beanToCopy.startDateBusinessDayAdjustment; this.endDateBusinessDayAdjustment = beanToCopy.endDateBusinessDayAdjustment; this.stubConvention = beanToCopy.stubConvention; this.rollConvention = beanToCopy.rollConvention; this.firstRegularStartDate = beanToCopy.firstRegularStartDate; this.lastRegularEndDate = beanToCopy.lastRegularEndDate; this.overrideStartDate = beanToCopy.overrideStartDate; }
/** * Gets the applicable roll convention defining how to roll dates. * <p> * The schedule periods are determined at the high level by repeatedly adding * the frequency to the start date, or subtracting it from the end date. * The roll convention provides the detailed rule to adjust the day-of-month or day-of-week. * <p> * The applicable roll convention is a non-null value. * If the roll convention property is not present, this is determined from the * stub convention, dates and frequency, defaulting to 'None' if necessary. * * @return the non-null roll convention */ public RollConvention calculatedRollConvention() { return calculatedRollConvention(calculatedFirstRegularStartDate(), calculatedLastRegularEndDate()); }
private List<LocalDate> applyBusinessDayAdjustment(List<LocalDate> unadj, ReferenceData refData) { List<LocalDate> adj = new ArrayList<>(unadj.size()); adj.add(calculatedStartDate().adjusted(refData)); for (int i = 1; i < unadj.size() - 1; i++) { adj.add(businessDayAdjustment.adjust(unadj.get(i), refData)); } adj.add(calculatedEndDate().adjusted(refData)); return adj; }
LocalDate firstRegularStartDate = LocalDate.of(2018, 6, 20); PeriodicSchedule scheduleDefinition = PeriodicSchedule.builder() .startDate(startDate) .endDate(endDate) .build(); Schedule schedule = scheduleDefinition.createSchedule(REF_DATA); assertEquals(schedule.size(), 5);
@Test(expectedExceptions = ScheduleException.class) public void test_both_badStub() { PeriodicSchedule defn = PeriodicSchedule.builder() .startDate(JUN_17) .endDate(SEP_17) .frequency(P1M) .businessDayAdjustment(BDA) .stubConvention(STUB_BOTH) .rollConvention(null) .firstRegularStartDate(JUN_17) .lastRegularEndDate(SEP_17) .build(); defn.createUnadjustedDates(); }
public void coverage_builder() { PeriodicSchedule test = PeriodicSchedule.builder() .startDate(JUL_17) .endDate(SEP_17) .frequency(P2M) .businessDayAdjustment(BDA_NONE) .startDateBusinessDayAdjustment(BDA_NONE) .endDateBusinessDayAdjustment(BDA_NONE) .stubConvention(STUB_NONE) .rollConvention(EOM) .firstRegularStartDate(JUL_17) .lastRegularEndDate(SEP_17) .overrideStartDate(AdjustableDate.of(JUL_11)) .build(); assertEquals(test.getStartDate(), JUL_17); assertEquals(test.getEndDate(), SEP_17); assertEquals(test.calculatedStartDate(), AdjustableDate.of(JUL_11, BDA_NONE)); assertEquals(test.calculatedEndDate(), AdjustableDate.of(SEP_17, BDA_NONE)); }
public void test_createTrade() { DatesCdsTemplate base = DatesCdsTemplate.of(START, END, CONV1); LocalDate tradeDate = LocalDate.of(2015, 5, 5); CdsTrade test = base.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, REF_DATA); Cds expected = Cds.of(BUY, LEGAL_ENTITY, CONV1.getCurrency(), NOTIONAL_2M, START, END, Frequency.P3M, CONV1.getSettlementDateOffset().getCalendar(), 0.05d); PeriodicSchedule sch1 = expected.getPaymentSchedule(); expected = expected.toBuilder() .paymentSchedule(sch1.toBuilder() .startDateBusinessDayAdjustment(sch1.getBusinessDayAdjustment()) .rollConvention(RollConventions.DAY_20) .build()) .build(); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); assertEquals(test.getUpfrontFee(), Optional.empty()); }
public void test_builder_min() { CmsLeg test = sutCap(); assertEquals(test.getPayReceive(), RECEIVE); assertEquals(test.getCapSchedule().get(), CAP); assertFalse(test.getFloorSchedule().isPresent()); assertEquals(test.getCurrency(), EUR_EURIBOR_6M.getCurrency()); assertEquals(test.getNotional(), NOTIONAL); assertEquals(test.getDayCount(), EUR_EURIBOR_6M.getDayCount()); assertEquals(test.getStartDate(), AdjustableDate.of(START, SCHEDULE_EUR.getBusinessDayAdjustment())); assertEquals(test.getEndDate(), SCHEDULE_EUR.calculatedEndDate()); assertEquals(test.getIndex(), INDEX); assertEquals(test.getPaymentSchedule(), SCHEDULE_EUR); assertEquals(test.getFixingRelativeTo(), FixingRelativeTo.PERIOD_START); assertEquals(test.getFixingDateOffset(), EUR_EURIBOR_6M.getFixingDateOffset()); assertEquals(test.getPaymentDateOffset(), DaysAdjustment.NONE); }
public void test_startEndAdjust() { BusinessDayAdjustment bda1 = BusinessDayAdjustment.of(PRECEDING, SAT_SUN); BusinessDayAdjustment bda2 = BusinessDayAdjustment.of(MODIFIED_PRECEDING, SAT_SUN); PeriodicSchedule test = PeriodicSchedule.builder() .startDate(date(2014, 10, 4)) .endDate(date(2015, 4, 4)) .frequency(P3M) .businessDayAdjustment(BDA) .startDateBusinessDayAdjustment(bda1) .endDateBusinessDayAdjustment(bda2) .stubConvention(STUB_NONE) .build(); assertEquals(test.calculatedStartDate(), AdjustableDate.of(date(2014, 10, 4), bda1)); assertEquals(test.calculatedEndDate(), AdjustableDate.of(date(2015, 4, 4), bda2)); assertEquals(test.createUnadjustedDates(), list(date(2014, 10, 4), date(2015, 1, 4), date(2015, 4, 4))); assertEquals(test.createAdjustedDates(REF_DATA), list(date(2014, 10, 3), date(2015, 1, 5), date(2015, 4, 3))); }
private PeriodicSchedule createDates(LocalDate start, LocalDate end, LocalDate first, LocalDate last) { return PeriodicSchedule.builder() .startDate(start) .endDate(end) .frequency(P1M) .businessDayAdjustment(BDA) .firstRegularStartDate(first) .lastRegularEndDate(last) .build(); }
LocalDate unadjStart = calculatedUnadjustedStartDate(refData); LocalDate unadjEnd = calculatedUnadjustedEndDate(refData); LocalDate regularStart = calculatedFirstRegularStartDate(unadjStart, refData); LocalDate regularEnd = calculatedLastRegularEndDate(unadjEnd, refData); RollConvention rollConv = calculatedRollConvention(regularStart, regularEnd); List<LocalDate> unadj = generateUnadjustedDates(unadjStart, regularStart, regularEnd, unadjEnd, rollConv); List<LocalDate> adj = applyBusinessDayAdjustment(unadj, refData); List<SchedulePeriod> periods = new ArrayList<>(); try { createUnadjustedDates(); createAdjustedDates(refData);
@Override public ResolvedCapitalIndexedBond resolve(ReferenceData refData) { Schedule adjustedSchedule = accrualSchedule.createSchedule(refData); DateAdjuster exCouponPeriodAdjuster = exCouponPeriod.resolve(refData); DoubleArray resolvedGearings = .securityId(securityId) .periodicPayments(ImmutableList.copyOf(bondPeriods)) .frequency(accrualSchedule.getFrequency()) .rollConvention(accrualSchedule.calculatedRollConvention()) .dayCount(dayCount) .yieldConvention(yieldConvention)
LocalDate unadjStart = calculatedUnadjustedStartDate(refData); LocalDate unadjEnd = calculatedUnadjustedEndDate(refData); LocalDate regularStart = calculatedFirstRegularStartDate(unadjStart, refData); LocalDate regularEnd = calculatedLastRegularEndDate(unadjEnd, refData); RollConvention rollConv = calculatedRollConvention(regularStart, regularEnd); List<LocalDate> unadj = generateUnadjustedDates(unadjStart, regularStart, regularEnd, unadjEnd, rollConv); List<LocalDate> adj = applyBusinessDayAdjustment(unadj, refData);
public void test_of_LocalDateRoll_null() { assertThrowsIllegalArg(() -> PeriodicSchedule.of(null, SEP_17, P1M, BDA, SHORT_INITIAL, DAY_17)); assertThrowsIllegalArg(() -> PeriodicSchedule.of(JUN_04, null, P1M, BDA, SHORT_INITIAL, DAY_17)); assertThrowsIllegalArg(() -> PeriodicSchedule.of(JUN_04, SEP_17, null, BDA, SHORT_INITIAL, DAY_17)); assertThrowsIllegalArg(() -> PeriodicSchedule.of(JUN_04, SEP_17, P1M, null, SHORT_INITIAL, DAY_17)); assertThrowsIllegalArg(() -> PeriodicSchedule.of(JUN_04, SEP_17, P1M, BDA, null, DAY_17)); assertThrowsIllegalArg(() -> PeriodicSchedule.of(JUN_04, SEP_17, P1M, BDA, SHORT_INITIAL, null)); }
static ResolvedCapitalIndexedBond sut() { return ResolvedCapitalIndexedBond.builder() .securityId(CapitalIndexedBondTest.sut().getSecurityId()) .dayCount(ACT_ACT_ISDA) .legalEntityId(LEGAL_ENTITY) .nominalPayment(NOMINAL) .periodicPayments(PERIODIC) .frequency(CapitalIndexedBondTest.sut().getAccrualSchedule().getFrequency()) .rollConvention(CapitalIndexedBondTest.sut().getAccrualSchedule().calculatedRollConvention()) .settlementDateOffset(SETTLE_OFFSET) .yieldConvention(US_IL_REAL) .rateCalculation(RATE_CALC) .build(); }
@Override public ResolvedCds resolve(ReferenceData refData) { Schedule adjustedSchedule = paymentSchedule.createSchedule(refData); ImmutableList.Builder<CreditCouponPaymentPeriod> accrualPeriods = ImmutableList.builder(); int nPeriods = adjustedSchedule.size(); .effectiveStartDate(protectionStart.isBeginning() ? lastPeriod.getStartDate().minusDays(1) : lastPeriod.getStartDate()) .effectiveEndDate(lastPeriod.getEndDate()) .paymentDate(paymentSchedule.getBusinessDayAdjustment().adjust(lastPeriod.getEndDate(), refData)) .notional(notional) .currency(currency)
@Test(expectedExceptions = ScheduleException.class, expectedExceptionsMessageRegExp = ".*duplicate adjusted dates.*") public void test_emptyWhenAdjusted_term_createAdjustedDates() { PeriodicSchedule defn = PeriodicSchedule.builder() .startDate(date(2015, 5, 29)) .endDate(date(2015, 5, 31)) .frequency(TERM) .businessDayAdjustment(BDA) .stubConvention(null) .rollConvention(null) .firstRegularStartDate(null) .lastRegularEndDate(null) .build(); defn.createAdjustedDates(REF_DATA); }
private static RateCalculationSwapLeg parseLeg( CsvRow row, String leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount) { PayReceive payReceive = LoaderUtils.parsePayReceive(getValue(row, leg, DIRECTION_FIELD)); PeriodicSchedule accrualSch = parseAccrualSchedule(row, leg); PaymentSchedule paymentSch = parsePaymentSchedule(row, leg, accrualSch.getFrequency()); NotionalSchedule notionalSch = parseNotionalSchedule(row, leg); RateCalculation calc = parseRateCalculation( row, leg, index, defaultFixedLegDayCount, accrualSch.getBusinessDayAdjustment(), notionalSch.getCurrency()); return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(accrualSch) .paymentSchedule(paymentSch) .notionalSchedule(notionalSch) .calculation(calc) .build(); }