// -------------------------------------------------------------------------
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Test
  public void testSearchBonds() {
    BondSecurity target =
        new GovernmentBondSecurity(
            "US TREASURY N/B",
            "Government",
            "US",
            "Treasury",
            Currency.USD,
            YieldConventionFactory.INSTANCE.getYieldConvention("US Treasury equivalent"),
            new Expiry(zdt(2011, 2, 1, 12, 0, 0, 0, ZoneOffset.UTC)),
            "",
            200,
            SimpleFrequencyFactory.INSTANCE.getFrequency(SimpleFrequency.SEMI_ANNUAL_NAME),
            DayCountFactory.INSTANCE.getDayCount("Actual/Actual"),
            zdt(2011, 2, 1, 12, 0, 0, 0, ZoneOffset.UTC),
            zdt(2011, 2, 1, 12, 0, 0, 0, ZoneOffset.UTC),
            zdt(2011, 2, 1, 12, 0, 0, 0, ZoneOffset.UTC),
            100d,
            100000000,
            5000,
            1000,
            100,
            100);
    target.setExternalIdBundle(ExternalIdBundle.of(ExternalId.of("A", "B")));
    Collection targetColl = ImmutableList.<Security>of(target);

    when(_underlying.getBondsWithIssuerName(eq("US TREASURY N/B"))).thenReturn(targetColl);

    Response test = _resource.searchBonds("US TREASURY N/B");
    assertEquals(Status.OK.getStatusCode(), test.getStatus());
    assertEquals(FudgeListWrapper.of(targetColl), test.getEntity());
  }
Ejemplo n.º 2
0
  @BeforeMethod
  public void configureService() {
    MockFinancialSecuritySource securitySource = new MockFinancialSecuritySource();
    ExternalId secId1 = ExternalId.of(ExternalScheme.of("d1"), "v1");
    ExternalId secId2 = ExternalId.of(ExternalScheme.of("d2"), "v2");

    MockSecurity sec1 = new MockSecurity("t1");
    sec1.setExternalIdBundle(ExternalIdBundle.of(secId1));
    sec1.setSecurityType("BOND");
    securitySource.addSecurity(sec1);

    MockSecurity sec2 = new MockSecurity("t2");
    sec2.setExternalIdBundle(ExternalIdBundle.of(secId2));
    securitySource.addSecurity(sec2);

    BondSecurity bondSec =
        new GovernmentBondSecurity(
            "US TREASURY N/B",
            "Government",
            "US",
            "Treasury",
            Currency.USD,
            YieldConventionFactory.INSTANCE.getYieldConvention("US Treasury equivalent"),
            new Expiry(ZonedDateTime.of(2011, 2, 1, 12, 0, 0, 0, TimeZone.UTC)),
            "",
            200,
            SimpleFrequencyFactory.INSTANCE.getFrequency(SimpleFrequency.SEMI_ANNUAL_NAME),
            DayCountFactory.INSTANCE.getDayCount("Actual/Actual"),
            ZonedDateTime.of(2011, 2, 1, 12, 0, 0, 0, TimeZone.UTC),
            ZonedDateTime.of(2011, 2, 1, 12, 0, 0, 0, TimeZone.UTC),
            ZonedDateTime.of(2011, 2, 1, 12, 0, 0, 0, TimeZone.UTC),
            100,
            100000000,
            5000,
            1000,
            100,
            100);
    bondSec.setExternalIdBundle(ExternalIdBundle.of(ExternalId.of("A", "B")));
    securitySource.addSecurity(bondSec);

    getSecuritySourceService().setUnderlying(securitySource);
    _uid1 = sec1.getUniqueId();
    _uid2 = sec2.getUniqueId();
  }
/**
 * Tests related to the pricing of bills security by discounting.
 *
 * @deprecated This class tests deprecated functionality
 */
@Deprecated
public class BillSecurityDiscountingMethodTest {

  private static final Currency EUR = Currency.EUR;
  private static final Calendar CALENDAR = new MondayToFridayCalendar("TARGET");
  private static final ZonedDateTime REFERENCE_DATE = DateUtils.getUTCDate(2012, 1, 17);

  private static final DayCount ACT360 = DayCountFactory.INSTANCE.getDayCount("Actual/360");
  private static final int SETTLEMENT_DAYS = 2;
  private static final YieldConvention YIELD_IAM =
      YieldConventionFactory.INSTANCE.getYieldConvention("INTEREST@MTY");
  private static final YieldConvention YIELD_DSC =
      YieldConventionFactory.INSTANCE.getYieldConvention("DISCOUNT");

