BondFuturesSecurityDefinition extends FuturesSecurityDefinition<BondFuturesSecurity> { @Override public BondFuturesSecurity toDerivative(final ZonedDateTime date) { ArgumentChecker.notNull(date, "date"); ArgumentChecker.isTrue(!date.toLocalDate().isAfter(getNoticeLastDate().toLocalDate()), "Date is after last notice date"); final double lastTradingTime = TimeCalculator.getTimeBetween(date, getLastTradingDate()); final double firstNoticeTime = TimeCalculator.getTimeBetween(date, getNoticeFirstDate()); final double lastNoticeTime = TimeCalculator.getTimeBetween(date, getNoticeLastDate()); final double firstDeliveryTime = TimeCalculator.getTimeBetween(date, getDeliveryFirstDate()); final double lastDeliveryTime = TimeCalculator.getTimeBetween(date, getDeliveryLastDate()); final BondFixedSecurity[] basketAtDeliveryDate = new BondFixedSecurity[_deliveryBasket.length]; final BondFixedSecurity[] basketAtSpotDate = new BondFixedSecurity[_deliveryBasket.length]; for (int loopbasket = 0; loopbasket < _deliveryBasket.length; loopbasket++) { basketAtDeliveryDate[loopbasket] = _deliveryBasket[loopbasket].toDerivative(date, _deliveryLastDate); basketAtSpotDate[loopbasket] = _deliveryBasket[loopbasket].toDerivative(date); } return new BondFuturesSecurity(lastTradingTime, firstNoticeTime, lastNoticeTime, firstDeliveryTime, lastDeliveryTime, _notional, basketAtDeliveryDate, basketAtSpotDate, _conversionFactor); } BondFuturesSecurityDefinition(final ZonedDateTime tradingLastDate, final ZonedDateTime noticeFirstDate, final ZonedDateTime noticeLastDate,
      final ZonedDateTime deliveryFirstDate, final ZonedDateTime deliveryLastDate,
      final double notional, final BondFixedSecurityDefinition[] deliveryBasket, final double[] conversionFactor);  BondFuturesSecurityDefinition(final ZonedDateTime tradingLastDate, final ZonedDateTime noticeFirstDate, final ZonedDateTime noticeLastDate, final double notional,
      final BondFixedSecurityDefinition[] deliveryBasket, final double[] conversionFactor); ZonedDateTime getNoticeFirstDate(); ZonedDateTime getNoticeLastDate(); ZonedDateTime getDeliveryFirstDate(); ZonedDateTime getDeliveryLastDate(); double getNotional(); BondFixedSecurityDefinition[] getDeliveryBasket(); double[] getConversionFactor(); Calendar getCalendar(); Currency getCurrency(); @Override BondFuturesSecurity toDerivative(final ZonedDateTime date); @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 toDerivative1() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 6, 17); final double lastTradingTime = TimeCalculator.getTimeBetween(referenceDate, LAST_TRADING_DATE); final double firstNoticeTime = TimeCalculator.getTimeBetween(referenceDate, FIRST_NOTICE_DATE); final double lastNoticeTime = TimeCalculator.getTimeBetween(referenceDate, LAST_NOTICE_DATE); final double firstDeliveryTime = TimeCalculator.getTimeBetween(referenceDate, FIRST_DELIVERY_DATE_STD); final double lastDeliveryTime = TimeCalculator.getTimeBetween(referenceDate, LAST_DELIVERY_DATE_STD); final BondFixedSecurity[] basketAtDeliveryDate = new BondFixedSecurity[NB_BOND]; final BondFixedSecurity[] basketAtSpotDate = new BondFixedSecurity[NB_BOND]; for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) { basketAtDeliveryDate[loopbasket] = BASKET_DEFINITION[loopbasket].toDerivative(referenceDate, LAST_DELIVERY_DATE_STD); basketAtSpotDate[loopbasket] = BASKET_DEFINITION[loopbasket].toDerivative(referenceDate); } final BondFuturesSecurity futureConverted = FUTURE_DEFINITION_1.toDerivative(referenceDate); final BondFuturesSecurity futureExpected = new BondFuturesSecurity(lastTradingTime, firstNoticeTime, lastNoticeTime, firstDeliveryTime, lastDeliveryTime, NOTIONAL, basketAtDeliveryDate, basketAtSpotDate, CONVERSION_FACTOR); assertEquals("Bond future security definition: future conversion", futureExpected, futureConverted); }
@Test public void toDerivative2() { final ZonedDateTime referenceDate = DateUtils.getUTCDate(2011, 6, 17); final double lastTradingTime = TimeCalculator.getTimeBetween(referenceDate, LAST_TRADING_DATE); final double firstNoticeTime = TimeCalculator.getTimeBetween(referenceDate, FIRST_NOTICE_DATE); final double lastNoticeTime = TimeCalculator.getTimeBetween(referenceDate, LAST_NOTICE_DATE); final double firstDeliveryTime = TimeCalculator.getTimeBetween(referenceDate, FIRST_DELIVERY_DATE); final double lastDeliveryTime = TimeCalculator.getTimeBetween(referenceDate, LAST_DELIVERY_DATE); final BondFixedSecurity[] basketAtDeliveryDate = new BondFixedSecurity[NB_BOND]; final BondFixedSecurity[] basketAtSpotDate = new BondFixedSecurity[NB_BOND]; for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) { basketAtDeliveryDate[loopbasket] = BASKET_DEFINITION[loopbasket].toDerivative(referenceDate, LAST_DELIVERY_DATE); basketAtSpotDate[loopbasket] = BASKET_DEFINITION[loopbasket].toDerivative(referenceDate); } final BondFuturesSecurity futureConverted = FUTURE_DEFINITION_2.toDerivative(referenceDate); final BondFuturesSecurity futureExpected = new BondFuturesSecurity(lastTradingTime, firstNoticeTime, lastNoticeTime, firstDeliveryTime, lastDeliveryTime, NOTIONAL, basketAtDeliveryDate, basketAtSpotDate, CONVERSION_FACTOR); assertEquals("Bond future security definition: future conversion", futureExpected, futureConverted); }