public void test_SHORT_FINAL() { assertEquals(SHORT_FINAL.isCalculateForwards(), true); assertEquals(SHORT_FINAL.isCalculateBackwards(), false); assertEquals(SHORT_FINAL.isLong(), false); assertEquals(SHORT_FINAL.isShort(), true); assertEquals(SHORT_FINAL.isSmart(), false); }
@Test(dataProvider = "isStubLong") public void test_isStubLong( StubConvention conv, LocalDate date1, LocalDate date2, Boolean expected) { if (expected == null) { assertThrowsIllegalArg(() -> conv.isStubLong(date1, date2)); } else { assertEquals(conv.isStubLong(date1, date2), expected.booleanValue()); } }
@Test(dataProvider = "name") public void test_of_lookup(StubConvention convention, String name) { assertEquals(StubConvention.of(name), convention); }
if (isCalculateBackwards()) { return impliedRollConvention(end, start, frequency, preferEndOfMonth); } else { return impliedRollConvention(start, end, frequency, preferEndOfMonth);
private RollConvention calculatedRollConvention( LocalDate calculatedFirstRegStartDate, LocalDate calculatedLastRegEndDate) { // determine roll convention from stub convention StubConvention stubConv = MoreObjects.firstNonNull(stubConvention, StubConvention.NONE); // special handling for EOM as it is advisory rather than mandatory if (rollConvention == RollConventions.EOM) { RollConvention derived = stubConv.toRollConvention(calculatedFirstRegStartDate, calculatedLastRegEndDate, frequency, true); return (derived == RollConventions.NONE ? RollConventions.EOM : derived); } // avoid RollConventions.NONE if possible if (rollConvention == null || rollConvention == RollConventions.NONE) { return stubConv.toRollConvention(calculatedFirstRegStartDate, calculatedLastRegEndDate, frequency, false); } // use RollConventions.NONE if nothing else applies return MoreObjects.firstNonNull(rollConvention, RollConventions.NONE); }
private StubConvention generateImplicitStubConvention(boolean explicitInitialStub, boolean explicitFinalStub) { // null is not same as NONE // NONE validates that there are no explicit stubs // null ensures that remainder after explicit stubs are removed has no stubs if (stubConvention != null) { return stubConvention.toImplicit(this, explicitInitialStub, explicitFinalStub); } return StubConvention.NONE; }
LocalDate end) { if (stubCnv.isCalculateBackwards()) {
@ImmutableConstructor private IborCapFloorLeg( PayReceive payReceive, PeriodicSchedule paymentSchedule, DaysAdjustment paymentDateOffset, Currency currency, ValueSchedule notional, IborRateCalculation calculation, ValueSchedule capSchedule, ValueSchedule floorSchedule) { this.payReceive = ArgChecker.notNull(payReceive, "payReceive"); this.paymentSchedule = ArgChecker.notNull(paymentSchedule, "paymentSchedule"); this.paymentDateOffset = ArgChecker.notNull(paymentDateOffset, "paymentDateOffset"); this.currency = currency != null ? currency : calculation.getIndex().getCurrency(); this.notional = notional; this.calculation = ArgChecker.notNull(calculation, "calculation"); this.capSchedule = capSchedule; this.floorSchedule = floorSchedule; ArgChecker.isTrue(!this.getPaymentSchedule().getStubConvention().isPresent() || this.getPaymentSchedule().getStubConvention().get().equals(StubConvention.NONE), "Stub period is not allowed"); ArgChecker.isFalse(this.getCapSchedule().isPresent() == this.getFloorSchedule().isPresent(), "One of cap schedule and floor schedule should be empty"); ArgChecker.isTrue(this.getCalculation().getIndex().getTenor().getPeriod().equals(this.getPaymentSchedule() .getFrequency().getPeriod()), "Payment frequency period should be the same as index tenor period"); }
@Test(dataProvider = "roll") public void test_toRollConvention( StubConvention conv, LocalDate start, LocalDate end, Frequency freq, boolean eom, RollConvention expected) { assertEquals(conv.toRollConvention(start, end, freq, eom), expected); }
@Test(dataProvider = "implicit") public void test_toImplicit( StubConvention conv, boolean initialStub, boolean finalStub, StubConvention expected) { if (expected == null) { assertThrowsIllegalArg(() -> conv.toImplicit(null, initialStub, finalStub)); } else { assertEquals(conv.toImplicit(null, initialStub, finalStub), expected); } }
this.floorSchedule = floorSchedule; ArgChecker.isTrue(!this.getPaymentSchedule().getStubConvention().isPresent() || this.getPaymentSchedule().getStubConvention().get().equals(StubConvention.NONE), "Stub period is not allowed"); ArgChecker.isFalse(this.getCapSchedule().isPresent() && this.getFloorSchedule().isPresent(), "At least one of cap schedule and floor schedule should be empty");
public void test_LONG_INITIAL() { assertEquals(LONG_INITIAL.isCalculateForwards(), false); assertEquals(LONG_INITIAL.isCalculateBackwards(), true); assertEquals(LONG_INITIAL.isLong(), true); assertEquals(LONG_INITIAL.isShort(), false); assertEquals(LONG_INITIAL.isSmart(), false); }
@Test(dataProvider = "name") public void test_of_lookupUpperCase(StubConvention convention, String name) { assertEquals(StubConvention.of(name.toUpperCase(Locale.ENGLISH)), convention); }
schedule, "Period '{}' to '{}' resulted in a disallowed stub with frequency '{}'", start, end, frequency); if (stubConv.isStubLong(dates.get(dates.size() - 1), end)) { dates.remove(dates.size() - 1);
@Test(dataProvider = "types") public void test_null(StubConvention type) { assertThrowsIllegalArg(() -> type.toRollConvention(null, date(2014, JULY, 1), Frequency.P3M, true)); assertThrowsIllegalArg(() -> type.toRollConvention(date(2014, JULY, 1), null, Frequency.P3M, true)); assertThrowsIllegalArg(() -> type.toRollConvention(date(2014, JULY, 1), date(2014, OCTOBER, 1), null, true)); }
public void test_BOTH() { assertEquals(BOTH.isCalculateForwards(), false); assertEquals(BOTH.isCalculateBackwards(), false); assertEquals(BOTH.isLong(), false); assertEquals(BOTH.isShort(), false); assertEquals(BOTH.isSmart(), false); }
@Test(dataProvider = "name") public void test_of_lookupLowerCase(StubConvention convention, String name) { assertEquals(StubConvention.of(name.toLowerCase(Locale.ENGLISH)), convention); }
private static List<LocalDate> generateBackwards( PeriodicSchedule schedule, LocalDate start, LocalDate end, Frequency frequency, RollConvention rollConv, StubConvention stubConv, LocalDate explicitStartDate) { // validate if (rollConv.matches(end) == false) { throw new ScheduleException( schedule, "Date '{}' does not match roll convention '{}' when starting to roll backwards", end, rollConv); } // generate BackwardsList dates = new BackwardsList(estimateNumberPeriods(start, end, frequency)); dates.addFirst(end); LocalDate temp = rollConv.previous(end, frequency); while (temp.isAfter(start)) { dates.addFirst(temp); temp = rollConv.previous(temp, frequency); } // convert to long stub, but only if we actually have a stub boolean stub = temp.equals(start) == false; if (stub && dates.size() > 1 && stubConv.isStubLong(start, dates.get(0))) { dates.removeFirst(); } dates.addFirst(explicitStartDate); return dates; }
public void test_NONE() { assertEquals(NONE.isCalculateForwards(), true); assertEquals(NONE.isCalculateBackwards(), false); assertEquals(NONE.isLong(), false); assertEquals(NONE.isShort(), false); assertEquals(NONE.isSmart(), false); }
public void test_of_lookup_notFound() { assertThrowsIllegalArg(() -> StubConvention.of("Rubbish")); }