CouponFixedFxResetDefinition extends CouponDefinition implements InstrumentDefinitionWithData<Payment, DoubleTimeSeries<ZonedDateTime>> { @Override public CouponFixedFxReset toDerivative(ZonedDateTime dateTime) { ArgumentChecker.notNull(dateTime, "date"); LocalDate conversionDate = dateTime.toLocalDate(); LocalDate fixingDate = _fxFixingDate.toLocalDate(); ArgumentChecker.isTrue(!conversionDate.isAfter(fixingDate), "Do not have any fixing data but are asking for a derivative at {} which is after fixing date {}", conversionDate, fixingDate); double paymentTime = TimeCalculator.getTimeBetween(dateTime, getPaymentDate()); double fixingTime = TimeCalculator.getTimeBetween(dateTime, _fxFixingDate); double deliveryTime = TimeCalculator.getTimeBetween(dateTime, _fxDeliveryDate); return new CouponFixedFxReset(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), _rate, _referenceCurrency, fixingTime, deliveryTime); } CouponFixedFxResetDefinition(Currency currency, ZonedDateTime paymentDate, ZonedDateTime accrualStartDate, 
      ZonedDateTime accrualEndDate, double paymentAccrualFactor, double notional,
      double rate, Currency referenceCurrency, ZonedDateTime fxFixingDate, ZonedDateTime fxDeliveryDate); double getRate(); Currency getReferenceCurrency(); ZonedDateTime getFxFixingDate(); ZonedDateTime getFxDeliveryDate(); double paymentAmount(double fxRate); @Override CouponFixedFxReset toDerivative(ZonedDateTime dateTime); @Override Coupon toDerivative(ZonedDateTime dateTime, DoubleTimeSeries<ZonedDateTime> fxFixingHts); @Override V accept(InstrumentDefinitionVisitor<U, V> visitor, U data); @Override V accept(InstrumentDefinitionVisitor<?, V> visitor); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void toDerivativeMissingFixing() { ZonedDateTime valuationDate = FX_FIXING_DATE.plusDays(1); CPN.toDerivative(valuationDate); }
@Test(expectedExceptions = IllegalArgumentException.class) public void toDerivativeNullFixing() { CPN.toDerivative(FX_FIXING_DATE, (DoubleTimeSeries<ZonedDateTime>)null); }
@Test public void toDerivativeBeforeFixingNoHts() { ZonedDateTime valuationDate = FX_FIXING_DATE.minusDays(10); double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); double fixingTime = TimeCalculator.getTimeBetween(valuationDate, FX_FIXING_DATE); double deliveryTime = TimeCalculator.getTimeBetween(valuationDate, FX_DELIVERY_DATE); CouponFixedFxReset cpnExpected = new CouponFixedFxReset(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL, RATE, CUR_REF, fixingTime, deliveryTime); CouponFixedFxReset cpnConverted = CPN.toDerivative(valuationDate); assertEquals("CouponFixedFxResetDefinition: toDerivative", cpnExpected, cpnConverted); }
@Test public void toDerivativeBeforeFixing() { ZonedDateTime valuationDate = FX_FIXING_DATE.minusDays(10); double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); double fixingTime = TimeCalculator.getTimeBetween(valuationDate, FX_FIXING_DATE); double deliveryTime = TimeCalculator.getTimeBetween(valuationDate, FX_DELIVERY_DATE); CouponFixedFxReset cpnExpected = new CouponFixedFxReset(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL, RATE, CUR_REF, fixingTime, deliveryTime); Payment cpnConverted = CPN.toDerivative(valuationDate, FX_FIXING_TS_10); assertEquals("CouponFixedFxResetDefinition: toDerivative", cpnExpected, cpnConverted); }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void toDerivativeAfterFixingNotAvailable() { ZonedDateTime valuationDate = FX_FIXING_DATE.plusDays(1); CPN.toDerivative(valuationDate, FX_FIXING_TS_1); }
@Test public void toDerivativeOnFixingNotAvailable() { ZonedDateTime valuationDate = FX_FIXING_DATE; double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); double fixingTime = TimeCalculator.getTimeBetween(valuationDate, FX_FIXING_DATE); double deliveryTime = TimeCalculator.getTimeBetween(valuationDate, FX_DELIVERY_DATE); CouponFixedFxReset cpnExpected = new CouponFixedFxReset(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL, RATE, CUR_REF, fixingTime, deliveryTime); Payment cpnConverted = CPN.toDerivative(valuationDate, FX_FIXING_TS_1); assertEquals("CouponFixedFxResetDefinition: toDerivative", cpnExpected, cpnConverted); }
@Test public void toDerivativeOnFixingAvailable() { ZonedDateTime valuationDate = FX_FIXING_DATE; double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); CouponFixed cpnExpected = new CouponFixed(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL*FX_FIXING_RATE, RATE); Payment cpnConverted = CPN.toDerivative(valuationDate, FX_FIXING_TS0); assertEquals("CouponFixedFxResetDefinition: toDerivative", cpnExpected, cpnConverted); }
@Test public void toDerivativeAfterFixing() { ZonedDateTime valuationDate = FX_FIXING_DATE.plusDays(1); double paymentTime = TimeCalculator.getTimeBetween(valuationDate, PAYMENT_DATE); CouponFixed cpnExpected = new CouponFixed(CUR_PAY, paymentTime, ACCRUAL_FACTOR, NOTIONAL*FX_FIXING_RATE, RATE); Payment cpnConverted = CPN.toDerivative(valuationDate, FX_FIXING_TS0); assertEquals("CouponFixedFxResetDefinition: toDerivative", cpnExpected, cpnConverted); }