  // ISIN: BE0312677462
  private static final String ISSUER_BEL = "BELGIUM GOVT";
  private static final String ISSUER_US = "US GOVT";
  private static final ZonedDateTime END_DATE = DateUtils.getUTCDate(2012, 3, 15);
  private static final double NOTIONAL = 1000;
  private static final double YIELD = 0.00185; // External source
  private static final double PRICE = 0.99971; // External source

  private static final ZonedDateTime SETTLE_DATE =
      ScheduleCalculator.getAdjustedDate(REFERENCE_DATE, SETTLEMENT_DAYS, CALENDAR);
  private static final String[] NAME_CURVES = TestsDataSetsSABR.nameCurvesBond3();
  private static final BillSecurityDefinition BILL_IAM_SEC_DEFINITION =
      new BillSecurityDefinition(
          EUR, END_DATE, NOTIONAL, SETTLEMENT_DAYS, CALENDAR, YIELD_IAM, ACT360, ISSUER_BEL);
  private static final BillSecurityDefinition BILL_DSC_SEC_DEFINITION =
      new BillSecurityDefinition(
          EUR, END_DATE, NOTIONAL, SETTLEMENT_DAYS, CALENDAR, YIELD_DSC, ACT360, ISSUER_US);
  // Should not be in EUR, but this is only a test
  private static final BillSecurity BILL_IAM_SEC =
      BILL_IAM_SEC_DEFINITION.toDerivative(REFERENCE_DATE, SETTLE_DATE, NAME_CURVES);
  private static final BillSecurity BILL_DSC_SEC =
      BILL_DSC_SEC_DEFINITION.toDerivative(REFERENCE_DATE, SETTLE_DATE, NAME_CURVES);
  private static final YieldCurveBundle CURVE_BUNDLE = TestsDataSetsSABR.createCurvesBond3();

  private static final BillSecurityDiscountingMethod METHOD_SECURITY =
      BillSecurityDiscountingMethod.getInstance();
  private static final PresentValueCalculator PVC = PresentValueCalculator.getInstance();
  private static final PresentValueCurveSensitivityCalculator PVCSC =
      PresentValueCurveSensitivityCalculator.getInstance();
  private static final YieldFromCurvesCalculator YFCC = YieldFromCurvesCalculator.getInstance();
  private static final YieldFromPriceCalculator YFPC = YieldFromPriceCalculator.getInstance();

  private static final double TOLERANCE_PV = 1.0E-2;
  private static final double TOLERANCE_PRICE = 1.0E-8;
  private static final double TOLERANCE_PRICE_EXTERNAL = 1.0E-5;
  private static final double TOLERANCE_YIELD = 1.0E-8;
  private static final double TOLERANCE_YIELD_EXTERNAL = 1.0E-4;
  private static final double TOLERANCE_YIELD_DERIVATIVE = 1.0E-6;

  @Test
  /** Tests the present value against explicit computation. */
  public void presentValue() {
    final CurrencyAmount pvComputed = METHOD_SECURITY.presentValue(BILL_IAM_SEC, CURVE_BUNDLE);
    final double pvExpected =
        NOTIONAL
            * CURVE_BUNDLE.getCurve(NAME_CURVES[1]).getDiscountFactor(BILL_IAM_SEC.getEndTime());
    assertEquals(
        "Bill Security: discounting method - present value",
        pvExpected,
        pvComputed.getAmount(),
        TOLERANCE_PV);
  }

  @Test
  /** Tests the present value: Method vs Calculator */
  public void presentValueMethodVsCalculator() {
    final CurrencyAmount pvMethod = METHOD_SECURITY.presentValue(BILL_IAM_SEC, CURVE_BUNDLE);
    final double pvCalculator = BILL_IAM_SEC.accept(PVC, CURVE_BUNDLE);
    assertEquals(
        "Bill Security: discounting method - present value",
        pvMethod.getAmount(),
        pvCalculator,
        TOLERANCE_PV);
  }

