SwapMultilegDefinition implements InstrumentDefinitionWithData<SwapMultileg, ZonedDateTimeDoubleTimeSeries[]> { @Override public SwapMultileg toDerivative(ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); final int nbLegs = _legs.length; @SuppressWarnings("unchecked") final Annuity<? extends Payment>[] legs = new Annuity[nbLegs]; for (int loopleg = 0; loopleg < nbLegs; loopleg++) { legs[loopleg] = _legs[loopleg].toDerivative(date); } return new SwapMultileg(legs); } SwapMultilegDefinition(final AnnuityDefinition<? extends PaymentDefinition>[] legs); AnnuityDefinition<? extends PaymentDefinition>[] getLegs(); @Override SwapMultileg toDerivative(ZonedDateTime date); @Override SwapMultileg toDerivative(ZonedDateTime date, ZonedDateTimeDoubleTimeSeries[] data); @Override V accept(InstrumentDefinitionVisitor<U, V> visitor, U data); @Override V accept(InstrumentDefinitionVisitor<?, V> visitor); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void toDerivative() { final ZonedDateTimeDoubleTimeSeries fixingTsF = ImmutableZonedDateTimeDoubleTimeSeries.ofEmpty(ZoneId.of("UTC")); final ZonedDateTimeDoubleTimeSeries fixingTs3 = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {((CouponIborDefinition) LEGS_DEFINITION[1].getNthPayment(0)).getFixingDate() }, new double[] {0.0123 }); final ZonedDateTimeDoubleTimeSeries fixingTs6 = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {((CouponIborDefinition) LEGS_DEFINITION[2].getNthPayment(0)).getFixingDate() }, new double[] {0.0135 }); final ZonedDateTimeDoubleTimeSeries[] fixingTs = new ZonedDateTimeDoubleTimeSeries[] {fixingTsF, fixingTs3, fixingTs6 }; final ZonedDateTime referenceDateBeforeFirstFixing = REFERENCE_DATE; final SwapMultileg swapConvertedBeforeFirstFixing = SWAP_MULTI_LEG_DEFINITION.toDerivative(referenceDateBeforeFirstFixing); for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[0].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedBeforeFirstFixing.getLegs()[0].getNthPayment(loopcpn) instanceof CouponFixed); } for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[1].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedBeforeFirstFixing.getLegs()[1].getNthPayment(loopcpn) instanceof CouponIbor); } for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[2].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedBeforeFirstFixing.getLegs()[2].getNthPayment(loopcpn) instanceof CouponIbor); } for (int loopleg = 0; loopleg < NB_LEGS; loopleg++) { assertEquals("SwapMultilegDefinition: toDerivative", swapConvertedBeforeFirstFixing.getLegs()[loopleg], LEGS_DEFINITION[loopleg].toDerivative(referenceDateBeforeFirstFixing)); } final ZonedDateTime referenceDateOnFirstFixingDate = ((CouponIborDefinition) LEGS_DEFINITION[1].getNthPayment(0)).getFixingDate(); final SwapMultileg swapConvertedOnFirstFixingDateNoFixing = SWAP_MULTI_LEG_DEFINITION.toDerivative(referenceDateOnFirstFixingDate); for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[0].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateNoFixing.getLegs()[0].getNthPayment(loopcpn) instanceof CouponFixed); } for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[1].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateNoFixing.getLegs()[1].getNthPayment(loopcpn) instanceof CouponIbor); } for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[2].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateNoFixing.getLegs()[2].getNthPayment(loopcpn) instanceof CouponIbor); } final SwapMultileg swapConvertedOnFirstFixingDateFixing = SWAP_MULTI_LEG_DEFINITION.toDerivative(referenceDateOnFirstFixingDate, fixingTs); for (int loopcpn = 0; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[0].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateFixing.getLegs()[0].getNthPayment(loopcpn) instanceof CouponFixed); } assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateFixing.getLegs()[1].getNthPayment(0) instanceof CouponFixed); for (int loopcpn = 1; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[1].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateFixing.getLegs()[1].getNthPayment(loopcpn) instanceof CouponIbor); } assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateFixing.getLegs()[2].getNthPayment(0) instanceof CouponFixed); for (int loopcpn = 1; loopcpn < swapConvertedBeforeFirstFixing.getLegs()[2].getNumberOfPayments(); loopcpn++) { assertTrue("SwapMultilegDefinition: toDerivative", swapConvertedOnFirstFixingDateFixing.getLegs()[2].getNthPayment(loopcpn) instanceof CouponIbor); } }