CouponInflationYearOnYearMonthlyDefinition extends CouponInflationDefinition { @Override public CouponInflationYearOnYearMonthly toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); ArgumentChecker.isTrue(!date.isAfter(getPaymentDate()), "Do not have any fixing data but are asking for a derivative after the payment date"); ArgumentChecker.isTrue(!date.isAfter(getPaymentDate()), "date is after payment date"); final double paymentTime = TimeCalculator.getTimeBetween(date, getPaymentDate()); final double referenceEndTime = TimeCalculator.getTimeBetween(date, getReferenceEndDate()); final double referenceStartTime = TimeCalculator.getTimeBetween(date, getReferenceStartDate()); final ZonedDateTime naturalPaymentEndDate = getPaymentDate().minusMonths(_monthLag - _conventionalMonthLag); final double naturalPaymentEndTime = TimeCalculator.getTimeBetween(date, naturalPaymentEndDate); final ZonedDateTime naturalPaymentstartDate = naturalPaymentEndDate.minusMonths(12); final double naturalPaymentStartTime = TimeCalculator.getTimeBetween(date, naturalPaymentstartDate); return new CouponInflationYearOnYearMonthly(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), getPriceIndex(), referenceStartTime, naturalPaymentStartTime, referenceEndTime, naturalPaymentEndTime, _payNotional); } CouponInflationYearOnYearMonthlyDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate,
      final ZonedDateTime accrualEndDate, final double paymentYearFraction, final double notional, final IndexPrice priceIndex, final int conventionalMonthLag,
      final int monthLag, final ZonedDateTime referenceStartDate, final ZonedDateTime referenceEndDate, final boolean payNotional); static CouponInflationYearOnYearMonthlyDefinition from(final ZonedDateTime accrualStartDate, final ZonedDateTime paymentDate, final double notional,
      final IndexPrice priceIndex, final int conventionalMonthLag, final boolean payNotional); static CouponInflationYearOnYearMonthlyDefinition from(final ZonedDateTime accrualStartDate, final ZonedDateTime paymentDate, final double notional,
      final IndexPrice priceIndex, final int conventionalMonthLag, final int monthLag, final boolean payNotional); ZonedDateTime getReferenceStartDate(); ZonedDateTime getReferenceEndDate(); boolean payNotional(); int getConventionalMonthLag(); int getMonthLag(); @Override CouponInflationDefinition with(final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double notional); @Override CouponInflationYearOnYearMonthly toDerivative(final ZonedDateTime date); @Override Coupon toDerivative(final ZonedDateTime date, final DoubleTimeSeries<ZonedDateTime> priceIndexTimeSeries); @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 toDerivativesNoData() { final ZonedDateTime pricingDate = DateUtils.getUTCDate(2011, 7, 29); final Coupon yearOnYearCouponConverted = YoY_COUPON_DEFINITION.toDerivative(pricingDate); final double paymentTime = ACT_ACT.getDayCountFraction(pricingDate, PAYMENT_DATE); final double referenceStartTime = ACT_ACT.getDayCountFraction(pricingDate, REFERENCE_START_DATE); final double referenceEndTime = ACT_ACT.getDayCountFraction(pricingDate, REFERENCE_END_DATE); final double naturalPaymentStartPaymentTime = ACT_ACT.getDayCountFraction(pricingDate, ACCRUAL_START_DATE); final double naturalPaymentEndPaymentTime = ACT_ACT.getDayCountFraction(pricingDate, ACCRUAL_END_DATE); final CouponInflationYearOnYearMonthly yearOnYearCoupon = new CouponInflationYearOnYearMonthly(CUR, paymentTime, 1.0, NOTIONAL, PRICE_INDEX, referenceStartTime, naturalPaymentStartPaymentTime, referenceEndTime, naturalPaymentEndPaymentTime, false); assertEquals("Inflation zero-coupon: toDerivative", yearOnYearCouponConverted, yearOnYearCoupon); }
@Test public void toDerivativesStartMonthNotknown() { final ZonedDateTime pricingDate = DateUtils.getUTCDate(2011, 7, 29); final DoubleTimeSeries<ZonedDateTime> priceIndexTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2017, 4, 30), DateUtils.getUTCDate(2017, 5, 31), DateUtils.getUTCDate(2018, 4, 30), DateUtils.getUTCDate(2018, 5, 31) }, new double[] { 127.23, 127.43, 128.23, 128.43 }); final Coupon yearOnYearCouponConverted = YoY_COUPON_DEFINITION.toDerivative(pricingDate, priceIndexTS); final double paymentTime = ACT_ACT.getDayCountFraction(pricingDate, PAYMENT_DATE); final double referenceStartTime = ACT_ACT.getDayCountFraction(pricingDate, REFERENCE_START_DATE); final double referenceEndTime = ACT_ACT.getDayCountFraction(pricingDate, REFERENCE_END_DATE); final double naturalPaymentStartPaymentTime = ACT_ACT.getDayCountFraction(pricingDate, ACCRUAL_START_DATE); final double naturalPaymentEndPaymentTime = ACT_ACT.getDayCountFraction(pricingDate, ACCRUAL_END_DATE); final CouponInflationYearOnYearMonthly yearOnYearCoupon = new CouponInflationYearOnYearMonthly(CUR, paymentTime, 1.0, NOTIONAL, PRICE_INDEX, referenceStartTime, naturalPaymentStartPaymentTime, referenceEndTime, naturalPaymentEndPaymentTime, false); assertEquals("Inflation zero-coupon: toDerivative", yearOnYearCoupon, yearOnYearCouponConverted); }
@Test public void toDerivativesStartMonthKnown() { final ZonedDateTime pricingDate = DateUtils.getUTCDate(2018, 7, 25); final DoubleTimeSeries<ZonedDateTime> priceIndexTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2017, 5, 31), DateUtils.getUTCDate(2017, 6, 30), DateUtils.getUTCDate(2018, 5, 31), DateUtils.getUTCDate(2018, 6, 30) }, new double[] { 127.23, 127.43, 128.23, 128.43 }); final Coupon zeroCouponConverted = YoY_COUPON_DEFINITION.toDerivative(pricingDate, priceIndexTS); final double paymentTime = ACT_ACT.getDayCountFraction(pricingDate, PAYMENT_DATE); final CouponFixed zeroCoupon = new CouponFixed(CUR, paymentTime, 1.0, NOTIONAL, 128.23 / 127.23 - 1.0); assertEquals("Inflation zero-coupon: toDerivative", zeroCoupon, zeroCouponConverted); }