CapFloorInflationYearOnYearMonthlyDefinition extends CouponInflationDefinition implements CapFloor { @Override public CapFloorInflationYearOnYearMonthly 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 lastKnownFixingTime = TimeCalculator.getTimeBetween(date, _lastKnownFixingDate); final double paymentTime = TimeCalculator.getTimeBetween(date, getPaymentDate()); final double referenceStartTime = TimeCalculator.getTimeBetween(date, _referenceStartDate); final double referenceEndTime = TimeCalculator.getTimeBetween(date, _referenceEndDate); 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 CapFloorInflationYearOnYearMonthly(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), getPriceIndex(), lastKnownFixingTime, referenceStartTime, naturalPaymentStartTime, referenceEndTime, naturalPaymentEndTime, _strike, _isCap); } CapFloorInflationYearOnYearMonthlyDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate,
      final ZonedDateTime accrualEndDate, final double paymentYearFraction, final double notional, final IndexPrice priceIndex, final ZonedDateTime lastKnownFixingDate,
      final int conventionalMonthLag, final int monthLag, final ZonedDateTime referenceStartDate, final ZonedDateTime referenceEndDate, final double strike, final boolean isCap); static CapFloorInflationYearOnYearMonthlyDefinition from(final ZonedDateTime accrualStartDate, final ZonedDateTime paymentDate, final double notional,
      final IndexPrice priceIndex, final int conventionalMonthLag, final ZonedDateTime lastKnownFixingDate, final double strike, final boolean isCap); static CapFloorInflationYearOnYearMonthlyDefinition from(final ZonedDateTime accrualStartDate, final ZonedDateTime paymentDate, final double notional,
      final IndexPrice priceIndex, final int conventionalMonthLag, final int monthLag, final ZonedDateTime lastKnownFixingDate, final double strike, final boolean isCap); static CapFloorInflationYearOnYearMonthlyDefinition from(final CouponInflationYearOnYearMonthlyDefinition coupon, final ZonedDateTime lastKnownFixingDate,
      final double strike, final boolean isCap); ZonedDateTime getLastKnownFixingDate(); int getConventionalMonthLag(); int getMonthLag(); ZonedDateTime getReferenceStartDate(); ZonedDateTime getReferenceEndDate(); @Override double getStrike(); @Override boolean isCap(); @Override double payOff(final double fixing); @Override CouponInflationDefinition with(final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double notional); @Override CapFloorInflationYearOnYearMonthly 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 String toString(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void toDerivativesNoData() { final ZonedDateTime pricingDate = DateUtils.getUTCDate(2011, 7, 29); final Coupon zeroCouponConverted = YoY_CAP_DEFINITION.toDerivative(pricingDate); final double lastKnownFixingTime = TimeCalculator.getTimeBetween(pricingDate, LAST_KNOWN_FIXING_DATE); 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 CapFloorInflationYearOnYearMonthly zeroCoupon = new CapFloorInflationYearOnYearMonthly(CUR, paymentTime, 1.0, NOTIONAL, PRICE_INDEX, lastKnownFixingTime, referenceStartTime, naturalPaymentStartPaymentTime, referenceEndTime, naturalPaymentEndPaymentTime, STRIKE, IS_CAP); assertEquals("Inflation zero-coupon: toDerivative", zeroCouponConverted, zeroCoupon); }
@Test public void toDerivativesStartMonthNotknown() { final ZonedDateTime pricingDate = DateUtils.getUTCDate(2011, 7, 29); final DoubleTimeSeries<ZonedDateTime> priceIndexTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2017, 5, 1), DateUtils.getUTCDate(2017, 6, 1), DateUtils.getUTCDate(2018, 5, 1), DateUtils.getUTCDate(2018, 6, 1) }, new double[] { 127.23, 127.43, 128.23, 128.43 }); final Coupon zeroCouponConverted = YoY_CAP_DEFINITION.toDerivative(pricingDate, priceIndexTS); final double lastKnownFixingTime = TimeCalculator.getTimeBetween(pricingDate, LAST_KNOWN_FIXING_DATE); 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 CapFloorInflationYearOnYearMonthly zeroCoupon = new CapFloorInflationYearOnYearMonthly(CUR, paymentTime, 1.0, NOTIONAL, PRICE_INDEX, lastKnownFixingTime, referenceStartTime, naturalPaymentStartPaymentTime, referenceEndTime, naturalPaymentEndPaymentTime, STRIKE, IS_CAP); assertEquals("Inflation zero-coupon: toDerivative", zeroCoupon, zeroCouponConverted); }
@Test public void toDerivativesStartMonthKnown() { final ZonedDateTime pricingDate = DateUtils.getUTCDate(2018, 6, 25); final DoubleTimeSeries<ZonedDateTime> priceIndexTS = ImmutableZonedDateTimeDoubleTimeSeries.ofUTC(new ZonedDateTime[] {DateUtils.getUTCDate(2017, 5, 1), DateUtils.getUTCDate(2017, 6, 1), DateUtils.getUTCDate(2018, 5, 1), DateUtils.getUTCDate(2018, 6, 1) }, new double[] { 127.23, 127.43, 128.23, 128.43 }); final Coupon zeroCouponConverted = YoY_CAP_DEFINITION.toDerivative(pricingDate, priceIndexTS); final double paymentTime = ACT_ACT.getDayCountFraction(pricingDate, PAYMENT_DATE); final CouponFixed zeroCoupon = new CouponFixed(CUR, paymentTime, 1.0, NOTIONAL, Math.max((WEIGHT_END * 128.23 + (1 - WEIGHT_END) * 128.43) / (WEIGHT_START * 127.23 + (1 - WEIGHT_START) * 127.43) - 1.0 - STRIKE, 0.0)); assertEquals("Inflation zero-coupon: toDerivative", zeroCoupon, zeroCouponConverted); }