CouponIborAverageFixingDatesDefinition extends CouponDefinition implements InstrumentDefinitionWithData<Payment, DoubleTimeSeries<ZonedDateTime>> { @Override public CouponIborAverageFixingDates toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); final int nDates = _weight.length; final LocalDate dayConversion = date.toLocalDate(); ArgumentChecker.isTrue(!dayConversion.isAfter(getPaymentDate().toLocalDate()), "date is after payment date"); ArgumentChecker.isTrue(!dayConversion.isAfter(getFixingDate()[0].toLocalDate()), "Do not have any fixing data but are asking for a derivative at " + date + " which is after fixing date " + getFixingDate()[0]); final double paymentTime = TimeCalculator.getTimeBetween(date, getPaymentDate()); final double[] fixingTime = new double[nDates]; final double[] fixingPeriodStartTime = new double[nDates]; final double[] fixingPeriodEndTime = new double[nDates]; for (int i = 0; i < nDates; ++i) { fixingTime[i] = TimeCalculator.getTimeBetween(date, getFixingDate()[i]); fixingPeriodStartTime[i] = TimeCalculator.getTimeBetween(date, getFixingPeriodStartDate()[i]); fixingPeriodEndTime[i] = TimeCalculator.getTimeBetween(date, getFixingPeriodEndDate()[i]); } return new CouponIborAverageFixingDates(getCurrency(), paymentTime, getPaymentYearFraction(), getNotional(), getIndex(), fixingTime, getWeight(), fixingPeriodStartTime, fixingPeriodEndTime, getFixingPeriodAccrualFactor(), 0); } CouponIborAverageFixingDatesDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate,
      final double paymentAccrualFactor, final double notional, final IborIndex index, final ZonedDateTime[] fixingDate, final double[] weight, final Calendar iborCalendar);  CouponIborAverageFixingDatesDefinition(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate,
      final double paymentAccrualFactor, final double notional, final IborIndex index, final ZonedDateTime[] fixingDate, final double[] weight, final ZonedDateTime[] fixingPeriodStartDate,
      final ZonedDateTime[] fixingPeriodEndDate, final double[] fixingPeriodAccrualFactor); static CouponIborAverageFixingDatesDefinition from(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate,
      final double paymentAccrualFactor, final double notional, final IborIndex index, final ZonedDateTime[] fixingDate, final double[] weight, final Calendar iborCalendar); static CouponIborAverageFixingDatesDefinition from(final Currency currency, final ZonedDateTime paymentDate, final ZonedDateTime accrualStartDate, final ZonedDateTime accrualEndDate,
      final double paymentAccrualFactor, final double notional, final IborIndex index, final ZonedDateTime[] fixingDate, final double[] weight, final ZonedDateTime[] fixingPeriodStartDate,
      final ZonedDateTime[] fixingPeriodEndDate, final double[] fixingPeriodAccrualFactor); CouponIborAverageFixingDatesDefinition withNotional(final double notional); @Override CouponIborAverageFixingDates toDerivative(final ZonedDateTime date); @Override Coupon toDerivative(ZonedDateTime dateTime, DoubleTimeSeries<ZonedDateTime> indexFixingTimeSeries); @Override V accept(final InstrumentDefinitionVisitor<U, V> visitor, final U data); @Override V accept(final InstrumentDefinitionVisitor<?, V> visitor); ZonedDateTime[] getFixingDate(); IborIndex getIndex(); double[] getWeight(); ZonedDateTime[] getFixingPeriodStartDate(); ZonedDateTime[] getFixingPeriodEndDate(); double[] getFixingPeriodAccrualFactor(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void toDerivativeException() { try { DFN1.toDerivative(PAYMENT_DATE.plusDays(10), FIXING_TS1); throw new RuntimeException(); } catch (final Exception e) { assertEquals("date is after payment date", e.getMessage()); } try { DFN1.toDerivative(DateUtils.getUTCDate(2011, 7, 3), FIXING_TS1); throw new RuntimeException(); } catch (final Exception e) { assertEquals("Could not get fixing value for date " + FIXING_DATES[0], e.getMessage()); } }
@Test public void exceptionTest() { try { new CouponIborAverageFixingDatesDefinition(Currency.GBP, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, WEIGHTS, CALENDAR); throw new RuntimeException(); } catch (final Exception e) { assertEquals("index currency different from payment currency", e.getMessage()); } try { new CouponIborAverageFixingDatesDefinition(Currency.USD, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, WEIGHTS, EXP_START_DATES, EXP_END_DATES, FIX_ACC_FACTORS); throw new RuntimeException(); } catch (final Exception e) { assertEquals("index currency different from payment currency", e.getMessage()); } final double[] shortWeight = Arrays.copyOf(WEIGHTS, NUM_OBS - 1); try { new CouponIborAverageFixingDatesDefinition(CUR, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, shortWeight, CALENDAR); throw new RuntimeException(); } catch (final Exception e) { assertEquals("weight length different from fixingDate length", e.getMessage()); } try { new CouponIborAverageFixingDatesDefinition(CUR, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, shortWeight, EXP_START_DATES, EXP_END_DATES, FIX_ACC_FACTORS); throw new RuntimeException(); } catch (final Exception e) { assertEquals("weight length different from fixingDate length", e.getMessage()); } final ZonedDateTime[] shortStartDates = Arrays.copyOf(EXP_START_DATES, NUM_OBS - 1); try { new CouponIborAverageFixingDatesDefinition(CUR, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, WEIGHTS, shortStartDates, EXP_END_DATES, FIX_ACC_FACTORS); throw new RuntimeException(); } catch (final Exception e) { assertEquals("fixingPeriodStartDate length different from fixingDate length", e.getMessage()); } final ZonedDateTime[] shortEndDates = Arrays.copyOf(EXP_END_DATES, NUM_OBS - 1); try { new CouponIborAverageFixingDatesDefinition(CUR, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, WEIGHTS, EXP_START_DATES, shortEndDates, FIX_ACC_FACTORS); throw new RuntimeException(); } catch (final Exception e) { assertEquals("fixingPeriodEndDate length different from fixingDate length", e.getMessage()); } final double[] shortFcc = Arrays.copyOf(FIX_ACC_FACTORS, NUM_OBS - 1); try { new CouponIborAverageFixingDatesDefinition(CUR, PAYMENT_DATE, ACCRUAL_START_DATE, ACCRUAL_END_DATE, ACCRUAL_FACTOR, NOTIONAL, INDEX, FIXING_DATES, WEIGHTS, EXP_START_DATES, EXP_END_DATES, shortFcc); throw new RuntimeException(); } catch (final Exception e) { assertEquals("fixingPeriodAccrualFactor length different from fixingDate length", e.getMessage()); } final ZonedDateTime afterPayment = PAYMENT_DATE.plusDays(1); try { DFN1.toDerivative(afterPayment); throw new RuntimeException(); } catch (final Exception e) { assertEquals("date is after payment date", e.getMessage()); } final ZonedDateTime afterFixing = FIXING_DATES[0].plusDays(1); try { DFN1.toDerivative(afterFixing); throw new RuntimeException(); } catch (final Exception e) { assertEquals("Do not have any fixing data but are asking for a derivative at " + afterFixing + " which is after fixing date " + FIXING_DATES[0], e.getMessage()); } }