Package com.opengamma.master.security

Examples of com.opengamma.master.security.SecurityMaster


    // create shell portfolio
    final ManageablePortfolio portfolio = createEmptyPortfolio();
    final ManageablePortfolioNode rootNode = portfolio.getRootNode();

    final Collection<UniqueId> loadSecurities = loadSecurities(tickers);
    final SecurityMaster secMaster = getToolContext().getSecurityMaster();
    for (final UniqueId uniqueId : loadSecurities) {
      final SecurityDocument securityDocument = secMaster.get(uniqueId);
      final EquitySecurity security = (EquitySecurity) securityDocument.getSecurity();
      final GICSCode gics = security.getGicsCode();
      if (gics == null || gics.isPartial()) {
        continue;
      }
View Full Code Here


    final Collection<ExternalId> tickers = readEquityTickers();
    createPortfolio(tickers);
  }

  private Collection<UniqueId> loadSecurities(final Collection<ExternalId> identifiers) {
    final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    final SecurityProvider securityProvider = getToolContext().getSecurityProvider();
    final DefaultSecurityLoader securityLoader = new DefaultSecurityLoader(securityMaster, securityProvider);

    final Map<ExternalIdBundle, UniqueId> loadedSecurities = securityLoader.loadSecurities(functional(identifiers).map(new Function1<ExternalId, ExternalIdBundle>() {
      @Override
View Full Code Here

  public static LocalDate getDateWithException(Map<String, String> fieldValueMap, String fieldName) {
    return LocalDate.parse(getWithException(fieldValueMap, fieldName), CSV_DATE_FORMATTER);
  }

  public static void persistLiborRawSecurities(Set<Currency> currencies, ToolContext toolContext) {
    SecurityMaster securityMaster = toolContext.getSecurityMaster();
    byte[] rawData = new byte[] {0};
    StringBuilder sb = new StringBuilder();
    sb.append("Created ").append(currencies.size()).append(" libor securities:\n");
    for (Currency ccy : currencies) {
      ConventionBundle swapConvention = getSwapConventionBundle(ccy, toolContext.getConventionBundleSource());
      ConventionBundle liborConvention = getLiborConventionBundle(swapConvention, toolContext.getConventionBundleSource());
      sb.append("\t").append(liborConvention.getIdentifiers()).append("\n");
      RawSecurity rawSecurity = new RawSecurity(LIBOR_RATE_SECURITY_TYPE, rawData);
      rawSecurity.setExternalIdBundle(liborConvention.getIdentifiers());
      SecurityDocument secDoc = new SecurityDocument();
      secDoc.setSecurity(rawSecurity);
      securityMaster.add(secDoc);
    }
    s_logger.info(sb.toString());
  }
View Full Code Here

  }

  private void loadFutures() {
    final Log log = new Log("Loading Futures reference data");
    try {
      final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
      final SecurityProvider securityProvider = getToolContext().getSecurityProvider();
      final DefaultSecurityLoader securityLoader = new DefaultSecurityLoader(securityMaster, securityProvider);
      securityLoader.loadSecurities(_futuresToLoad);
      _futuresToLoad.clear();
      log.done();
View Full Code Here

      log.fail(t);
    }
  }

  private Iterable<SecurityDocument> readEquitySecurities() {
    final SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    final SecuritySearchRequest request = new SecuritySearchRequest();
    request.setSecurityType(EquitySecurity.SECURITY_TYPE);
    return SecuritySearchIterator.iterable(securityMaster, request);
  }
View Full Code Here

   * @param name the pattern to match securities
   * @param dryRun set to true to not write to the database
   */
  private void createSurfaces(String name, boolean dryRun) {
    ConfigMaster configMaster = getToolContext().getConfigMaster();
    SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    ReferenceDataProvider bbgRefData = getToolContext().getBloombergReferenceDataProvider();

    SecuritySearchRequest securityRequest = new SecuritySearchRequest();
    securityRequest.setName(name);
    securityRequest.setSortOrder(SecuritySearchSortOrder.NAME_ASC);
View Full Code Here

  }

  private void fixCDSOptionsStrike() {

    final MasterConfigSource configSource = new MasterConfigSource(getToolContext().getConfigMaster());
    final SecurityMaster securityMaster = getToolContext().getSecurityMaster();

    String snapshotName = "Sameday spread";
    MarketDataSnapshotSearchRequest marketDataSnapshotSearchRequest = new MarketDataSnapshotSearchRequest();
    marketDataSnapshotSearchRequest.setName(snapshotName);
    MarketDataSnapshotSearchResult marketDataSnapshotSearchResult = getToolContext().getMarketDataSnapshotMaster().search(marketDataSnapshotSearchRequest);
    ManageableMarketDataSnapshot snapshot = marketDataSnapshotSearchResult.getFirstSnapshot();

    PortfolioSearchRequest portfolioSearchRequest = new PortfolioSearchRequest();
    portfolioSearchRequest.setName("CDSOpts");
    //portfolioSearchRequest.setName("Standard CDS Portfolio");
    List<ManageablePortfolio> portfolios = getToolContext().getPortfolioMaster().search(portfolioSearchRequest).getPortfolios();
    for (ManageablePortfolio portfolio : portfolios) {

      List<ObjectId> positionIds = portfolio.getRootNode().getPositionIds();
      List<UniqueId> positionUids = newArrayList();
      for (ObjectId positionId : positionIds) {
        positionUids.add(positionId.atLatestVersion());
      }
      Map<UniqueId, PositionDocument> positions = getToolContext().getPositionMaster().get(positionUids);

      // Ticker, RedCode, Currency, Term, Seniority, RestructuringClause
      final List<ExternalId> cdsArgs = newArrayList();


      final SecureRandom random = new SecureRandom();
      for (PositionDocument positionDocument : positions.values()) {
        ManageablePosition position = positionDocument.getValue();

        ManageableSecurityLink link = position.getSecurityLink();
        SecuritySearchRequest ssr = new SecuritySearchRequest();
        ssr.addExternalIds(link.getExternalIds());
        SecuritySearchResult securitySearchResult = getToolContext().getSecurityMaster().search(ssr);
        Security security = securitySearchResult.getFirstSecurity();
        //Security security = position.getSecurity();
        if (security != null && security instanceof CreditDefaultSwapOptionSecurity) {
          CreditDefaultSwapOptionSecurity cdsOption = (CreditDefaultSwapOptionSecurity) security;
          CreditDefaultSwapSecurity cds = (CreditDefaultSwapSecurity) this.getToolContext().getSecuritySource().getSingle(
              cdsOption.getUnderlyingId().toBundle());

          String curveDefinitionID = "SAMEDAY_" + cds.getReferenceEntity().getValue() + "_" + cds.getNotional().getCurrency() + "_" +
              cds.getDebtSeniority().toString() + "_" + cds.getRestructuringClause();

          ConfigSearchRequest<CurveDefinition> curveDefinitionConfigSearchRequest = new ConfigSearchRequest<CurveDefinition>(CurveDefinition.class);
          curveDefinitionConfigSearchRequest.setName(curveDefinitionID);
          CurveDefinition curveDefinition = getToolContext().getConfigMaster().search(
              curveDefinitionConfigSearchRequest).getFirstValue().getValue();
        /*final CurveDefinition curveDefinition = configSource.getSingle(CurveDefinition.class,
                                                                       curveName,
                                                                       VersionCorrection.LATEST);

        if (curveDefinition == null) {
          throw new OpenGammaRuntimeException("No curve definition for " + curveName);
        }

        //Map<Tenor, CurveNode> curveNodesByTenors = new HashMap<Tenor, CurveNode>();
        //for (CurveNode curveNode : curveDefinition.getNodes()) {
        //  curveNodesByTenors.put(curveNode.getResolvedMaturity(), curveNode);
        //}
        Map<Tenor, CurveNode> curveNodesByTenors = functional(curveDefinition.getNodes()).groupBy(new Function1<CurveNode, Tenor>() {
          @Override
          public Tenor execute(CurveNode curveNode) {
            return curveNode.getResolvedMaturity();
          }
        });*/

          ZonedDateTime start = cds.getStartDate();
          ZonedDateTime maturity = cds.getMaturityDate();
          Period period = Period.between(start.toLocalDate(), maturity.toLocalDate());
          Tenor tenor = Tenor.of(period);


          final CurveNodeIdMapper curveNodeIdMapper = configSource.getSingle(CurveNodeIdMapper.class,
                                                                             curveDefinitionID,
                                                                             VersionCorrection.LATEST);


          try {
            tenor = Tenor.of(Period.ofYears(5));
            ExternalId timeSeriesId = curveNodeIdMapper.getCreditSpreadNodeId(null /* magic null - ask Elaine */, tenor);

           
            Object strikeObj = snapshot.getGlobalValues().getValue(timeSeriesId, "PX_LAST").getMarketValue();
            if ((strikeObj instanceof Double)) {
              cdsOption.setStrike((Double) strikeObj);
            } else {
              throw new OpenGammaRuntimeException(format("Double expected for strike but '%s' found instead.", String.valueOf(strikeObj)));
            }
            //else throw?
            //snapshot.getGlobalValues().getValue()
            //cdsArgs.add(timeSeriesId);
            //loadTimeSeries(newArrayList(timeSeriesId));
            //LocalDate tradeDate = functional(position.getTrades()).first().getTradeDate();
            //Double strike = getFixedRate(random, tradeDate, timeSeriesId);
            securityMaster.update(new SecurityDocument(cdsOption));
          } catch (Exception e) {
            e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
          }
        }
      }
View Full Code Here

                                                                                "EXTERNAL_SENSITIVITIES_SECURITY", "EXTERNAL_SENSITIVITY_RISK_FACTORS");
                                                                                // not enough string conversion stuff there for these yet

  private List<ManageablePosition> loadSomePositions(boolean includeTrades) {
    List<ManageablePosition> positions = new ArrayList<ManageablePosition>();
    SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    SecurityMetaDataRequest metaRequest = new SecurityMetaDataRequest();
    SecurityMetaDataResult metaData = securityMaster.metaData(metaRequest);
    for (String securityType : metaData.getSecurityTypes()) {
      if (UNSUPPORTED_SECURITY_TYPES.contains(securityType)) {
        continue;
      }
      s_logger.info("Processing security type " + securityType);
      SecuritySearchRequest searchRequest = new SecuritySearchRequest();
      searchRequest.setName("*");
      searchRequest.setSecurityType(securityType);
      searchRequest.setPagingRequest(PagingRequest.FIRST_PAGE);
      SecuritySearchResult search = securityMaster.search(searchRequest);
      s_logger.info("Search returned " + search.getPaging().getTotalItems() + " securities");
      List<ManageableSecurity> securities = search.getSecurities();
      int count = 0;
      for (ManageableSecurity security : securities) {
        if (security == null) {
View Full Code Here

    if (getCommandLine().hasOption(EXTERNAL_ID_VALUES_OPT)) {
      securitySearchRequest.setExternalIdValue(
          getCommandLine().getOptionValue(EXTERNAL_ID_VALUES_OPT));
    }
   
    SecurityMaster securityMaster = getToolContext().getSecurityMaster();
    for (SecurityDocument securityDocument : SecuritySearchIterator.iterable(securityMaster, securitySearchRequest)) {
      if (getCommandLine().hasOption(WRITE_OPT)) {
        securityMaster.remove(securityDocument.getUniqueId());
        s_logger.warn("Deleted " + securityDocument.getSecurity().getUniqueId() +
            " (" + securityDocument.getSecurity().getName() + ")");
      } else {
        s_logger.warn("Matched " + securityDocument.getSecurity().getUniqueId() +
            " (" + securityDocument.getSecurity().getName() + ")");
View Full Code Here

  }

  private void persistToPortfolio(final Collection<SwapSecurity> swaps, final String portfolioName) {
    final PortfolioMaster portfolioMaster = getToolContext().getPortfolioMaster();
    final PositionMaster positionMaster = getToolContext().getPositionMaster();
    final SecurityMaster securityMaster = getToolContext().getSecurityMaster();

    final ManageablePortfolioNode rootNode = new ManageablePortfolioNode(portfolioName);
    final ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName, rootNode);
    final PortfolioDocument portfolioDoc = new PortfolioDocument();
    portfolioDoc.setPortfolio(portfolio);

    for (final SwapSecurity swap : swaps) {
      final SecurityDocument swapToAddDoc = new SecurityDocument();
      swapToAddDoc.setSecurity(swap);
      securityMaster.add(swapToAddDoc);
      final ManageablePosition swapPosition = new ManageablePosition(BigDecimal.ONE, swap.getExternalIdBundle());
      final PositionDocument addedDoc = positionMaster.add(new PositionDocument(swapPosition));
      rootNode.addPosition(addedDoc.getUniqueId());
    }
    portfolioMaster.add(portfolioDoc);
View Full Code Here

TOP

Related Classes of com.opengamma.master.security.SecurityMaster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.