CouponIborFxResetDefinition extends CouponDefinition implements
    InstrumentDefinitionWithData<Payment, DoubleTimeSeries<ZonedDateTime>[]> { @Override public CouponIborFxReset toDerivative(ZonedDateTime dateTime) { ArgumentChecker.notNull(dateTime, "dateTime"); LocalDate dayConversion = dateTime.toLocalDate(); ArgumentChecker.isTrue(!dayConversion.isAfter(getIborIndexFixingDate().toLocalDate()), "Do not have any fixing data but are asking for a derivative at " + dateTime + " which is after ibor index fixing date " + getIborIndexFixingDate()); ArgumentChecker.isTrue(!dayConversion.isAfter(getPaymentDate().toLocalDate()), "date is after payment date"); double paymentTime = TimeCalculator.getTimeBetween(dateTime, getPaymentDate()); double fixingTime = TimeCalculator.getTimeBetween(dateTime, getIborIndexFixingDate()); double fixingPeriodStartTime = TimeCalculator.getTimeBetween(dateTime, getIborIndexFixingPeriodStartDate()); double fixingPeriodEndTime = TimeCalculator.getTimeBetween(dateTime, getIborIndexFixingPeriodEndDate()); double fxFixingTime = TimeCalculator.getTimeBetween(dateTime, _fxFixingDate); double fxDeliveryTime = TimeCalculator.getTimeBetween(dateTime, _fxDeliveryDate); return new CouponIborFxReset(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), fixingTime, getIndex(), fixingPeriodStartTime, fixingPeriodEndTime, getIborIndexFixingPeriodAccrualFactor(), _spread, getReferenceCurrency(), fxFixingTime, fxDeliveryTime); } CouponIborFxResetDefinition(final Currency currency, final ZonedDateTime paymentDate,
      final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double paymentAccrualFactor,
      final double notional, final ZonedDateTime iborIndexFixingDate, final IborIndex index, final double spread,
      final Calendar calendar, final Currency referenceCurrency, final ZonedDateTime fxFixingDate,
      final ZonedDateTime fxDeliveryDate);  CouponIborFxResetDefinition(final Currency currency, final ZonedDateTime paymentDate,
      final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate, final double paymentAccrualFactor,
      final double notional, final ZonedDateTime iborIndexFixingDate,
      final ZonedDateTime iborIndexFixingPeriodStartDate,
      final ZonedDateTime iborIndexFixingPeriodEndDate, final double iborIndexFixingPeriodAccrualFactor,
      final IborIndex index,
      final double spread, final Calendar calendar, final Currency referenceCurrency, final ZonedDateTime fxFixingDate,
      final ZonedDateTime fxDeliveryDate); ZonedDateTime getIborIndexFixingDate(); double getSpread(); IborIndex getIndex(); ZonedDateTime getIborIndexFixingPeriodStartDate(); ZonedDateTime getIborIndexFixingPeriodEndDate(); double getIborIndexFixingPeriodAccrualFactor(); Calendar getCalendar(); Currency getReferenceCurrency(); ZonedDateTime getFxFixingDate(); ZonedDateTime getFxDeliveryDate(); @Override CouponIborFxReset toDerivative(ZonedDateTime dateTime); @Override Coupon toDerivative(ZonedDateTime dateTime, DoubleTimeSeries<ZonedDateTime>[] timeSeries); @Override V accept(InstrumentDefinitionVisitor<U, V> visitor, U data); @Override V accept(InstrumentDefinitionVisitor<?, V> visitor); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void toDerivativeAfterFxAfterIndex() { ZonedDateTime valuationDate1 = FX_FIXING_DATE.plusDays(1); DoubleTimeSeries<ZonedDateTime>[] htsArray1 = new DoubleTimeSeries[] {INDEX_FIXING_TS_SAME, FX_FIXING_TS_0 }; double paymentTime1 = TimeCalculator.getTimeBetween(valuationDate1, PAYMENT_DATE); CouponFixed cpnWithFxIndexExpected1 = new CouponFixed(CUR_PAY, paymentTime1, ACCRUAL_FACTOR, NOTIONAL * FX_FIXING_RATE, FIXING_RATE + SPREAD); Payment cpnConvertedWithFxIndex1 = CPN_SAME_FIXING_DATES.toDerivative(valuationDate1, htsArray1); assertEquals("CouponIborFxResetDefinition: toDerivative", cpnWithFxIndexExpected1, cpnConvertedWithFxIndex1); ZonedDateTime valuationDate2 = FX_FIXING_DATE.plusDays(1); DoubleTimeSeries<ZonedDateTime>[] htsArray2 = new DoubleTimeSeries[] {INDEX_FIXING_TS_BEFORE_FX, FX_FIXING_TS_0 }; double paymentTime2 = TimeCalculator.getTimeBetween(valuationDate2, PAYMENT_DATE); CouponFixed cpnWithFxIndexExpected2 = new CouponFixed(CUR_PAY, paymentTime2, ACCRUAL_FACTOR, NOTIONAL * FX_FIXING_RATE, FIXING_RATE + SPREAD); Payment cpnConvertedWithFxRate2 = CPN_INDEX_FIXED_FIRST.toDerivative(valuationDate2, htsArray2); assertEquals("CouponIborFxResetDefinition: toDerivative", cpnWithFxIndexExpected2, cpnConvertedWithFxRate2); ZonedDateTime valuationDate3 = FX_FIXING_DATE.plusDays(2); DoubleTimeSeries<ZonedDateTime>[] htsArray3 = new DoubleTimeSeries[] {INDEX_FIXING_TS_AFTER_FX, FX_FIXING_TS_0 }; double paymentTime3 = TimeCalculator.getTimeBetween(valuationDate3, PAYMENT_DATE); CouponFixed cpnWithFxIndexExpected3 = new CouponFixed(CUR_PAY, paymentTime3, ACCRUAL_FACTOR, NOTIONAL * FX_FIXING_RATE, FIXING_RATE + SPREAD); Payment cpnConvertedWithFxRate3 = CPN_FX_FIXED_FIRST.toDerivative(valuationDate3, htsArray3); assertEquals("CouponIborFxResetDefinition: toDerivative", cpnWithFxIndexExpected3, cpnConvertedWithFxRate3); }
