AnnuityCouponIborDefinition extends AnnuityCouponDefinition<CouponIborDefinition> { @Override public Annuity<? extends Coupon> toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> indexFixingTS) { ArgumentChecker.notNull(date, "date"); final List<Coupon> resultList = new ArrayList<>(); final CouponIborDefinition[] payments = getPayments(); for (int loopcoupon = 0; loopcoupon < payments.length; loopcoupon++) { if (!date.isAfter(payments[loopcoupon].getPaymentDate())) { resultList.add(payments[loopcoupon].toDerivative(date, indexFixingTS)); } } return new Annuity<>(resultList.toArray(new Coupon[resultList.size()])); } AnnuityCouponIborDefinition(final CouponIborDefinition[] payments, final IborIndex iborIndex, final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final Period tenor, final double notional, final IborIndex index, final boolean isPayer,
      final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IborIndex index, final boolean isPayer,
      final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IborIndex index, final boolean isPayer,
      final BusinessDayConvention businessDayConvention, final boolean endOfMonth, final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period paymentPeriod, final double notional, final IborIndex index,
      final boolean isPayer, final BusinessDayConvention businessDayConvention, final boolean endOfMonth, final DayCount dayCount, final Calendar calendar); static AnnuityCouponIborDefinition from(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period paymentPeriod, final double notional, final IborIndex index,
      final boolean isPayer, final BusinessDayConvention businessDayConvention, final boolean endOfMonth, final DayCount dayCount, final Calendar calendar, final StubType stub); static AnnuityCouponIborDefinition fromAccrualUnadjusted(final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final double notional, final IborIndex index,
      final boolean isPayer, final Calendar calendar); static AnnuityCouponIborDefinition from(final AnnuityCouponIborSpreadDefinition annuity); AnnuityCouponIborDefinition trimStart(final ZonedDateTime trimDate); IborIndex getIborIndex(); Calendar getIborCalendar(); @Override Annuity<? extends Coupon> toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> indexFixingTS); @Override Annuity<? extends Coupon> toDerivative(final ZonedDateTime date); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullConversionDate() { IBOR_ANNUITY.toDerivative(null, FIXING_TS); }
@Test public void testToDerivativeAfterFixing() { final Payment[] couponIborConverted = new Payment[PAYMENT_DATES.length]; ZonedDateTime date = REFERENCE_DATE.plusMonths(1); for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponIborConverted[loopcpn] = IBOR_ANNUITY.getNthPayment(loopcpn).toDerivative(date, FIXING_TS); } Annuity<Payment> referenceAnnuity = new Annuity<>(couponIborConverted); Annuity<? extends Payment> convertedDefinition = IBOR_ANNUITY.toDerivative(date, FIXING_TS); assertEquals(referenceAnnuity, convertedDefinition); assertTrue(convertedDefinition.getNthPayment(0) instanceof CouponFixed); assertEquals(((CouponFixed) convertedDefinition.getNthPayment(0)).getFixedRate(), FIXING_RATE, 0); for (int i = 1; i < PAYMENT_DATES.length; i++) { assertTrue(convertedDefinition.getNthPayment(i) instanceof CouponIbor); } date = REFERENCE_DATE; for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponIborConverted[loopcpn] = IBOR_ANNUITY.getNthPayment(loopcpn).toDerivative(date, FIXING_TS); } referenceAnnuity = new Annuity<>(couponIborConverted); convertedDefinition = IBOR_ANNUITY.toDerivative(date, FIXING_TS); assertEquals(referenceAnnuity, convertedDefinition); assertTrue(convertedDefinition.getNthPayment(0) instanceof CouponFixed); assertEquals(((CouponFixed) convertedDefinition.getNthPayment(0)).getFixedRate(), FIXING_RATE, 0); for (int i = 1; i < PAYMENT_DATES.length; i++) { assertTrue(convertedDefinition.getNthPayment(i) instanceof CouponIbor); } }
@Test public void testToDerivativeBeforeFixing() { final Payment[] couponIborConverted = new Payment[PAYMENT_DATES.length]; final ZonedDateTime date = REFERENCE_DATE.minusDays(1); for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponIborConverted[loopcpn] = IBOR_ANNUITY.getNthPayment(loopcpn).toDerivative(date, FIXING_TS); } final Annuity<Payment> referenceAnnuity = new Annuity<>(couponIborConverted); final Annuity<? extends Payment> convertedDefinition = IBOR_ANNUITY.toDerivative(date, FIXING_TS); assertEquals(referenceAnnuity, convertedDefinition); for (int i = 0; i < PAYMENT_DATES.length; i++) { assertTrue(convertedDefinition.getNthPayment(i) instanceof CouponIbor); } }