AnnuityPaymentFixedDefinition extends AnnuityDefinition<PaymentFixedDefinition> { @Override public AnnuityPaymentFixed toDerivative(final ZonedDateTime date) { final List<PaymentFixed> 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 AnnuityPaymentFixed(resultList.toArray(new PaymentFixed[resultList.size()])); } AnnuityPaymentFixedDefinition(final PaymentFixedDefinition[] payments, final Calendar calendar); @Override AnnuityPaymentFixedDefinition trimBefore(final ZonedDateTime trimDate); @Override AnnuityPaymentFixed toDerivative(final ZonedDateTime date);  }
@Test public void testConverter() { final PaymentFixedDefinition[] annuityDefinitions = new PaymentFixedDefinition[PAYMENT_DATE.length]; PaymentFixed[] payment = new PaymentFixed[PAYMENT_DATE.length]; ZonedDateTime date = DateUtils.getUTCDate(2011, 6, 19); for (int looppay = 0; looppay < PAYMENT_DATE.length; looppay++) { annuityDefinitions[looppay] = new PaymentFixedDefinition(CUR, PAYMENT_DATE[looppay], PAYMENT_AMOUNT[looppay]); payment[looppay] = annuityDefinitions[looppay].toDerivative(date); } final AnnuityPaymentFixedDefinition definition = new AnnuityPaymentFixedDefinition(annuityDefinitions, CALENDAR); AnnuityPaymentFixed annuity = new AnnuityPaymentFixed(payment); assertEquals(annuity, definition.toDerivative(date)); date = DateUtils.getUTCDate(2011, 8, 19); payment = new PaymentFixed[PAYMENT_DATE.length - 1]; for (int looppay = 0; looppay < PAYMENT_DATE.length; looppay++) { annuityDefinitions[looppay] = new PaymentFixedDefinition(CUR, PAYMENT_DATE[looppay], PAYMENT_AMOUNT[looppay]); if (looppay > 0) { payment[looppay - 1] = annuityDefinitions[looppay].toDerivative(date); } } annuity = new AnnuityPaymentFixed(payment); assertEquals(annuity, definition.toDerivative(date)); }