CapFloorCMSSpreadDefinition extends CouponFloatingDefinition implements CapFloor { @Override public Coupon toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); ArgumentChecker.isTrue(date.isBefore(getFixingDate()), "Do not have any fixing data but are asking for a derivative after the fixing date"); ArgumentChecker.isTrue(!date.isAfter(getPaymentDate()), "date is after payment date"); final double paymentTime = TimeCalculator.getTimeBetween(date, getPaymentDate()); final double fixingTime = TimeCalculator.getTimeBetween(date, getFixingDate()); final double settlementTime = TimeCalculator.getTimeBetween(date, _underlyingSwap1.getFixedLeg().getNthPayment(0).getAccrualStartDate()); final SwapFixedCoupon<Coupon> swap1 = _underlyingSwap1.toDerivative(date); final SwapFixedCoupon<Coupon> swap2 = _underlyingSwap2.toDerivative(date); return new CapFloorCMSSpread(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), fixingTime, swap1, _cmsIndex1, swap2, _cmsIndex2, settlementTime, _strike, _isCap); } CapFloorCMSSpreadDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor,
      final double notional, final ZonedDateTime fixingDate, final SwapFixedIborDefinition underlyingSwap1, final IndexSwap cmsIndex1, final SwapFixedIborDefinition underlyingSwap2,
      final IndexSwap cmsIndex2, final double strike, final boolean isCap, final Calendar calendar1, final Calendar calendar2); static CapFloorCMSSpreadDefinition from(final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor,
      final double notional, final IndexSwap cmsIndex1, final IndexSwap cmsIndex2, final double strike, final boolean isCap, final Calendar calendar1, final Calendar calendar2); SwapFixedIborDefinition getUnderlyingSwap1(); IndexSwap getCmsIndex1(); SwapFixedIborDefinition getUnderlyingSwap2(); IndexSwap getCmsIndex2(); @Override double getStrike(); @Override boolean isCap(); @Override /** * The "fixing" is the difference between the first and the second CMS rates fixings. */ double payOff(final double fixing); @Override V accept(final InstrumentDefinitionVisitor<U, V> visitor, final U data); @Override V accept(final InstrumentDefinitionVisitor<?, V> visitor); @Override int hashCode(); @Override boolean equals(final Object obj); @Override Coupon toDerivative(final ZonedDateTime date); @Override Coupon toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> data);  }
@Test public void testToDerivative() { final SwapFixedCoupon<? extends Payment> swap1 = SWAP_DEFINITION_1.toDerivative(REFERENCE_DATE); final SwapFixedCoupon<? extends Payment> swap2 = SWAP_DEFINITION_2.toDerivative(REFERENCE_DATE); final CapFloorCMSSpread cmsSpread = (CapFloorCMSSpread) CMS_SPREAD_DEFINITION.toDerivative(REFERENCE_DATE); assertEquals(swap1, cmsSpread.getUnderlyingSwap1()); assertEquals(swap2, cmsSpread.getUnderlyingSwap2()); final CapFloorCMSSpread cmsSpreadExpected = new CapFloorCMSSpread(CUR, PAYMENT_TIME, PAYMENT_ACCRUAL_FACTOR, NOTIONAL, FIXING_TIME, swap1, CMS_INDEX_1, swap2, CMS_INDEX_2, SETTLEMENT_TIME, STRIKE, IS_CAP); assertEquals("CMS Spread to derivatives", cmsSpreadExpected, cmsSpread); }