AnnuityCapFloorCMSSpreadDefinition extends AnnuityDefinition<CapFloorCMSSpreadDefinition> { public static AnnuityCapFloorCMSSpreadDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IndexSwap index1, final IndexSwap index2, final Period paymentPeriod, final DayCount dayCount, final boolean isPayer, final double strike, final boolean isCap, final Calendar calendar1, final Calendar calendar2) { ArgumentChecker.notNull(settlementDate, "settlement date"); ArgumentChecker.notNull(maturityDate, "maturity date"); ArgumentChecker.notNull(index1, "First index"); ArgumentChecker.notNull(index2, "Second index"); ArgumentChecker.isTrue(notional > 0, "notional <= 0"); ArgumentChecker.notNull(paymentPeriod, "Payment period"); final ZonedDateTime[] paymentDatesUnadjusted = ScheduleCalculator.getUnadjustedDateSchedule(settlementDate, maturityDate, paymentPeriod, true, false); final ZonedDateTime[] paymentDates = ScheduleCalculator.getAdjustedDateSchedule(paymentDatesUnadjusted, index1.getIborIndex().getBusinessDayConvention(), calendar1, false); final double sign = isPayer ? -1.0 : 1.0; final CapFloorCMSSpreadDefinition[] coupons = new CapFloorCMSSpreadDefinition[paymentDates.length]; coupons[0] = CapFloorCMSSpreadDefinition.from(paymentDates[0], settlementDate, paymentDates[0], dayCount.getDayCountFraction(settlementDate, paymentDates[0], calendar1), sign * notional, index1, index2, strike, isCap, calendar1, calendar2); for (int loopcpn = 1; loopcpn < paymentDates.length; loopcpn++) { coupons[loopcpn] = CapFloorCMSSpreadDefinition.from(paymentDates[loopcpn], paymentDates[loopcpn - 1], paymentDates[loopcpn], dayCount.getDayCountFraction(paymentDates[loopcpn - 1], paymentDates[loopcpn], calendar1), sign * notional, index1, index2, strike, isCap, calendar1, calendar2); } return new AnnuityCapFloorCMSSpreadDefinition(coupons, calendar1); } AnnuityCapFloorCMSSpreadDefinition(final CapFloorCMSSpreadDefinition[] payments, final Calendar calendar); static AnnuityCapFloorCMSSpreadDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IndexSwap index1, final IndexSwap index2,
      final Period paymentPeriod, final DayCount dayCount, final boolean isPayer, final double strike, final boolean isCap, final Calendar calendar1, final Calendar calendar2);  }
@Test public void dates() { final IborIndex fakeIborIndex12 = new IborIndex(CUR, LEG_PAYMENT_PERIOD, IBOR_SETTLEMENT_DAYS, LEG_DAY_COUNT, BUSINESS_DAY, IS_EOM, "Ibor"); final AnnuityCouponIborDefinition iborLeg = AnnuityCouponIborDefinition.from(START_DATE, MATURITY_DATE, NOTIONAL, fakeIborIndex12, IS_PAYER, CALENDAR); for (int loopcpn = 0; loopcpn < iborLeg.getNumberOfPayments(); loopcpn++) { assertEquals(iborLeg.getNthPayment(loopcpn).getAccrualStartDate(), CMS_SPREAD_LEG.getNthPayment(loopcpn).getAccrualStartDate()); assertEquals(iborLeg.getNthPayment(loopcpn).getAccrualEndDate(), CMS_SPREAD_LEG.getNthPayment(loopcpn).getAccrualEndDate()); assertEquals(iborLeg.getNthPayment(loopcpn).getPaymentYearFraction(), CMS_SPREAD_LEG.getNthPayment(loopcpn).getPaymentYearFraction()); assertEquals(iborLeg.getNthPayment(loopcpn).getPaymentDate(), CMS_SPREAD_LEG.getNthPayment(loopcpn).getPaymentDate()); assertEquals(iborLeg.getNthPayment(loopcpn).getFixingDate(), CMS_SPREAD_LEG.getNthPayment(loopcpn).getFixingDate()); } }
@Test public void common() { for (int loopcpn = 0; loopcpn < CMS_SPREAD_LEG.getNumberOfPayments(); loopcpn++) { assertEquals(CMS_INDEX_10, CMS_SPREAD_LEG.getNthPayment(loopcpn).getCmsIndex1()); assertEquals(CMS_INDEX_2, CMS_SPREAD_LEG.getNthPayment(loopcpn).getCmsIndex2()); assertEquals(NOTIONAL * (IS_PAYER ? -1.0 : 1.0), CMS_SPREAD_LEG.getNthPayment(loopcpn).getNotional()); assertEquals(STRIKE, CMS_SPREAD_LEG.getNthPayment(loopcpn).getStrike()); assertEquals(IS_CAP, CMS_SPREAD_LEG.getNthPayment(loopcpn).isCap()); } final AnnuityCapFloorCMSSpreadDefinition cmsCapReceiver = AnnuityCapFloorCMSSpreadDefinition.from(START_DATE, MATURITY_DATE, NOTIONAL, CMS_INDEX_10, CMS_INDEX_2, LEG_PAYMENT_PERIOD, LEG_DAY_COUNT, !IS_PAYER, STRIKE, IS_CAP, CALENDAR, CALENDAR); for (int loopcpn = 0; loopcpn < cmsCapReceiver.getNumberOfPayments(); loopcpn++) { assertEquals(CMS_INDEX_10, cmsCapReceiver.getNthPayment(loopcpn).getCmsIndex1()); assertEquals(CMS_INDEX_2, cmsCapReceiver.getNthPayment(loopcpn).getCmsIndex2()); assertEquals(-NOTIONAL * (IS_PAYER ? -1.0 : 1.0), cmsCapReceiver.getNthPayment(loopcpn).getNotional()); } }