Ejemplo n.º 1
0
/** Tests related to the construction of CapFloorCMSSpread. */
public class CapFloorCMSSpreadTest {

  // Swaps
  private static final Currency CUR = Currency.USD;
  private static final Calendar CALENDAR = new MondayToFridayCalendar("A");
  private static final BusinessDayConvention BUSINESS_DAY =
      BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Modified Following");
  private static final boolean IS_EOM = true;
  private static final ZonedDateTime SETTLEMENT_DATE = DateUtils.getUTCDate(2011, 3, 17);
  private static final Period FIXED_PAYMENT_PERIOD = Period.ofMonths(6);
  private static final DayCount FIXED_DAY_COUNT = DayCountFactory.INSTANCE.getDayCount("30/360");
  private static final boolean FIXED_IS_PAYER = true; // Irrelevant for the underlying
  private static final double RATE = 0.0; // Irrelevant for the underlying
  private static final Period INDEX_TENOR = Period.ofMonths(3);
  private static final int SETTLEMENT_DAYS = 2;
  private static final DayCount DAY_COUNT = DayCountFactory.INSTANCE.getDayCount("Actual/360");
  private static final IborIndex IBOR_INDEX =
      new IborIndex(CUR, INDEX_TENOR, SETTLEMENT_DAYS, CALENDAR, DAY_COUNT, BUSINESS_DAY, IS_EOM);
  // Swap 10Y
  private static final Period ANNUITY_TENOR_1 = Period.ofYears(10);
  private static final IndexSwap CMS_INDEX_1 =
      new IndexSwap(FIXED_PAYMENT_PERIOD, FIXED_DAY_COUNT, IBOR_INDEX, ANNUITY_TENOR_1);
  private static final SwapFixedIborDefinition SWAP_DEFINITION_1 =
      SwapFixedIborDefinition.from(SETTLEMENT_DATE, CMS_INDEX_1, 1.0, RATE, FIXED_IS_PAYER);
  // Swap 2Y
  private static final Period ANNUITY_TENOR_2 = Period.ofYears(2);
  private static final IndexSwap CMS_INDEX_2 =
      new IndexSwap(FIXED_PAYMENT_PERIOD, FIXED_DAY_COUNT, IBOR_INDEX, ANNUITY_TENOR_2);
  private static final SwapFixedIborDefinition SWAP_DEFINITION_2 =
      SwapFixedIborDefinition.from(SETTLEMENT_DATE, CMS_INDEX_2, 1.0, RATE, FIXED_IS_PAYER);
  // CMS spread coupon
  private static final double NOTIONAL = 10000000;
  private static final ZonedDateTime PAYMENT_DATE = DateUtils.getUTCDate(2011, 4, 6);
  private static final ZonedDateTime FIXING_DATE = DateUtils.getUTCDate(2010, 12, 30);
  private static final ZonedDateTime ACCRUAL_START_DATE = DateUtils.getUTCDate(2011, 1, 5);
  private static final ZonedDateTime ACCRUAL_END_DATE = DateUtils.getUTCDate(2011, 4, 5);
  private static final DayCount PAYMENT_DAY_COUNT =
      DayCountFactory.INSTANCE.getDayCount("Actual/360");
  private static final double PAYMENT_ACCRUAL_FACTOR =
      PAYMENT_DAY_COUNT.getDayCountFraction(ACCRUAL_START_DATE, ACCRUAL_END_DATE);
  private static final double STRIKE = 0.0050; // 50 bps
  private static final boolean IS_CAP = true;
  // to derivatives
  private static final ZonedDateTime REFERENCE_DATE = DateUtils.getUTCDate(2010, 8, 18);
  private static final String FUNDING_CURVE_NAME = "Funding";
  private static final String FORWARD_CURVE_1_NAME = "Forward 1";
  //  private static final String FORWARD_CURVE_2_NAME = "Forward 2";
  private static final String[] CURVES_2_NAME = {FUNDING_CURVE_NAME, FORWARD_CURVE_1_NAME};
  //  private static final String[] CURVES_3_NAME = {FUNDING_CURVE_NAME, FORWARD_CURVE_1_NAME,
  // FORWARD_CURVE_2_NAME};
  private static final FixedCouponSwap<? extends Payment> SWAP_1 =
      SWAP_DEFINITION_1.toDerivative(REFERENCE_DATE, CURVES_2_NAME);
  private static final FixedCouponSwap<? extends Payment> SWAP_2 =
      SWAP_DEFINITION_2.toDerivative(REFERENCE_DATE, CURVES_2_NAME);
  private static final DayCount ACT_ACT =
      DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");
  private static final ZonedDateTime REFERENCE_DATE_ZONED =
      ZonedDateTime.of(LocalDateTime.ofMidnight(REFERENCE_DATE), TimeZone.UTC);
  private static final double PAYMENT_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, PAYMENT_DATE);
  private static final double FIXING_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, FIXING_DATE);
  private static final double SETTLEMENT_TIME =
      ACT_ACT.getDayCountFraction(
          REFERENCE_DATE_ZONED,
          SWAP_DEFINITION_1.getFixedLeg().getNthPayment(0).getAccrualStartDate());

  private static final CapFloorCMSSpread CMS_SPREAD =
      new CapFloorCMSSpread(
          CUR,
          PAYMENT_TIME,
          PAYMENT_ACCRUAL_FACTOR,
          NOTIONAL,
          FIXING_TIME,
          SWAP_1,
          CMS_INDEX_1,
          SWAP_2,
          CMS_INDEX_2,
          SETTLEMENT_TIME,
          STRIKE,
          IS_CAP,
          FUNDING_CURVE_NAME);

  @Test
  public void testGetter() {
    assertEquals(SWAP_1, CMS_SPREAD.getUnderlyingSwap1());
    assertEquals(CMS_INDEX_1, CMS_SPREAD.getCmsIndex1());
    assertEquals(SWAP_2, CMS_SPREAD.getUnderlyingSwap2());
    assertEquals(CMS_INDEX_2, CMS_SPREAD.getCmsIndex2());
    assertEquals(STRIKE, CMS_SPREAD.getStrike(), 1E-10);
    assertEquals(IS_CAP, CMS_SPREAD.isCap());
  }

  @Test
  public void testEqualHash() {
    final CapFloorCMSSpread newCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(newCMSSpread.equals(CMS_SPREAD), true);
    assertEquals(newCMSSpread.hashCode() == CMS_SPREAD.hashCode(), true);
    final Currency newCur = Currency.EUR;
    CapFloorCMSSpread modifiedCMSSpread;
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            newCur,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME + 1.0,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR + 1.0,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL + 1.0,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME + 1.0,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME + 1.0,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE + 1.0,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            !IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_2,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_2,
            SWAP_2,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_1,
            CMS_INDEX_2,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
    modifiedCMSSpread =
        new CapFloorCMSSpread(
            CUR,
            PAYMENT_TIME,
            PAYMENT_ACCRUAL_FACTOR,
            NOTIONAL,
            FIXING_TIME,
            SWAP_1,
            CMS_INDEX_1,
            SWAP_2,
            CMS_INDEX_1,
            SETTLEMENT_TIME,
            STRIKE,
            IS_CAP,
            FUNDING_CURVE_NAME);
    assertEquals(modifiedCMSSpread.equals(CMS_SPREAD), false);
  }
}
/** Tests related to the construction of interest rate future security. */
public class InterestRateFutureSecurityTest {
  // EURIBOR 3M Index
  private static final Period TENOR = Period.ofMonths(3);
  private static final int SETTLEMENT_DAYS = 2;
  private static final Calendar CALENDAR = new MondayToFridayCalendar("A");
  private static final DayCount DAY_COUNT_INDEX =
      DayCountFactory.INSTANCE.getDayCount("Actual/360");
  private static final BusinessDayConvention BUSINESS_DAY =
      BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Modified Following");
  private static final boolean IS_EOM = true;
  private static final Currency CUR = Currency.EUR;
  private static final IborIndex IBOR_INDEX =
      new IborIndex(CUR, TENOR, SETTLEMENT_DAYS, CALENDAR, DAY_COUNT_INDEX, BUSINESS_DAY, IS_EOM);
  // Future
  private static final ZonedDateTime SPOT_LAST_TRADING_DATE = DateUtil.getUTCDate(2012, 9, 19);
  private static final ZonedDateTime LAST_TRADING_DATE =
      ScheduleCalculator.getAdjustedDate(SPOT_LAST_TRADING_DATE, CALENDAR, -SETTLEMENT_DAYS);
  private static final ZonedDateTime FIXING_END_DATE =
      ScheduleCalculator.getAdjustedDate(
          SPOT_LAST_TRADING_DATE, BUSINESS_DAY, CALENDAR, IS_EOM, TENOR);
  private static final double NOTIONAL = 1000000.0; // 1m
  private static final double FUTURE_FACTOR = 0.25;
  private static final String NAME = "ERU2";
  //  private static final InterestRateFutureSecurityDefinition ERU2 = new
  // InterestRateFutureSecurityDefinition(LAST_TRADING_DATE, IBOR_INDEX, NOTIONAL, FUTURE_FACTOR,
  // NAME);

