CouponIborGearingDefinition extends CouponFloatingDefinition { @Override public CouponIborGearing toDerivative(final ZonedDateTime dateTime) { ArgumentChecker.notNull(dateTime, "date"); final LocalDate dayConversion = dateTime.toLocalDate(); ArgumentChecker.isTrue(!dayConversion.isAfter(getFixingDate().toLocalDate()), "Do not have any fixing data but are asking for a derivative after the fixing date " + getFixingDate() + " " + dateTime); ArgumentChecker.isTrue(!dayConversion.isAfter(getPaymentDate().toLocalDate()), "date is after payment date"); final double paymentTime = TimeCalculator.getTimeBetween(dateTime, getPaymentDate()); final double fixingTime = TimeCalculator.getTimeBetween(dateTime, getFixingDate()); final double fixingPeriodStartTime = TimeCalculator.getTimeBetween(dateTime, getFixingPeriodStartDate()); final double fixingPeriodEndTime = TimeCalculator.getTimeBetween(dateTime, getFixingPeriodEndDate()); return new CouponIborGearing(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), fixingTime, getIndex(), fixingPeriodStartTime, fixingPeriodEndTime, getFixingPeriodAccrualFactor(), _spread, _factor); } CouponIborGearingDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor,
      final double notional, final ZonedDateTime fixingDate, final IborIndex index, final double spread, final double factor, final Calendar calendar);  CouponIborGearingDefinition(
      Currency currency,
      ZonedDateTime paymentDate,
      ZonedDateTime accrualStartDate,
      ZonedDateTime accrualEndDate,
      double accrualFactor,
      double notional,
      ZonedDateTime fixingDate,
      IborIndex index,
      ZonedDateTime fixingPeriodStartDate,
      ZonedDateTime fixingPeriodEndDate,
      double fixingPeriodAccrualFactor,
      double spread,
      double factor); static CouponIborGearingDefinition from(final CouponIborDefinition couponIbor, final double spread, final double factor); static CouponIborGearingDefinition from(final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double accrualFactor, final double notional, final IborIndex index,
      final double spread, final double factor, final Calendar calendar); IborIndex getIndex(); ZonedDateTime getFixingPeriodStartDate(); ZonedDateTime getFixingPeriodEndDate(); double getFixingPeriodAccrualFactor(); double getSpread(); double getSpreadAmount(); double getFactor(); @Override CouponIborGearing toDerivative(final ZonedDateTime dateTime); @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 String toString(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void testToDerivativeBeforeFixing() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2010, 12, 27, 9, 0); final double paymentTime = TimeCalculator.getTimeBetween(referenceDate, ACCRUAL_END_DATE); final double fixingTime = TimeCalculator.getTimeBetween(referenceDate, FIXING_DATE); final double fixingPeriodStartTime = TimeCalculator.getTimeBetween(referenceDate, FIXING_START_DATE); final double fixingPeriodEndTime = TimeCalculator.getTimeBetween(referenceDate, FIXING_END_DATE); final CouponIborGearing coupon = new CouponIborGearing(CUR, paymentTime, ACCRUAL_FACTOR, NOTIONAL, fixingTime, INDEX, fixingPeriodStartTime, fixingPeriodEndTime, FIXING_ACCRUAL_FACTOR, SPREAD, FACTOR); Payment couponConverted = COUPON_DEFINITION.toDerivative(referenceDate); assertEquals(coupon, couponConverted); couponConverted = COUPON_DEFINITION.toDerivative(referenceDate, FIXING_TS); assertEquals("CouponIborGearingDefinition: toDerivative", coupon, couponConverted); }
@Test public void testToDerivativeAfterFixing() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 5, 23); final double paymentTime = TimeCalculator.getTimeBetween(referenceDate, ACCRUAL_END_DATE); final CouponFixed coupon = new CouponFixed(CUR, paymentTime, ACCRUAL_FACTOR, NOTIONAL, FIXING_RATE * FACTOR + SPREAD); final Payment couponConverted = COUPON_DEFINITION.toDerivative(referenceDate, FIXING_TS); assertEquals("CouponIborGearingDefinition: toDerivative", coupon, couponConverted); }
@Test public void testToDerivativeOnFixing() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 5, 19, 9, 0); final double paymentTime = TimeCalculator.getTimeBetween(referenceDate, ACCRUAL_END_DATE); final double fixingTime = TimeCalculator.getTimeBetween(referenceDate, FIXING_DATE); final double fixingPeriodStartTime = TimeCalculator.getTimeBetween(referenceDate, FIXING_START_DATE); final double fixingPeriodEndTime = TimeCalculator.getTimeBetween(referenceDate, FIXING_END_DATE); final CouponFixed coupon = new CouponFixed(CUR, paymentTime, ACCRUAL_FACTOR, NOTIONAL, FIXING_RATE * FACTOR + SPREAD); final Payment couponConverted = COUPON_DEFINITION.toDerivative(referenceDate, FIXING_TS); assertEquals(coupon, couponConverted); final DoubleTimeSeries<ZonedDateTime> fixingTS2 = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {ScheduleCalculator.getAdjustedDate(FIXING_DATE, -1, CALENDAR) }, new double[] {FIXING_RATE }); final CouponIborGearing coupon2 = new CouponIborGearing(CUR, paymentTime, ACCRUAL_FACTOR, NOTIONAL, fixingTime, INDEX, fixingPeriodStartTime, fixingPeriodEndTime, FIXING_ACCRUAL_FACTOR, SPREAD, FACTOR); final Payment couponConverted2 = COUPON_DEFINITION.toDerivative(referenceDate, fixingTS2); assertEquals("CouponIborGearingDefinition: toDerivative", coupon2, couponConverted2); final Payment couponConverted3 = COUPON_DEFINITION.toDerivative(referenceDate); assertEquals("CouponIborGearingDefinition: toDerivative", coupon2, couponConverted3); }