Ejemplo n.º 1
0
 private ManageableSecurity getSecurity(ExternalId underlyingIdentifier) {
   if (underlyingIdentifier == null) {
     return null;
   }
   SecurityMaster securityMaster = data().getSecurityMaster();
   SecuritySearchRequest request = new SecuritySearchRequest();
   request.addExternalId(underlyingIdentifier);
   SecuritySearchResult search = securityMaster.search(request);
   return search.getFirstSecurity();
 }
 private ManageableSecurity getOrLoadSecurity(final ExternalId ticker) {
   final SecuritySearchResult underlyingSearch =
       getToolContext().getSecurityMaster().search(new SecuritySearchRequest(ticker));
   switch (underlyingSearch.getDocuments().size()) {
     case 0:
       s_logger.debug("Loading security for underlying {}", ticker);
       return loadSecurity(ticker);
     case 1:
       return underlyingSearch.getSingleSecurity();
     default:
       // Duplicate securities in the master
       s_logger.info(
           "Multiple securities matched search for ticker {}. Using the first. {}",
           ticker,
           underlyingSearch);
       return underlyingSearch.getFirstSecurity();
   }
 }
  // -------------------------------------------------------------------------
  @Test(enabled = false)
  public void test_bond() throws Exception {
    ZonedDateTime zdt = ZonedDateTime.parse("2011-01-31T12:00Z[Europe/London]");
    GovernmentBondSecurity sec =
        new GovernmentBondSecurity(
            "US TREASURY N/B",
            "issuerType",
            "issuerDomicile",
            "market",
            Currency.GBP,
            SimpleYieldConvention.US_TREASURY_EQUIVALANT,
            new Expiry(zdt),
            "couponType",
            23.5d,
            SimpleFrequency.ANNUAL,
            DayCountFactory.INSTANCE.getDayCount("Act/Act"),
            zdt,
            zdt,
            zdt,
            129d,
            1324d,
            12d,
            1d,
            2d,
            3d);
    sec.addExternalId(ExternalId.of("abc", "def"));
    SecurityDocument addDoc = new SecurityDocument(sec);
    SecurityDocument added = _secMaster.add(addDoc);

    SecurityDocument loaded = _secMaster.get(added.getUniqueId());
    assertEquals(added, loaded);

    BondSecuritySearchRequest request = new BondSecuritySearchRequest();
    request.setIssuerName("*TREASURY*");
    SecuritySearchResult result = _secMaster.search(request);
    assertEquals(1, result.getDocuments().size());
    assertEquals(loaded, result.getFirstDocument());
  }