@Test
 public void testNoSpread() {
   final AnnuityCouponIborDefinition definition =
       AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, MATURITY_DATE, NOTIONAL, INDEX, IS_PAYER);
   final CouponIborDefinition[] noSpreadCoupons = definition.getPayments();
   final int n = noSpreadCoupons.length;
   final double spread = 0.01;
   final CouponIborSpreadDefinition[] spreadCoupons = new CouponIborSpreadDefinition[n];
   for (int i = 0; i < n; i++) {
     final CouponIborDefinition coupon = noSpreadCoupons[i];
     spreadCoupons[i] =
         new CouponIborSpreadDefinition(
             coupon.getCurrency(),
             coupon.getPaymentDate(),
             coupon.getAccrualStartDate(),
             coupon.getAccrualEndDate(),
             coupon.getPaymentYearFraction(),
             coupon.getNotional(),
             coupon.getFixingDate(),
             coupon.getIndex(),
             spread);
   }
   assertEquals(
       definition,
       AnnuityCouponIborDefinition.from(new AnnuityCouponIborSpreadDefinition(spreadCoupons)));
 }
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void testOneNullPayment() {
   final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length];
   // First coupon uses settlement date
   CouponFixedDefinition coupon =
       new CouponFixedDefinition(
           CUR,
           PAYMENT_DATES[0],
           SETTLEMENT_DATE,
           PAYMENT_DATES[0],
           DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]),
           NOTIONAL,
           0.0);
   ZonedDateTime fixingDate =
       ScheduleCalculator.getAdjustedDate(
           SETTLEMENT_DATE, BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
   coupons[0] = null;
   for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) {
     coupon =
         new CouponFixedDefinition(
             CUR,
             PAYMENT_DATES[loopcpn],
             PAYMENT_DATES[loopcpn - 1],
             PAYMENT_DATES[loopcpn],
             DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]),
             NOTIONAL,
             0.0);
     fixingDate =
         ScheduleCalculator.getAdjustedDate(
             PAYMENT_DATES[loopcpn - 1], BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
     coupons[loopcpn] = CouponIborDefinition.from(coupon, fixingDate, INDEX);
   }
   new AnnuityCouponIborDefinition(coupons);
 }
 @Test
 public void test() {
   final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length];
   final double sign = IS_PAYER ? -1.0 : 1.0;
   // First coupon uses settlement date
   CouponFixedDefinition coupon =
       new CouponFixedDefinition(
           CUR,
           PAYMENT_DATES[0],
           SETTLEMENT_DATE,
           PAYMENT_DATES[0],
           DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]),
           sign * NOTIONAL,
           0.0);
   ZonedDateTime fixingDate =
       ScheduleCalculator.getAdjustedDate(
           SETTLEMENT_DATE, BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
   coupons[0] = CouponIborDefinition.from(coupon, fixingDate, INDEX);
   for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) {
     coupon =
         new CouponFixedDefinition(
             CUR,
             PAYMENT_DATES[loopcpn],
             PAYMENT_DATES[loopcpn - 1],
             PAYMENT_DATES[loopcpn],
             DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]),
             sign * NOTIONAL,
             0.0);
     fixingDate =
         ScheduleCalculator.getAdjustedDate(
             PAYMENT_DATES[loopcpn - 1], BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
     coupons[loopcpn] = CouponIborDefinition.from(coupon, fixingDate, INDEX);
   }
   final AnnuityCouponIborDefinition iborAnnuity = new AnnuityCouponIborDefinition(coupons);
   //    assertEquals(iborAnnuity.getPayments(), coupons);
   assertEquals(iborAnnuity.isPayer(), IS_PAYER);
   for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) {
     assertEquals(iborAnnuity.getNthPayment(loopcpn), coupons[loopcpn]);
     assertEquals(iborAnnuity.getPayments()[loopcpn], coupons[loopcpn]);
   }
   final AnnuityCouponIborDefinition iborAnnuity2 =
       AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, INDEX, IS_PAYER);
   assertEquals(iborAnnuity, iborAnnuity2);
 }
 @Test
 public void testEqualHash() {
   final CouponIborDefinition[] coupons = new CouponIborDefinition[PAYMENT_DATES.length];
   // First coupon uses settlement date
   CouponFixedDefinition coupon =
       new CouponFixedDefinition(
           CUR,
           PAYMENT_DATES[0],
           SETTLEMENT_DATE,
           PAYMENT_DATES[0],
           DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]),
           NOTIONAL,
           0.0);
   ZonedDateTime fixingDate =
       ScheduleCalculator.getAdjustedDate(
           SETTLEMENT_DATE, BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
   coupons[0] = CouponIborDefinition.from(coupon, fixingDate, INDEX);
   for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) {
     coupon =
         new CouponFixedDefinition(
             CUR,
             PAYMENT_DATES[loopcpn],
             PAYMENT_DATES[loopcpn - 1],
             PAYMENT_DATES[loopcpn],
             DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]),
             NOTIONAL,
             0.0);
     fixingDate =
         ScheduleCalculator.getAdjustedDate(
             PAYMENT_DATES[loopcpn - 1], BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
     coupons[loopcpn] = CouponIborDefinition.from(coupon, fixingDate, INDEX);
   }
   final AnnuityCouponIborDefinition iborAnnuity = new AnnuityCouponIborDefinition(coupons);
   final AnnuityCouponIborDefinition iborAnnuity2 = new AnnuityCouponIborDefinition(coupons);
   assertEquals(iborAnnuity, iborAnnuity2);
   assertEquals(iborAnnuity.hashCode(), iborAnnuity2.hashCode());
   AnnuityCouponIborDefinition modifiedIborAnnuity =
       AnnuityCouponIborDefinition.from(SETTLEMENT_DATE, ANNUITY_TENOR, NOTIONAL, INDEX, IS_PAYER);
   assertFalse(iborAnnuity.equals(modifiedIborAnnuity));
   final CouponIborDefinition[] couponsModified = new CouponIborDefinition[PAYMENT_DATES.length];
   CouponFixedDefinition couponModified =
       new CouponFixedDefinition(
           CUR,
           PAYMENT_DATES[0],
           SETTLEMENT_DATE,
           PAYMENT_DATES[0],
           DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]),
           NOTIONAL,
           0.0);
   fixingDate =
       ScheduleCalculator.getAdjustedDate(
           SETTLEMENT_DATE, BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
   couponsModified[0] = CouponIborDefinition.from(couponModified, fixingDate, INDEX);
   for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) {
     couponModified =
         new CouponFixedDefinition(
             CUR,
             PAYMENT_DATES[loopcpn],
             PAYMENT_DATES[loopcpn - 1],
             PAYMENT_DATES[loopcpn],
             DAY_COUNT.getDayCountFraction(PAYMENT_DATES[loopcpn - 1], PAYMENT_DATES[loopcpn]),
             NOTIONAL + 5.0,
             0.0);
     fixingDate =
         ScheduleCalculator.getAdjustedDate(
             PAYMENT_DATES[loopcpn - 1], BUSINESS_DAY, CALENDAR, -SETTLEMENT_DAYS);
     couponsModified[loopcpn] = CouponIborDefinition.from(couponModified, fixingDate, INDEX);
   }
   modifiedIborAnnuity = new AnnuityCouponIborDefinition(couponsModified);
   assertFalse(iborAnnuity.equals(modifiedIborAnnuity));
 }