CapFloorCMSDefinition 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 " + getFixingDate() + " " + 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, _underlyingSwap.getFixedLeg().getNthPayment(0).getAccrualStartDate()); final SwapFixedCoupon<Coupon> swap = _underlyingSwap.toDerivative(date); return new CapFloorCMS(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), fixingTime, swap, settlementTime, _strike, _isCap); } CapFloorCMSDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor,
      final double notional, final ZonedDateTime fixingDate, final SwapFixedIborDefinition underlyingSwap, final IndexSwap cmsIndex, final double strike, final boolean isCap); static CapFloorCMSDefinition from(final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor,
      final double notional, final ZonedDateTime fixingDate, final SwapFixedIborDefinition underlyingSwap, final IndexSwap cmsIndex, final double strike, final boolean isCap); static CapFloorCMSDefinition from(final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor,
      final double notional, final IndexSwap cmsIndex, final double strike, final boolean isCap, final Calendar calendar); static CapFloorCMSDefinition from(final CouponCMSDefinition coupon, final double strike, final boolean isCap); SwapFixedIborDefinition getUnderlyingSwap(); IndexSwap getCMSIndex(); @Override double getStrike(); @Override boolean isCap(); @Override double payOff(final double fixing); @Override Coupon toDerivative(final ZonedDateTime date); @Override Coupon toDerivative(final ZonedDateTime dateTime, final DoubleTimeSeries<ZonedDateTime> indexFixingTimeSeries); @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);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testConversionNullDate1() { CMS_CAP_DEFINITION.toDerivative(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testConversionNullDate2() { CMS_CAP_DEFINITION.toDerivative(null, HIGH_FIXING_TS); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testConversionNoTS() { CMS_CAP_DEFINITION.toDerivative(FIXING_DATE.plusDays(1)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testConversionNullTS() { CMS_CAP_DEFINITION.toDerivative(FIXING_DATE.plusDays(1), (DoubleTimeSeries<ZonedDateTime>) null); }
@Test public void testToDerivative() { final CapFloorCMS cmsCap = (CapFloorCMS) CMS_CAP_DEFINITION.toDerivative(REFERENCE_DATE); final CouponCMS cmsCoupon = (CouponCMS) CMS_COUPON_DEFINITION.toDerivative(REFERENCE_DATE); final CapFloorCMS capDirect = CapFloorCMS.from(cmsCoupon, STRIKE, IS_CAP); assertEquals(capDirect, cmsCap); }