示例#1
0
 private Map<String, String> getBondFutureBasket(ManageableSecurity security) {
   Map<String, String> result = new TreeMap<String, String>();
   if (security instanceof BondFutureSecurity) {
     BondFutureSecurity bondFutureSecurity = (BondFutureSecurity) security;
     List<BondFutureDeliverable> basket = bondFutureSecurity.getBasket();
     for (BondFutureDeliverable bondFutureDeliverable : basket) {
       String identifierValue =
           bondFutureDeliverable.getIdentifiers().getValue(ExternalSchemes.BLOOMBERG_BUID);
       result.put(
           ExternalSchemes.BLOOMBERG_BUID.getName() + "-" + identifierValue,
           String.valueOf(bondFutureDeliverable.getConversionFactor()));
     }
   }
   return result;
 }
 @Test(groups = {"bbgSecurityFutureTests"})
 public void euroBondFuture() throws Exception {
   ExternalIdBundle euroBund =
       ExternalIdBundle.of(ExternalSchemes.bloombergTickerSecurityId("RXA Comdty"));
   Security bond = _securityProvider.getSecurity(euroBund);
   assertNotNull(bond);
   assertTrue(bond instanceof BondFutureSecurity);
   BondFutureSecurity euroBondFuture = (BondFutureSecurity) bond;
   assertEquals("FUTURE", euroBondFuture.getSecurityType());
   assertEquals("Bond", euroBondFuture.getContractCategory());
   assertEquals(EUR, euroBondFuture.getCurrency());
   String displayName = euroBondFuture.getName();
   assertNotNull(displayName);
   assertTrue(displayName.contains("EURO-BUND FUTURE"));
   Expiry expiry = euroBondFuture.getExpiry();
   assertNotNull(expiry);
   assertTrue(expiry.toInstant().isAfter(getTodayInstant()));
   assertEquals("XEUR", euroBondFuture.getTradingExchange());
   assertEquals("XEUR", euroBondFuture.getSettlementExchange());
   // assert identifiers are set
   Collection<ExternalId> identifiers = euroBondFuture.getExternalIdBundle().getExternalIds();
   assertNotNull(identifiers);
   assertTrue(identifiers.size() >= EXPECTED_IDENTIFICATION_SCHEME.length);
   ExternalIdBundle identifierBundle = ExternalIdBundle.of(identifiers);
   for (ExternalScheme expectedIDScheme : EXPECTED_IDENTIFICATION_SCHEME) {
     assertNotNull(identifierBundle.getExternalId(expectedIDScheme));
   }
   // assert deliverables are not empty
   Collection<BondFutureDeliverable> basket = euroBondFuture.getBasket();
   assertNotNull(basket);
   for (BondFutureDeliverable bondFutureDeliverable : basket) {
     ExternalIdBundle bundle = bondFutureDeliverable.getIdentifiers();
     assertNotNull(bundle);
     assertNotNull(bundle.getExternalId(ExternalSchemes.BLOOMBERG_BUID));
     assertTrue(bondFutureDeliverable.getConversionFactor() > 0);
   }
 }
  /**
   * Get US bond future security for testing
   *
   * @return the bond future security
   */
  public static BondFutureSecurity getBondFutureSecurity() {
    Expiry expiry =
        new Expiry(
            ZonedDateTime.of(LocalDateTime.of(2010, Month.JUNE, 21, 19, 0), ZoneOffset.UTC),
            ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR);
    Set<BondFutureDeliverable> basket = new HashSet<BondFutureDeliverable>();
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810EV6")), 1.0858));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FB9")), 1.0132));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810PX0")), 0.7984));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FG8")), 0.9169));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810QD3")), 0.7771));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FF0")), 0.9174));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810PW2")), 0.7825));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FE3")), 0.9454));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810QH4")), 0.7757));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810PU6")), 0.8675));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810EX2")), 1.0765));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FT0")), 0.8054));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FJ2")), 1.0141));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810PT9")), 0.8352));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810QE1")), 0.8109));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FP8")), 0.9268));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810QA9")), 0.6606));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FM5")), 1.0286));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810EY0")), 1.0513));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810QB7")), 0.7616));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810QC5")), 0.795));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810EZ7")), 1.0649));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810EW4")), 1.0));
    basket.add(
        new BondFutureDeliverable(
            ExternalIdBundle.of(ExternalSchemes.bloombergBuidSecurityId("GV912810FA1")), 1.0396));

    BondFutureSecurity sec =
        new BondFutureSecurity(
            expiry,
            "XCBT",
            "XCBT",
            Currency.USD,
            1000,
            basket,
            LocalDate.of(2010, 6, 01).atStartOfDay(ZoneOffset.UTC),
            LocalDate.of(2010, 6, 01).atStartOfDay(ZoneOffset.UTC),
            "Bond");
    sec.setName("US LONG BOND(CBT) Jun10");
    Set<ExternalId> identifiers = new HashSet<ExternalId>();
    identifiers.add(ExternalSchemes.bloombergBuidSecurityId("IX8530684-0"));
    identifiers.add(ExternalSchemes.cusipSecurityId("USM10"));
    identifiers.add(ExternalSchemes.bloombergTickerSecurityId("USM10 Comdty"));
    sec.setExternalIdBundle(ExternalIdBundle.of(identifiers));
    return sec;
  }