AnnuityCouponFixedDefinition extends AnnuityDefinition<CouponFixedDefinition> { @Override public AnnuityCouponFixed toDerivative(final ZonedDateTime date) { final List<CouponFixed> resultList = new ArrayList<>(); for (int loopcoupon = 0; loopcoupon < getPayments().length; loopcoupon++) { if (!date.isAfter(getNthPayment(loopcoupon).getPaymentDate())) { resultList.add(getNthPayment(loopcoupon).toDerivative(date)); } } return new AnnuityCouponFixed(resultList.toArray(new CouponFixed[resultList.size()])); } AnnuityCouponFixedDefinition(final CouponFixedDefinition[] payments, final Calendar calendar); static AnnuityCouponFixedDefinition from(final Currency currency, final ZonedDateTime settlementDate, final Period tenor, final Period paymentPeriod, final Calendar calendar,
      final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM, final double notional, final double fixedRate, final boolean isPayer); static AnnuityCouponFixedDefinition from(final Currency currency, final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period paymentPeriod, final Calendar calendar,
      final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM, final double notional, final double fixedRate, final boolean isPayer); static AnnuityCouponFixedDefinition from(final Currency currency, final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period paymentPeriod, final Calendar calendar,
      final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM, final double notional, final double fixedRate, final boolean isPayer, final StubType stub); static AnnuityCouponFixedDefinition from(final Currency currency, final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Frequency frequency, final Calendar calendar,
      final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM, final double notional, final double fixedRate, final boolean isPayer); static AnnuityCouponFixedDefinition from(final Currency currency, final ZonedDateTime settlementDate, final ZonedDateTime[] paymentDatesUnadjusted, final Frequency frequency,
      final Calendar calendar, final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM, final double notional, final double fixedRate, final boolean isPayer); static AnnuityCouponFixedDefinition from(final ZonedDateTime settlementDate, final Period tenor, final GeneratorSwapFixedIbor generator, final double notional, final double fixedRate,
      final boolean isPayer); static AnnuityCouponFixedDefinition fromAccrualUnadjusted(final Currency currency, final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period period,
      final boolean stubShort, final boolean fromEnd, final Calendar calendar, final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM, final double notional,
      final double fixedRate, final boolean isPayer); static AnnuityCouponFixedDefinition fromAccrualUnadjusted(final Currency currency, final ZonedDateTime settlementDate, final ZonedDateTime maturityDate, final Period period,
      final int nbPaymentPerYear, final boolean stubShort, final boolean fromEnd, final Calendar calendar, final DayCount dayCount, final BusinessDayConvention businessDay, final boolean isEOM,
      final double notional, final double fixedRate, final boolean isPayer); @Override AnnuityCouponFixedDefinition trimBefore(final ZonedDateTime trimDate); AnnuityCouponFixedDefinition trimStart(final ZonedDateTime trimDate); @Override AnnuityCouponFixed toDerivative(final ZonedDateTime date); AnnuityCouponFixedDefinition withRate(final double rate);  }
@Test public void testToDerivative() { final double sign = IS_PAYER ? -1.0 : 1.0; final CouponFixedDefinition[] coupons = new CouponFixedDefinition[PAYMENT_DATES.length]; coupons[0] = new CouponFixedDefinition(CUR, PAYMENT_DATES[0], SETTLEMENT_DATE, PAYMENT_DATES[0], DAY_COUNT.getDayCountFraction(SETTLEMENT_DATE, PAYMENT_DATES[0]), sign * NOTIONAL, RATE); for (int loopcpn = 1; loopcpn < PAYMENT_DATES.length; loopcpn++) { coupons[loopcpn] = 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, RATE); } final AnnuityCouponFixedDefinition fixedAnnuity = new AnnuityCouponFixedDefinition(coupons, CALENDAR); final CouponFixed[] couponFixedConverted = new CouponFixed[PAYMENT_DATES.length]; for (int loopcpn = 0; loopcpn < PAYMENT_DATES.length; loopcpn++) { couponFixedConverted[loopcpn] = fixedAnnuity.getNthPayment(loopcpn).toDerivative(REFERENCE_DATE); } final AnnuityCouponFixed referenceAnnuity = new AnnuityCouponFixed(couponFixedConverted); final AnnuityCouponFixed convertedDefinition = fixedAnnuity.toDerivative(REFERENCE_DATE); assertEquals(referenceAnnuity, convertedDefinition); }