  @Test
  public void priceFromYield() {
    final double[] yields = new double[] {0.0010, 0.0, -0.0010};
    for (final double yield2 : yields) {
      final double priceComputed = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, yield2);
      final double priceExpected = 1.0 / (1 + BILL_IAM_SEC.getAccrualFactor() * yield2);
      assertEquals(
          "Bill Security: discounting method - price",
          priceExpected,
          priceComputed,
          TOLERANCE_PRICE);
    }
  }

  @Test
  public void priceFromYieldExternal() {
    final double priceComputed = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, YIELD);
    assertEquals(
        "Bill Security: discounting method - price",
        PRICE,
        priceComputed,
        TOLERANCE_PRICE_EXTERNAL);
  }

  @Test
  public void yieldFromPrice() {
    final double yieldComputedIAM = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
    final double yieldExpectedIAM = (1.0 / PRICE - 1.0) / BILL_IAM_SEC.getAccrualFactor();
    assertEquals(
        "Bill Security: discounting method - yield",
        yieldExpectedIAM,
        yieldComputedIAM,
        TOLERANCE_YIELD);
    final double yieldComputedDSC = METHOD_SECURITY.yieldFromPrice(BILL_DSC_SEC, PRICE);
    final double yieldExpectedDSC = (1.0 - PRICE) / BILL_DSC_SEC.getAccrualFactor();
    assertEquals(
        "Bill Security: discounting method - yield",
        yieldExpectedDSC,
        yieldComputedDSC,
        TOLERANCE_YIELD);
  }

  @Test
  public void yieldFromPriceDerivative() {
    final double shift = 1.0E-8;
    final double yieldIAM = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
    final double yieldPIAM = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE + shift);
    final double yieldDerivativeExpectedIAM = (yieldPIAM - yieldIAM) / shift;
    final double yieldDerivativeComputedIAM =
        METHOD_SECURITY.yieldFromPriceDerivative(BILL_IAM_SEC, PRICE);
    assertEquals(
        "Bill Security: discounting method - yield",
        yieldDerivativeExpectedIAM,
        yieldDerivativeComputedIAM,
        TOLERANCE_YIELD_DERIVATIVE);
    final double yieldDSC = METHOD_SECURITY.yieldFromPrice(BILL_DSC_SEC, PRICE);
    final double yieldPDSC = METHOD_SECURITY.yieldFromPrice(BILL_DSC_SEC, PRICE + shift);
    final double yieldDerivativeExpectedDSC = (yieldPDSC - yieldDSC) / shift;
    final double yieldDerivativeComputedDSC =
        METHOD_SECURITY.yieldFromPriceDerivative(BILL_DSC_SEC, PRICE);
    assertEquals(
        "Bill Security: discounting method - yield",
        yieldDerivativeExpectedDSC,
        yieldDerivativeComputedDSC,
        TOLERANCE_YIELD_DERIVATIVE);
  }

  @Test
  public void yieldFromPriceExternal() {
    final double yieldComputed = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
    assertEquals(
        "Bill Security: discounting method - yield",
        YIELD,
        yieldComputed,
        TOLERANCE_YIELD_EXTERNAL);
  }

  @Test
  public void yieldFromPriceCoherence() {
    final double priceComputed = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, YIELD);
    final double yieldComputed = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, priceComputed);
    assertEquals(
        "Bill Security: discounting method - yield", YIELD, yieldComputed, TOLERANCE_YIELD);
  }

  @Test
  public void priceFromYieldCoherence() {
    final double yieldComputed = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
    final double priceComputed = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, yieldComputed);
    assertEquals(
        "Bill Security: discounting method - price", PRICE, priceComputed, TOLERANCE_PRICE);
  }

  @Test
  public void presentValueFromPrice() {
    final CurrencyAmount pvComputed =
        METHOD_SECURITY.presentValueFromPrice(BILL_IAM_SEC, PRICE, CURVE_BUNDLE);
    final double pvExpected =
        NOTIONAL
            * PRICE
            * CURVE_BUNDLE
                .getCurve(NAME_CURVES[0])
                .getDiscountFactor(BILL_IAM_SEC.getSettlementTime());
    assertEquals(
        "Bill Security: discounting method - present value",
        pvExpected,
        pvComputed.getAmount(),
        TOLERANCE_PV);
  }

  @Test
  public void presentValueFromYield() {
    final CurrencyAmount pvComputed =
        METHOD_SECURITY.presentValueFromYield(BILL_IAM_SEC, YIELD, CURVE_BUNDLE);
    final double price = METHOD_SECURITY.priceFromYield(BILL_IAM_SEC, YIELD);
    final double pvExpected =
        NOTIONAL
            * price
            * CURVE_BUNDLE
                .getCurve(NAME_CURVES[0])
                .getDiscountFactor(BILL_IAM_SEC.getSettlementTime());
    assertEquals(
        "Bill Security: discounting method - present value",
        pvExpected,
        pvComputed.getAmount(),
        TOLERANCE_PV);
  }

  @Test
  public void priceFromCurves() {
    final double priceComputed = METHOD_SECURITY.priceFromCurves(BILL_IAM_SEC, CURVE_BUNDLE);
    final CurrencyAmount pvComputed = METHOD_SECURITY.presentValue(BILL_IAM_SEC, CURVE_BUNDLE);
    final double priceExpected =
        pvComputed.getAmount()
            / (NOTIONAL
                * CURVE_BUNDLE
                    .getCurve(NAME_CURVES[0])
                    .getDiscountFactor(BILL_IAM_SEC.getSettlementTime()));
    assertEquals(
        "Bill Security: discounting method - price", priceExpected, priceComputed, TOLERANCE_PRICE);
  }

  @Test
  public void yieldFromCurves() {
    final double yieldComputed = METHOD_SECURITY.yieldFromCurves(BILL_IAM_SEC, CURVE_BUNDLE);
    final double priceComputed = METHOD_SECURITY.priceFromCurves(BILL_IAM_SEC, CURVE_BUNDLE);
    final double yieldExpected = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, priceComputed);
    assertEquals(
        "Bill Security: discounting method - yield", yieldExpected, yieldComputed, TOLERANCE_YIELD);
  }

  @Test
  public void presentValueCurveSensitivity() {
    final InterestRateCurveSensitivity pvcsComputed =
        METHOD_SECURITY.presentValueCurveSensitivity(BILL_IAM_SEC, CURVE_BUNDLE);
    assertEquals(
        "Bill Security: present value curve sensitivity",
        1,
        pvcsComputed.getSensitivities().size());
    assertEquals(
        "Bill Security: present value curve sensitivity",
        1,
        pvcsComputed.getSensitivities().get(NAME_CURVES[1]).size());
    final double deltaTolerancePrice = 1.0E+2;
    // Testing note: Sensitivity is for a movement of 1. 1E+2 = 0.01 unit for a 1 bp move.
    final double deltaShift = 1.0E-6;
    // Credit curve sensitivity
    final String bumpedCurveName = "Bumped Curve";
    final BillSecurity billBumped =
        BILL_IAM_SEC_DEFINITION.toDerivative(REFERENCE_DATE, NAME_CURVES[0], bumpedCurveName);
    final double[] nodeTimes = new double[] {billBumped.getEndTime()};
    final double[] sensi =
        SensitivityFiniteDifference.curveSensitivity(
            billBumped,
            CURVE_BUNDLE,
            NAME_CURVES[1],
            bumpedCurveName,
            nodeTimes,
            deltaShift,
            METHOD_SECURITY);
    final List<DoublesPair> sensiPv = pvcsComputed.getSensitivities().get(NAME_CURVES[1]);
    for (int loopnode = 0; loopnode < sensi.length; loopnode++) {
      final DoublesPair pairPv = sensiPv.get(loopnode);
      assertEquals(
          "Bill Security: curve sensitivity - Node " + loopnode,
          nodeTimes[loopnode],
          pairPv.getFirst(),
          1E-8);
      AssertJUnit.assertEquals(
          "Bill Security: curve sensitivity", pairPv.second, sensi[loopnode], deltaTolerancePrice);
    }
  }

  @Test
  public void presentValueCurveSensitivityMethodVsCalculator() {
    final InterestRateCurveSensitivity pvcsMethod =
        METHOD_SECURITY.presentValueCurveSensitivity(BILL_IAM_SEC, CURVE_BUNDLE);
    final InterestRateCurveSensitivity pvcsCalculator =
        new InterestRateCurveSensitivity(BILL_IAM_SEC.accept(PVCSC, CURVE_BUNDLE));
    AssertSensivityObjects.assertEquals(
        "Bill Security: discounting method - curve sensitivity",
        pvcsMethod,
        pvcsCalculator,
        TOLERANCE_PV);
  }

  @Test
  public void methodVsCalculator() {
    double yield1 = METHOD_SECURITY.yieldFromCurves(BILL_IAM_SEC, CURVE_BUNDLE);
    double yield2 = BILL_IAM_SEC.accept(YFCC, CURVE_BUNDLE);
    assertEquals(
        "Bill Security: discounting method - yield from curves", yield1, yield2, TOLERANCE_YIELD);
    yield1 = METHOD_SECURITY.yieldFromPrice(BILL_IAM_SEC, PRICE);
    yield2 = BILL_IAM_SEC.accept(YFPC, PRICE);
    assertEquals(
        "Bill Security: discounting method - yield from price", yield1, yield2, TOLERANCE_YIELD);
  }
}
Ejemplo n.º 4
0
/** Tests related to bond futures security Derivative construction. */
public class BondFutureTest {
  // 5-Year U.S. Treasury Note Futures: FVU1
  private static final Currency CUR = Currency.EUR;
  private static final Period PAYMENT_TENOR = Period.ofMonths(6);
  private static final Calendar CALENDAR = new MondayToFridayCalendar("A");
  private static final String ISSUER_NAME = "Issuer";
  private static final DayCount DAY_COUNT =
      DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");
  private static final BusinessDayConvention BUSINESS_DAY =
      BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Following");
  private static final boolean IS_EOM = false;
  private static final int SETTLEMENT_DAYS = 1;
  private static final YieldConvention YIELD_CONVENTION =
      YieldConventionFactory.INSTANCE.getYieldConvention("STREET CONVENTION");
  private static final int NB_BOND = 7;
  private static final Period[] BOND_TENOR =
      new Period[] {
        Period.ofYears(5),
        Period.ofYears(5),
        Period.ofYears(5),
        Period.ofYears(8),
        Period.ofYears(5),
        Period.ofYears(5),
        Period.ofYears(5)
      };
  private static final ZonedDateTime[] START_ACCRUAL_DATE =
      new ZonedDateTime[] {
        DateUtils.getUTCDate(2010, 11, 30),
        DateUtils.getUTCDate(2010, 12, 31),
        DateUtils.getUTCDate(2011, 1, 31),
        DateUtils.getUTCDate(2008, 2, 29),
        DateUtils.getUTCDate(2011, 3, 31),
        DateUtils.getUTCDate(2011, 4, 30),
        DateUtils.getUTCDate(2011, 5, 31)
      };
  private static final double[] RATE =
      new double[] {0.01375, 0.02125, 0.0200, 0.02125, 0.0225, 0.0200, 0.0175};
  private static final double[] CONVERSION_FACTOR =
      new double[] {.8317, .8565, .8493, .8516, .8540, .8417, .8292};
  private static final ZonedDateTime[] MATURITY_DATE = new ZonedDateTime[NB_BOND];
  private static final BondFixedSecurityDefinition[] BASKET_DEFINITION =
      new BondFixedSecurityDefinition[NB_BOND];

