CouponONDefinition extends CouponDefinition implements InstrumentDefinitionWithData<Payment, DoubleTimeSeries<ZonedDateTime>> { @Override public CouponON toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); final LocalDate firstPublicationDate = _fixingPeriodDate[_index.getPublicationLag()].toLocalDate(); ArgumentChecker.isTrue(date.toLocalDate().isBefore(firstPublicationDate), "toDerivative method without time series as argument is only valid at dates where the first fixing has not yet been published."); final double paymentTime = TimeCalculator.getTimeBetween(date, getPaymentDate()); final double fixingPeriodStartTime = TimeCalculator.getTimeBetween(date, _fixingPeriodDate[0]); final double fixingPeriodEndTime = TimeCalculator.getTimeBetween(date, _fixingPeriodDate[_fixingPeriodDate.length - 1]); double fixingAccrualFactorTotal = 0.0; for (final Double element : _fixingPeriodAccrualFactor) { fixingAccrualFactorTotal += element; } final CouponON cpn = new CouponON(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), _index, fixingPeriodStartTime, fixingPeriodEndTime, fixingAccrualFactorTotal, getNotional()); return cpn; } CouponONDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate,
      final double paymentYearFraction, final double notional, final IndexON index, final ZonedDateTime fixingPeriodStartDate, final ZonedDateTime fixingPeriodEndDate,
      final Calendar calendar); static CouponONDefinition from(final IndexON index, final ZonedDateTime settlementDate, final Period tenor, final double notional, final int settlementDays,
      final BusinessDayConvention businessDayConvention, final boolean isEOM, final Calendar calendar); static CouponONDefinition from(final IndexON index, final ZonedDateTime settlementDate, final ZonedDateTime fixingPeriodEndDate, final double notional,
      final int settlementDays, final Calendar calendar); IndexON getIndex(); ZonedDateTime[] getFixingPeriodDate(); Double[] getFixingPeriodAccrualFactor(); @Override CouponON toDerivative(final ZonedDateTime date); @Override Coupon toDerivative(final ZonedDateTime valZdt, 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 public void toDerivativeNoFixing() { final CouponON cpnConverted = EONIA_COUPON_DEFINITION.toDerivative(TRADE_DATE); final double paymentTime = TimeCalculator.getTimeBetween(TRADE_DATE, EUR_PAYMENT_DATE); final double fixingStartTime = TimeCalculator.getTimeBetween(TRADE_DATE, START_ACCRUAL_DATE); final double fixingEndTime = TimeCalculator.getTimeBetween(TRADE_DATE, EUR_END_ACCRUAL_DATE); final CouponON cpnExpected = new CouponON(EUR_CUR, paymentTime, EUR_PAYMENT_YEAR_FRACTION, NOTIONAL, EUR_OIS, fixingStartTime, fixingEndTime, EUR_FIXING_YEAR_FRACTION, NOTIONAL); assertEquals("CouponOISSimplified definition: toDerivative", cpnExpected, cpnConverted); }
@Test public void toDerivativeFixingBeforeStart() { final ZonedDateTime referenceDate = ScheduleCalculator.getAdjustedDate(TRADE_DATE, 1, EUR_CALENDAR); final DoubleTimeSeries<ZonedDateTime> fixingTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2011, 9, 7) }, new double[] {0.01 }); final Payment cpnConverted = EONIA_COUPON_DEFINITION.toDerivative(referenceDate, fixingTS); final double paymentTime = TimeCalculator.getTimeBetween(referenceDate, EUR_PAYMENT_DATE); final double fixingStartTime = TimeCalculator.getTimeBetween(referenceDate, START_ACCRUAL_DATE); final double fixingEndTime = TimeCalculator.getTimeBetween(referenceDate, EUR_END_ACCRUAL_DATE); final CouponON cpnExpected = new CouponON(EUR_CUR, paymentTime, EUR_PAYMENT_YEAR_FRACTION, NOTIONAL, EUR_OIS, fixingStartTime, fixingEndTime, EUR_FIXING_YEAR_FRACTION, NOTIONAL); assertEquals("CouponOISSimplified definition: toDerivative", cpnExpected, cpnConverted); }
@Test public void toDerivativeFixingOnStartNotYetFixed() { final ZonedDateTime referenceDate = SPOT_DATE; final DoubleTimeSeries<ZonedDateTime> fixingTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2011, 9, 7), DateUtils.getUTCDate(2011, 9, 8) }, new double[] { 0.01, 0.01 }); final Payment cpnConverted = EONIA_COUPON_DEFINITION.toDerivative(referenceDate, fixingTS); final double paymentTime = TimeCalculator.getTimeBetween(referenceDate, EUR_PAYMENT_DATE); final double fixingStartTime = TimeCalculator.getTimeBetween(referenceDate, START_ACCRUAL_DATE); final double fixingEndTime = TimeCalculator.getTimeBetween(referenceDate, EUR_END_ACCRUAL_DATE); final CouponON cpnExpected = new CouponON(EUR_CUR, paymentTime, EUR_PAYMENT_YEAR_FRACTION, NOTIONAL, EUR_OIS, fixingStartTime, fixingEndTime, EUR_FIXING_YEAR_FRACTION, NOTIONAL); assertEquals("CouponOISSimplified definition: toDerivative", cpnExpected, cpnConverted); }
@Test(expectedExceptions = IllegalArgumentException.class) public void toDerivativeAfterPayment() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 9, 20); final double fixingRate = 0.01; final DoubleTimeSeries<ZonedDateTime> fixingTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2011, 9, 7), DateUtils.getUTCDate(2011, 9, 8), DateUtils.getUTCDate(2011, 9, 9), DateUtils.getUTCDate(2011, 9, 12), DateUtils.getUTCDate(2011, 9, 13), DateUtils.getUTCDate(2011, 9, 14), DateUtils.getUTCDate(2011, 9, 15) }, new double[] { fixingRate, fixingRate, fixingRate, fixingRate, fixingRate, fixingRate, fixingRate }); EONIA_COUPON_DEFINITION.toDerivative(referenceDate, fixingTS); }
@Test public void toDerivativeUSDNoFixingOnFirst() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 9, 12); final double fixingRate = 0.01; final DoubleTimeSeries<ZonedDateTime> fixingTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2011, 9, 7), DateUtils.getUTCDate(2011, 9, 8) }, new double[] { fixingRate, fixingRate }); final Payment cpnConverted = OIS_COUPON_DEFINITION.toDerivative(referenceDate, fixingTS); final ZonedDateTime startFixingLeft = DateUtils.getUTCDate(2011, 9, 9); final double paymentTime = TimeCalculator.getTimeBetween(referenceDate, USD_PAYMENT_DATE); final double fixingStartTime = TimeCalculator.getTimeBetween(referenceDate, startFixingLeft); final double fixingEndTime = TimeCalculator.getTimeBetween(referenceDate, USD_END_ACCRUAL_DATE); final double notionalIncreased = NOTIONAL; final double yearFractionLeft = USD_FIXING_YEAR_FRACTION; final CouponON cpnExpected = new CouponON(USD_FEDFUND.getCurrency(), paymentTime, USD_PAYMENT_YEAR_FRACTION, NOTIONAL, USD_FEDFUND, fixingStartTime, fixingEndTime, yearFractionLeft, notionalIncreased); assertEquals("CouponOISSimplified definition: toDerivative", cpnExpected, cpnConverted); }