  private static final LocalDate REFERENCE_DATE = LocalDate.of(2010, 8, 18);
  private static final DayCount ACT_ACT =
      DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");
  private static final ZonedDateTime REFERENCE_DATE_ZONED =
      ZonedDateTime.of(LocalDateTime.ofMidnight(REFERENCE_DATE), TimeZone.UTC);
  private static final double LAST_TRADING_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, LAST_TRADING_DATE);
  private static final double FIXING_START_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, SPOT_LAST_TRADING_DATE);
  private static final double FIXING_END_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, FIXING_END_DATE);
  private static final double FIXING_ACCRUAL =
      DAY_COUNT_INDEX.getDayCountFraction(SPOT_LAST_TRADING_DATE, FIXING_END_DATE);
  private static final String DISCOUNTING_CURVE_NAME = "Funding";
  private static final String FORWARD_CURVE_NAME = "Forward";
  private static final InterestRateFutureSecurity ERU2 =
      new InterestRateFutureSecurity(
          LAST_TRADING_TIME,
          IBOR_INDEX,
          FIXING_START_TIME,
          FIXING_END_TIME,
          FIXING_ACCRUAL,
          NOTIONAL,
          FUTURE_FACTOR,
          NAME,
          DISCOUNTING_CURVE_NAME,
          FORWARD_CURVE_NAME);

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullIndex() {
    new InterestRateFutureSecurity(
        LAST_TRADING_TIME,
        null,
        FIXING_START_TIME,
        FIXING_END_TIME,
        FIXING_ACCRUAL,
        NOTIONAL,
        FUTURE_FACTOR,
        NAME,
        DISCOUNTING_CURVE_NAME,
        FORWARD_CURVE_NAME);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullName() {
    new InterestRateFutureSecurity(
        LAST_TRADING_TIME,
        IBOR_INDEX,
        FIXING_START_TIME,
        FIXING_END_TIME,
        FIXING_ACCRUAL,
        NOTIONAL,
        FUTURE_FACTOR,
        null,
        DISCOUNTING_CURVE_NAME,
        FORWARD_CURVE_NAME);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullDscCurve() {
    new InterestRateFutureSecurity(
        LAST_TRADING_TIME,
        IBOR_INDEX,
        FIXING_START_TIME,
        FIXING_END_TIME,
        FIXING_ACCRUAL,
        NOTIONAL,
        FUTURE_FACTOR,
        NAME,
        null,
        FORWARD_CURVE_NAME);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullForwardCurve() {
    new InterestRateFutureSecurity(
        LAST_TRADING_TIME,
        IBOR_INDEX,
        FIXING_START_TIME,
        FIXING_END_TIME,
        FIXING_ACCRUAL,
        NOTIONAL,
        FUTURE_FACTOR,
        NAME,
        DISCOUNTING_CURVE_NAME,
        null);
  }

  @Test
  public void getter() {
    assertEquals(LAST_TRADING_TIME, ERU2.getLastTradingTime());
    assertEquals(IBOR_INDEX, ERU2.getIborIndex());
    assertEquals(NOTIONAL, ERU2.getNotional());
    assertEquals(FUTURE_FACTOR, ERU2.getPaymentAccrualFactor());
    assertEquals(DISCOUNTING_CURVE_NAME, ERU2.getDiscountingCurveName());
    assertEquals(FORWARD_CURVE_NAME, ERU2.getForwardCurveName());
    assertEquals(NAME, ERU2.getName());
    assertEquals(FIXING_START_TIME, ERU2.getFixingPeriodStartTime());
    assertEquals(FIXING_END_TIME, ERU2.getFixingPeriodEndTime());
    assertEquals(FIXING_ACCRUAL, ERU2.getFixingPeriodAccrualFactor());
  }

  @Test
  public void equalHash() {
    assertTrue(ERU2.equals(ERU2));
    InterestRateFutureSecurity other =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertTrue(ERU2.equals(other));
    assertTrue(ERU2.hashCode() == other.hashCode());
    assertEquals(ERU2.toString(), other.toString());
    InterestRateFutureSecurity modifiedFuture;
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME - 0.01,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME + 0.01,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME + 0.01,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL + 0.01,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL + 1.0,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR + 0.25,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME + "NO",
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME + "NO");
    assertFalse(ERU2.equals(modifiedFuture));
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            IBOR_INDEX,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME + NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    IborIndex otherIndex =
        new IborIndex(
            CUR, TENOR, SETTLEMENT_DAYS, CALENDAR, DAY_COUNT_INDEX, BUSINESS_DAY, !IS_EOM);
    modifiedFuture =
        new InterestRateFutureSecurity(
            LAST_TRADING_TIME,
            otherIndex,
            FIXING_START_TIME,
            FIXING_END_TIME,
            FIXING_ACCRUAL,
            NOTIONAL,
            FUTURE_FACTOR,
            NAME,
            DISCOUNTING_CURVE_NAME,
            FORWARD_CURVE_NAME);
    assertFalse(ERU2.equals(modifiedFuture));
    assertFalse(ERU2.equals(LAST_TRADING_DATE));
    assertFalse(ERU2.equals(null));
  }
}
/**
 * Tests for the methods related to interest rate securities pricing with Hull-White model convexity
 * adjustment.
 */
public class InterestRateFutureSecurityHullWhiteMethodTest {
  // EURIBOR 3M Index
  private static final Period TENOR = Period.ofMonths(3);
  private static final int SETTLEMENT_DAYS = 2;
  private static final Calendar CALENDAR = new MondayToFridayCalendar("A");
  private static final DayCount DAY_COUNT_INDEX =
      DayCountFactory.INSTANCE.getDayCount("Actual/360");
  private static final BusinessDayConvention BUSINESS_DAY =
      BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Modified Following");
  private static final boolean IS_EOM = true;
  private static final Currency CUR = Currency.EUR;
  private static final IborIndex IBOR_INDEX =
      new IborIndex(CUR, TENOR, SETTLEMENT_DAYS, CALENDAR, DAY_COUNT_INDEX, BUSINESS_DAY, IS_EOM);
  // Future
  private static final ZonedDateTime SPOT_LAST_TRADING_DATE = DateUtil.getUTCDate(2012, 9, 19);
  private static final ZonedDateTime LAST_TRADING_DATE =
      ScheduleCalculator.getAdjustedDate(SPOT_LAST_TRADING_DATE, CALENDAR, -SETTLEMENT_DAYS);
  private static final ZonedDateTime FIXING_END_DATE =
      ScheduleCalculator.getAdjustedDate(
          SPOT_LAST_TRADING_DATE, BUSINESS_DAY, CALENDAR, IS_EOM, TENOR);
  private static final double NOTIONAL = 1000000.0; // 1m
  private static final double FUTURE_FACTOR = 0.25;
  private static final String NAME = "ERU2";
  // Time version
  private static final LocalDate REFERENCE_DATE = LocalDate.of(2011, 5, 12);
  private static final DayCount ACT_ACT =
      DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");
  private static final ZonedDateTime REFERENCE_DATE_ZONED =
      ZonedDateTime.of(LocalDateTime.ofMidnight(REFERENCE_DATE), TimeZone.UTC);
  private static final double LAST_TRADING_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, LAST_TRADING_DATE);
  private static final double FIXING_START_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, SPOT_LAST_TRADING_DATE);
  private static final double FIXING_END_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE_ZONED, FIXING_END_DATE);
  private static final double FIXING_ACCRUAL =
      DAY_COUNT_INDEX.getDayCountFraction(SPOT_LAST_TRADING_DATE, FIXING_END_DATE);
  private static final String DISCOUNTING_CURVE_NAME = "Funding";
  private static final String FORWARD_CURVE_NAME = "Forward";
  private static final InterestRateFutureSecurity ERU2 =
      new InterestRateFutureSecurity(
          LAST_TRADING_TIME,
          IBOR_INDEX,
          FIXING_START_TIME,
          FIXING_END_TIME,
          FIXING_ACCRUAL,
          NOTIONAL,
          FUTURE_FACTOR,
          NAME,
          DISCOUNTING_CURVE_NAME,
          FORWARD_CURVE_NAME);
  private static final double MEAN_REVERSION = 0.01;
  private static final double[] VOLATILITY = new double[] {0.01, 0.011, 0.012, 0.013, 0.014};
  private static final double[] VOLATILITY_TIME = new double[] {0.5, 1.0, 2.0, 5.0};
  private static final HullWhiteOneFactorPiecewiseConstantParameters MODEL_PARAMETERS =
      new HullWhiteOneFactorPiecewiseConstantParameters(
          MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);
  private static final InterestRateFutureSecurityHullWhiteMethod METHOD =
      new InterestRateFutureSecurityHullWhiteMethod(MODEL_PARAMETERS);
  private static final HullWhiteOneFactorPiecewiseConstantInterestRateModel MODEL =
      new HullWhiteOneFactorPiecewiseConstantInterestRateModel();

  @Test
  /** Test the constructors. */
  public void constructor() {
    final InterestRateFutureSecurityHullWhiteMethod methodParameters =
        new InterestRateFutureSecurityHullWhiteMethod(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);
    assertTrue(METHOD.equals(methodParameters));
  }

  @Test
  /** Test the price computed from the curves */
  public void price() {
    final YieldCurveBundle curves = TestsDataSets.createCurves1();
    final double price = METHOD.price(ERU2, curves);
    final YieldAndDiscountCurve forwardCurve = curves.getCurve(FORWARD_CURVE_NAME);
    final double forward =
        (forwardCurve.getDiscountFactor(FIXING_START_TIME)
                    / forwardCurve.getDiscountFactor(FIXING_END_TIME)
                - 1)
            / FIXING_ACCRUAL;
    final double factor = MODEL.futureConvexityFactor(ERU2, MODEL_PARAMETERS);
    final double expectedPrice = 1.0 - factor * forward + (1 - factor) / FIXING_ACCRUAL;
    assertEquals("Future price from curves in Hull-White one factor model", expectedPrice, price);
  }

  @Test
  /** Compare the price with a price without convexity adjustment. */
  public void comparisonDiscounting() {
    final YieldCurveBundle curves = TestsDataSets.createCurves1();
    final InterestRateFutureSecurityDiscountingMethod methodDiscounting =
        InterestRateFutureSecurityDiscountingMethod.getInstance();
    final double priceDiscounting = methodDiscounting.priceFromCurves(ERU2, curves);
    final double priceHullWhite = METHOD.price(ERU2, curves);
    assertTrue(
        "Future price comparison with no convexity adjustment", priceDiscounting > priceHullWhite);
  }

  @Test
  public void equalHash() {
    assertTrue(METHOD.equals(METHOD));
    InterestRateFutureSecurityHullWhiteMethod other =
        new InterestRateFutureSecurityHullWhiteMethod(MODEL_PARAMETERS);
    assertTrue(METHOD.equals(other));
    assertTrue(METHOD.hashCode() == other.hashCode());
    InterestRateFutureSecurityHullWhiteMethod modifiedMethod;
    HullWhiteOneFactorPiecewiseConstantParameters modifiedParameter =
        new HullWhiteOneFactorPiecewiseConstantParameters(
            MEAN_REVERSION * 2, VOLATILITY, VOLATILITY_TIME);
    modifiedMethod = new InterestRateFutureSecurityHullWhiteMethod(modifiedParameter);
    assertFalse(METHOD.equals(modifiedMethod));
    assertFalse(METHOD.equals(CUR));
    assertFalse(METHOD.equals(null));
  }
}