@Test public void toDerivativeOnFxAfterIndex() { ZonedDateTime valuationDate = FX_FIXING_DATE; double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); double fxFixingTime = TimeCalculator.getTimeBetween(valuationDate, FX_FIXING_DATE); double fXDeliveryTime = TimeCalculator.getTimeBetween(valuationDate, FX_DELIVERY_DATE); DoubleTimeSeries<ZonedDateTime>[] htsArrayWithoutFxRate = new DoubleTimeSeries[] {INDEX_FIXING_TS_BEFORE_FX, FX_FIXING_TS_1 }; CouponFixedFxReset cpnWithIndexExpected = new CouponFixedFxReset(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL, FIXING_RATE + SPREAD, CUR_REF, fxFixingTime, fXDeliveryTime); Payment cpnConvertedWithIndex = CPN_INDEX_FIXED_FIRST.toDerivative(valuationDate, htsArrayWithoutFxRate); assertEquals("CouponIborFxResetDefinition: toDerivative", cpnWithIndexExpected, cpnConvertedWithIndex); DoubleTimeSeries<ZonedDateTime>[] htsArrayWithFxRate = new DoubleTimeSeries[] {INDEX_FIXING_TS_BEFORE_FX, FX_FIXING_TS_0 }; CouponFixed cpnWithFxIndexExpected = new CouponFixed(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL * FX_FIXING_RATE, FIXING_RATE + SPREAD); Payment cpnConvertedWithFxIndex = CPN_INDEX_FIXED_FIRST.toDerivative(valuationDate, htsArrayWithFxRate); assertEquals("CouponIborFxResetDefinition: toDerivative", cpnWithFxIndexExpected, cpnConvertedWithFxIndex); }
@Test public void toDerivativeBeforeFxAfterIndex() { ZonedDateTime valuationDate = FX_FIXING_DATE.minusDays(1); double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); double fxFixingTime = TimeCalculator.getTimeBetween(valuationDate, FX_FIXING_DATE); double fXDeliveryTime = TimeCalculator.getTimeBetween(valuationDate, FX_DELIVERY_DATE); DoubleTimeSeries<ZonedDateTime>[] htsArray = new DoubleTimeSeries[] { INDEX_FIXING_TS_BEFORE_FX, FX_FIXING_TS_1 }; CouponFixedFxReset cpnWithIndexExpected = new CouponFixedFxReset(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL, FIXING_RATE + SPREAD, CUR_REF, fxFixingTime, fXDeliveryTime); Payment cpnConvertedWithIndex = CPN_INDEX_FIXED_FIRST.toDerivative(valuationDate, htsArray); assertEquals("CouponIborFxResetDefinition: toDerivative", cpnWithIndexExpected, cpnConvertedWithIndex); }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void nullFxRateTest() { ZonedDateTime valuationDate = FX_FIXING_DATE.minusDays(1); DoubleTimeSeries<ZonedDateTime>[] htsArray = new DoubleTimeSeries[] { INDEX_FIXING_TS_OLD, FX_FIXING_TS_1 }; CPN_INDEX_FIXED_FIRST.toDerivative(valuationDate, htsArray); }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void nullIndexRateTest() { ZonedDateTime valuationDate = FX_FIXING_DATE.plusDays(1); DoubleTimeSeries<ZonedDateTime>[] htsArray = new DoubleTimeSeries[] { INDEX_FIXING_TS_AFTER_FX, FX_FIXING_TS_10 }; CPN_FX_FIXED_FIRST.toDerivative(valuationDate, htsArray); }
@Test(expectedExceptions = IllegalArgumentException.class) public void dateAfterFixingTest() { ZonedDateTime valuationDate = FX_FIXING_DATE.plusDays(1); CPN_SAME_FIXING_DATES.toDerivative(valuationDate); }
@Test(expectedExceptions = IllegalArgumentException.class) public void singleTimeSeriesTest() { ZonedDateTime valuationDate = PAYMENT_DATE; DoubleTimeSeries<ZonedDateTime>[] htsArray = new DoubleTimeSeries[] {INDEX_FIXING_TS_SAME }; CPN_SAME_FIXING_DATES.toDerivative(valuationDate, htsArray); }
@Test(expectedExceptions = IllegalArgumentException.class) public void dateAfterPaymentTest() { ZonedDateTime valuationDate = PAYMENT_DATE.plusDays(1); DoubleTimeSeries<ZonedDateTime>[] htsArray = new DoubleTimeSeries[] {INDEX_FIXING_TS_SAME, FX_FIXING_TS_10 }; CPN_SAME_FIXING_DATES.toDerivative(valuationDate, htsArray); }