  static {
    for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) {
      MATURITY_DATE[loopbasket] = START_ACCRUAL_DATE[loopbasket].plus(BOND_TENOR[loopbasket]);
      BASKET_DEFINITION[loopbasket] =
          BondFixedSecurityDefinition.from(
              CUR,
              MATURITY_DATE[loopbasket],
              START_ACCRUAL_DATE[loopbasket],
              PAYMENT_TENOR,
              RATE[loopbasket],
              SETTLEMENT_DAYS,
              CALENDAR,
              DAY_COUNT,
              BUSINESS_DAY,
              YIELD_CONVENTION,
              IS_EOM,
              ISSUER_NAME);
    }
  }

  private static final ZonedDateTime LAST_TRADING_DATE = DateUtils.getUTCDate(2011, 9, 21);
  private static final ZonedDateTime FIRST_NOTICE_DATE = DateUtils.getUTCDate(2011, 8, 31);
  private static final ZonedDateTime LAST_NOTICE_DATE = DateUtils.getUTCDate(2011, 9, 29);
  private static final ZonedDateTime FIRST_DELIVERY_DATE =
      ScheduleCalculator.getAdjustedDate(FIRST_NOTICE_DATE, SETTLEMENT_DAYS, CALENDAR);
  private static final ZonedDateTime LAST_DELIVERY_DATE =
      ScheduleCalculator.getAdjustedDate(LAST_NOTICE_DATE, SETTLEMENT_DAYS, CALENDAR);
  private static final double NOTIONAL = 100000;
  private static final double REF_PRICE = 0.0;

  private static final ZonedDateTime REFERENCE_DATE = DateUtils.getUTCDate(2011, 6, 20);
  private static final DayCount ACT_ACT =
      DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");
  private static final double LAST_TRADING_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE, LAST_TRADING_DATE);
  private static final double FIRST_NOTICE_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE, FIRST_NOTICE_DATE);
  private static final double LAST_NOTICE_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE, LAST_NOTICE_DATE);
  private static final double FIRST_DELIVERY_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE, FIRST_DELIVERY_DATE);
  private static final double LAST_DELIVERY_TIME =
      ACT_ACT.getDayCountFraction(REFERENCE_DATE, LAST_DELIVERY_DATE);
  private static final BondFixedSecurity[] BASKET = new BondFixedSecurity[NB_BOND];

  static {
    for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) {
      BASKET[loopbasket] =
          BASKET_DEFINITION[loopbasket].toDerivative(REFERENCE_DATE, LAST_DELIVERY_DATE);
    }
  }

  private static final BondFuture BOND_FUTURE_SECURITY =
      new BondFuture(
          LAST_TRADING_TIME,
          FIRST_NOTICE_TIME,
          LAST_NOTICE_TIME,
          FIRST_DELIVERY_TIME,
          LAST_DELIVERY_TIME,
          NOTIONAL,
          BASKET,
          CONVERSION_FACTOR,
          REF_PRICE);

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullBasket() {
    new BondFuture(
        LAST_TRADING_TIME,
        FIRST_NOTICE_TIME,
        LAST_NOTICE_TIME,
        FIRST_DELIVERY_TIME,
        LAST_DELIVERY_TIME,
        NOTIONAL,
        null,
        CONVERSION_FACTOR,
        REF_PRICE);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullConversion() {
    new BondFuture(
        LAST_TRADING_TIME,
        FIRST_NOTICE_TIME,
        LAST_NOTICE_TIME,
        FIRST_DELIVERY_TIME,
        LAST_DELIVERY_TIME,
        NOTIONAL,
        BASKET,
        null,
        REF_PRICE);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void zeroBasket() {
    new BondFuture(
        LAST_TRADING_TIME,
        FIRST_NOTICE_TIME,
        LAST_NOTICE_TIME,
        FIRST_DELIVERY_TIME,
        LAST_DELIVERY_TIME,
        NOTIONAL,
        new BondFixedSecurity[0],
        CONVERSION_FACTOR,
        REF_PRICE);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void sizeConversionFactor() {
    final double[] incorrectConversionFactor = new double[NB_BOND - 1];
    new BondFuture(
        LAST_TRADING_TIME,
        FIRST_NOTICE_TIME,
        LAST_NOTICE_TIME,
        FIRST_DELIVERY_TIME,
        LAST_DELIVERY_TIME,
        NOTIONAL,
        BASKET,
        incorrectConversionFactor,
        REF_PRICE);
  }

  @Test
  public void getter() {
    assertEquals(
        "Bond future security derivative: last trading date",
        LAST_TRADING_TIME,
        BOND_FUTURE_SECURITY.getTradingLastTime());
    assertEquals(
        "Bond future security derivative: first notice date",
        FIRST_NOTICE_TIME,
        BOND_FUTURE_SECURITY.getNoticeFirstTime());
    assertEquals(
        "Bond future security derivative: last notice date",
        LAST_NOTICE_TIME,
        BOND_FUTURE_SECURITY.getNoticeLastTime());
    assertEquals(
        "Bond future security derivative: first delivery date",
        FIRST_DELIVERY_TIME,
        BOND_FUTURE_SECURITY.getDeliveryFirstTime());
    assertEquals(
        "Bond future security derivative: last delivery date",
        LAST_DELIVERY_TIME,
        BOND_FUTURE_SECURITY.getDeliveryLastTime());
    assertEquals(
        "Bond future security derivative: basket",
        BASKET,
        BOND_FUTURE_SECURITY.getDeliveryBasket());
    assertEquals(
        "Bond future security derivative: conversion factor",
        CONVERSION_FACTOR,
        BOND_FUTURE_SECURITY.getConversionFactor());
    assertEquals(
        "Bond future security derivative: notional", NOTIONAL, BOND_FUTURE_SECURITY.getNotional());
    assertEquals(
        "Bond future security derivative: currency", CUR, BOND_FUTURE_SECURITY.getCurrency());
  }

  @Test
  /** Tests the equal and hashCode methods. */
  public void equalHash() {
    assertTrue(BOND_FUTURE_SECURITY.equals(BOND_FUTURE_SECURITY));
    final BondFuture other =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertTrue(BOND_FUTURE_SECURITY.equals(other));
    assertTrue(BOND_FUTURE_SECURITY.hashCode() == other.hashCode());
    BondFuture modifiedFuture;
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME + 0.1,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME + 0.1,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME + 0.1,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME + 0.1,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME + 0.1,
            NOTIONAL,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL + 100000,
            BASKET,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    final BondFixedSecurity[] otherBasket = new BondFixedSecurity[NB_BOND];
    for (int loopbasket = 0; loopbasket < NB_BOND; loopbasket++) {
      otherBasket[loopbasket] =
          BASKET_DEFINITION[loopbasket].toDerivative(REFERENCE_DATE, LAST_NOTICE_DATE);
    }
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            otherBasket,
            CONVERSION_FACTOR,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    final double[] otherConversionFactor =
        new double[] {.9000, .8565, .8493, .8516, .8540, .8417, .8292};
    modifiedFuture =
        new BondFuture(
            LAST_TRADING_TIME,
            FIRST_NOTICE_TIME,
            LAST_NOTICE_TIME,
            FIRST_DELIVERY_TIME,
            LAST_DELIVERY_TIME,
            NOTIONAL,
            BASKET,
            otherConversionFactor,
            REF_PRICE);
    assertFalse(BOND_FUTURE_SECURITY.equals(modifiedFuture));
    assertFalse(BOND_FUTURE_SECURITY.equals(LAST_TRADING_DATE));
    assertFalse(BOND_FUTURE_SECURITY.equals(null));
  }
}
Ejemplo n.º 5
0
/** Tests related to the construction of bills transaction. */
public class BillTransactionTest {

  private static final Currency EUR = Currency.EUR;
  private static final Calendar CALENDAR = new MondayToFridayCalendar("TARGET");
  private static final ZonedDateTime REFERENCE_DATE = DateUtils.getUTCDate(2012, 1, 16);

  private static final DayCount ACT360 = DayCountFactory.INSTANCE.getDayCount("Actual/360");
  private static final int SETTLEMENT_DAYS = 2;
  private static final YieldConvention YIELD_CONVENTION =
      YieldConventionFactory.INSTANCE.getYieldConvention("INTEREST@MTY");

  private static final String ISSUER_BEL = "BELGIUM GOVT";
  private static final ZonedDateTime END_DATE = DateUtils.getUTCDate(2012, 2, 29);
  private static final double NOTIONAL = 1000;
  private static final BillSecurityDefinition BILL_SEC_DEFINITION =
      new BillSecurityDefinition(
          EUR, END_DATE, NOTIONAL, SETTLEMENT_DAYS, CALENDAR, YIELD_CONVENTION, ACT360, ISSUER_BEL);

  private static final double QUANTITY = 123456;
  private static final ZonedDateTime SETTLE_DATE =
      ScheduleCalculator.getAdjustedDate(REFERENCE_DATE, 3, CALENDAR);
  private static final double SETTLE_AMOUT = -NOTIONAL * QUANTITY * 99.95;

  private static final String DSC_NAME = "EUR Discounting";
  private static final String CREDIT_NAME = "EUR BELGIUM GOVT";

  private static final BillSecurity BILL_PURCHASE =
      BILL_SEC_DEFINITION.toDerivative(REFERENCE_DATE, SETTLE_DATE, DSC_NAME, CREDIT_NAME);
  private static final BillSecurity BILL_STANDARD =
      BILL_SEC_DEFINITION.toDerivative(REFERENCE_DATE, DSC_NAME, CREDIT_NAME);
  private static final BillTransaction BILL_TRA =
      new BillTransaction(BILL_PURCHASE, QUANTITY, SETTLE_AMOUT, BILL_STANDARD);

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void nullPurchase() {
    new BillTransaction(null, QUANTITY, SETTLE_AMOUT, BILL_STANDARD);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void nullStandard() {
    new BillTransaction(BILL_PURCHASE, QUANTITY, SETTLE_AMOUT, null);
  }

  @Test
  /** Tests the bill getters. */
  public void getters() {
    assertEquals("Bill transation: getter", BILL_PURCHASE, BILL_TRA.getBillPurchased());
    assertEquals("Bill transation: getter", QUANTITY, BILL_TRA.getQuantity());
    assertEquals("Bill transation: getter", SETTLE_AMOUT, BILL_TRA.getSettlementAmount());
    assertEquals("Bill transation: getter", BILL_STANDARD, BILL_TRA.getBillStandard());
  }

  @Test
  /** Tests the equal and hash-code methods. */
  public void equalHash() {
    assertEquals("Bill transaction: equal-hash code", BILL_TRA, BILL_TRA);
    BillTransaction other =
        new BillTransaction(BILL_PURCHASE, QUANTITY, SETTLE_AMOUT, BILL_STANDARD);
    assertEquals("Bill transaction: equal-hash code", BILL_TRA, other);
    assertEquals("Bill transaction: equal-hash code", BILL_TRA.hashCode(), other.hashCode());
    BillTransaction modified;
    modified = new BillTransaction(BILL_STANDARD, QUANTITY, SETTLE_AMOUT, BILL_STANDARD);
    assertFalse("Bill transaction: equal-hash code", BILL_TRA.equals(modified));
    modified = new BillTransaction(BILL_PURCHASE, QUANTITY + 1.0, SETTLE_AMOUT, BILL_STANDARD);
    assertFalse("Bill transaction: equal-hash code", BILL_TRA.equals(modified));
    modified = new BillTransaction(BILL_PURCHASE, QUANTITY, SETTLE_AMOUT + 1.0, BILL_STANDARD);
    assertFalse("Bill transaction: equal-hash code", BILL_TRA.equals(modified));
    modified = new BillTransaction(BILL_PURCHASE, QUANTITY, SETTLE_AMOUT, BILL_PURCHASE);
    assertFalse("Bill transaction: equal-hash code", BILL_TRA.equals(modified));
  }
}
public class BondFixedDescriptionTest {

  // Semi-annual 2Y
  private static final Currency CUR = Currency.USD;
  private static final Period PAYMENT_TENOR = Period.ofMonths(6);
  private static final int PAYMENT_PER_YEAR = 2;
  private static final Calendar CALENDAR = new MondayToFridayCalendar("A");
  private static final DayCount DAY_COUNT =
      DayCountFactory.INSTANCE.getDayCount("Actual/Actual ICMA");
  private static final BusinessDayConvention BUSINESS_DAY =
      BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention("Following");
  private static final boolean IS_EOM = false;
  private static final Period BOND_TENOR = Period.ofYears(2);
  private static final ZonedDateTime START_ACCRUAL_DATE = DateUtil.getUTCDate(2011, 7, 13);
  private static final ZonedDateTime MATURITY_DATE = START_ACCRUAL_DATE.plus(BOND_TENOR);
  private static final double RATE = 0.0325;
  private static final YieldConvention YIELD_CONVENTION =
      YieldConventionFactory.INSTANCE.getYieldConvention("STREET CONVENTION");
  private static final AnnuityCouponFixedDefinition COUPON_DEFINITION =
      AnnuityCouponFixedDefinition.fromAccrualUnadjusted(
          CUR,
          START_ACCRUAL_DATE,
          MATURITY_DATE,
          PAYMENT_TENOR,
          PAYMENT_PER_YEAR,
          CALENDAR,
          DAY_COUNT,
          BUSINESS_DAY,
          IS_EOM,
          1.0,
          RATE,
          false);
  private static final AnnuityPaymentFixedDefinition NOMINAL_DEFINITION =
      new AnnuityPaymentFixedDefinition(
          new PaymentFixedDefinition[] {new PaymentFixedDefinition(CUR, MATURITY_DATE, 1.0)});
  // to derivatives: common
  private static final String FUNDING_CURVE_NAME = "Funding";
  private static final String FORWARD_CURVE_NAME = "Forward";
  private static final String[] CURVES_NAME = {FUNDING_CURVE_NAME, FORWARD_CURVE_NAME};
  YieldCurveBundle CURVES = TestsDataSets.createCurves1();
  // to derivatives: first coupon
  private static final ZonedDateTime REFERENCE_DATE_1 = DateUtil.getUTCDate(2011, 8, 18);
  private static final AnnuityCouponFixed COUPON_1 =
      COUPON_DEFINITION.toDerivative(REFERENCE_DATE_1, CURVES_NAME);
  private static final AnnuityPaymentFixed NOMINAL_1 =
      NOMINAL_DEFINITION.toDerivative(REFERENCE_DATE_1, CURVES_NAME);
  private static final BondFixedDescription BOND_DESCRIPTION_1 =
      new BondFixedDescription(NOMINAL_1, COUPON_1, YIELD_CONVENTION);
  // to derivatives: second coupon
  private static final ZonedDateTime REFERENCE_DATE_2 = DateUtil.getUTCDate(2012, 2, 16);
  private static final AnnuityCouponFixed COUPON_2 =
      COUPON_DEFINITION.toDerivative(REFERENCE_DATE_2, CURVES_NAME);
  private static final AnnuityPaymentFixed NOMINAL_2 =
      NOMINAL_DEFINITION.toDerivative(REFERENCE_DATE_2, CURVES_NAME);
  private static final BondFixedDescription BOND_DESCRIPTION_2 =
      new BondFixedDescription(NOMINAL_2, COUPON_2, YIELD_CONVENTION);

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullNominal() {
    new BondFixedDescription(null, COUPON_1, YIELD_CONVENTION);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullCoupon() {
    new BondFixedDescription(NOMINAL_1, null, YIELD_CONVENTION);
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testNullYield() {
    new BondFixedDescription(NOMINAL_1, COUPON_1, null);
  }

  @Test
  public void testGetters1() {
    assertEquals(NOMINAL_1, BOND_DESCRIPTION_1.getNominal());
    assertEquals(COUPON_1, BOND_DESCRIPTION_1.getCoupon());
  }

  @Test
  public void testGetters2() {
    assertEquals(NOMINAL_2, BOND_DESCRIPTION_2.getNominal());
    assertEquals(COUPON_2, BOND_DESCRIPTION_2.getCoupon());
  }
}