Package com.opengamma.master.portfolio

Examples of com.opengamma.master.portfolio.ManageablePortfolioNode


  private void persistToPortfolio(final Collection<FinancialSecurity> securities, 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 FinancialSecurity security : securities) {
      final SecurityDocument securityToAddDoc = new SecurityDocument();
      securityToAddDoc.setSecurity(security);
      securityMaster.add(securityToAddDoc);
      final ManageablePosition position = new ManageablePosition(BigDecimal.ONE, security.getExternalIdBundle());
      final PositionDocument addedDoc = positionMaster.add(new PositionDocument(position));
      rootNode.addPosition(addedDoc.getUniqueId());
    }
    portfolioMaster.add(portfolioDoc);
  }
View Full Code Here


   */
  @Override
  protected void doRun() {
    // create shell portfolio
    final ManageablePortfolio portfolio = createPortfolio();
    final ManageablePortfolioNode rootNode = portfolio.getRootNode();
   
    // add each security to the portfolio
    for (SecurityDocument shellDoc : loadAllBondSecurities()) {
      // load the full detail of the security
      final BondSecurity security = loadFullSecurity(shellDoc);
     
      // build the tree structure
      final ManageablePortfolioNode issuerNode = buildPortfolioTree(rootNode, security);
     
      // create the position and add it to the master
      final ManageablePosition position = createPosition(security);
      final PositionDocument addedPosition = addPosition(position);
     
      // add the position reference (the unique identifier) to portfolio
      issuerNode.addPosition(addedPosition.getUniqueId());
    }
   
    // adds the complete tree structure to the master
    addPortfolio(portfolio);
  }
View Full Code Here

   *
   * @return the shell portfolio, not null
   */
  protected ManageablePortfolio createPortfolio() {
    ManageablePortfolio portfolio = new ManageablePortfolio(PORTFOLIO_NAME);
    ManageablePortfolioNode rootNode = portfolio.getRootNode();
    rootNode.setName("Root");
    return portfolio;
  }
View Full Code Here

   * @param security  the bond security, not null
   * @return the lowest child node, not null
   */
  protected ManageablePortfolioNode buildPortfolioTree(ManageablePortfolioNode rootNode, BondSecurity security) {
    String domicile = security.getIssuerDomicile();
    ManageablePortfolioNode domicileNode = rootNode.findNodeByName(domicile);
    if (domicileNode == null) {
      s_logger.info("Creating node for domicile {}", domicile);
      domicileNode = new ManageablePortfolioNode(domicile);
      rootNode.addChildNode(domicileNode);
    }
   
    String issuerType = security.getIssuerType();
    ManageablePortfolioNode issuerTypeNode = domicileNode.findNodeByName(issuerType);
    if (issuerTypeNode == null) {
      s_logger.info("Creating node for issuer type {}", issuerType);
      issuerTypeNode = new ManageablePortfolioNode(issuerType);
      domicileNode.addChildNode(issuerTypeNode);
    }
   
    String issuerName = security.getIssuerName();
    ManageablePortfolioNode issuerNode = issuerTypeNode.findNodeByName(issuerName);
    if (issuerNode == null) {
      s_logger.info("Creating node for isssuer {}", issuerName);
      issuerNode = new ManageablePortfolioNode(issuerName);
      issuerTypeNode.addChildNode(issuerNode);
    }
    return issuerNode;
  }
View Full Code Here

    private void buildNode(final ResultSet rs, final long nodeId) throws SQLException {
      final long nodeOid = rs.getLong("NODE_OID");
      final long treeLeft = rs.getLong("TREE_LEFT");
      final long treeRight = rs.getLong("TREE_RIGHT");
      final String name = StringUtils.defaultString(rs.getString("NODE_NAME"));
      _node = new ManageablePortfolioNode(name);
      _nodePositionIds = new HashSet<ObjectId>(); //To maintain invariant this becomes is empty
      _node.setUniqueId(createUniqueId(nodeOid, nodeId));
      _node.setPortfolioId(_portfolio.getUniqueId());
      if (_nodes.size() == 0) {
        if (_complete == false) {
          final Long parentNodeId = (Long) rs.getObject("PARENT_NODE_ID");
          final Long parentNodeOid = (Long) rs.getObject("PARENT_NODE_OID");
          if (parentNodeId != null && parentNodeOid != null) {
            _node.setParentNodeId(createUniqueId(parentNodeOid, parentNodeId));
          }
        }
        _portfolio.setRootNode(_node);
      } else {
        while (treeLeft > _nodes.peek().first) {
          _nodes.pop();
        }
        final ManageablePortfolioNode parentNode = _nodes.peek().second;
        _node.setParentNodeId(parentNode.getUniqueId());
        parentNode.addChildNode(_node);
      }
      // add to stack
      _nodes.push(LongObjectPair.of(treeRight, _node));
    }
View Full Code Here

    }
    return id;
  }

  private ManageablePortfolioNode createManageablePortfolioNode(final PortfolioNode node) {
    final ManageablePortfolioNode manageableNode = new ManageablePortfolioNode();
    manageableNode.setName(node.getName());
    final List<PortfolioNode> childNodes = node.getChildNodes();
    final List<ManageablePortfolioNode> manageableChildNodes = new ArrayList<ManageablePortfolioNode>(childNodes.size());
    // TODO: put a hook here so a sub-class can choose to flatten the portfolio if it wishes
    for (PortfolioNode childNode : childNodes) {
      manageableChildNodes.add(createManageablePortfolioNode(childNode));
    }
    manageableNode.setChildNodes(manageableChildNodes);
    final List<Position> positions = node.getPositions();
    final List<ObjectId> positionIdentifiers = new ArrayList<ObjectId>(positions.size());
    for (Position position : positions) {
      positionIdentifiers.add(mapPositionIdentifier(position));
    }
    manageableNode.setPositionIds(positionIdentifiers);
    return manageableNode;
  }
View Full Code Here

  private void persistToPortfolio(final Collection<Collection<FinancialSecurity>> subPortfolios, final Collection<String> names, 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);

    final Iterator<Collection<FinancialSecurity>> iter1 = subPortfolios.iterator();
    final Iterator<String> iter2 = names.iterator();
    final Random random = new Random(2349);
    while (iter1.hasNext()) {
      final Collection<FinancialSecurity> securities = iter1.next();
      final String name = iter2.next();
      final ManageablePortfolioNode subNode = new ManageablePortfolioNode(name);
      final ManageablePortfolio subPortfolio = new ManageablePortfolio(name, subNode);
      final PortfolioDocument subPortfolioDoc = new PortfolioDocument();
      subPortfolioDoc.setPortfolio(subPortfolio);
      for (final FinancialSecurity security : securities) {
        final SecurityDocument securityToAddDoc = new SecurityDocument();
        securityToAddDoc.setSecurity(security);
        securityMaster.add(securityToAddDoc);
        BigDecimal trades;
        if (security instanceof FutureSecurity) {
          trades = new BigDecimal(1 + (random.nextInt(150) - 75));
        } else {
          trades = BigDecimal.ONE;
        }
        final ManageablePosition securityPosition = new ManageablePosition(trades, security.getExternalIdBundle());
        final PositionDocument addedDoc = positionMaster.add(new PositionDocument(securityPosition));
        subNode.addPosition(addedDoc.getUniqueId());
      }
      portfolioMaster.add(subPortfolioDoc);
      rootNode.addChildNode(subNode);
    }
    portfolioMaster.add(portfolioDoc);
View Full Code Here

                                   _portfolioMaster,
                                   _securityMaster,
                                   BlotterUtils.getMetaBeans(),
                                   BlotterUtils.getStringConvert());
    ManageablePortfolio portfolio = new ManageablePortfolio();
    ManageablePortfolioNode root = new ManageablePortfolioNode();
    ManageablePortfolioNode node = new ManageablePortfolioNode();
    root.addChildNode(node);
    portfolio.setRootNode(root);
    _savedPortfolio = _portfolioMaster.add(new PortfolioDocument(portfolio)).getPortfolio();
    _nodeId = _savedPortfolio.getRootNode().getChildNodes().get(0).getUniqueId();
  }
View Full Code Here

    assertEquals(PREMIUM_TIME, trade.getPremiumTime());
    assertEquals(TRADE_TIME, trade.getTradeTime());
    assertEquals(ATTRIBUTES, trade.getAttributes());

    // can't check the node ID as nodes are completely replaced
    ManageablePortfolioNode loadedRoot = _portfolioMaster.get(_savedPortfolio.getUniqueId()).getPortfolio().getRootNode();
    ManageablePortfolioNode loadedNode = loadedRoot.getChildNodes().get(0);
    assertEquals(1, loadedNode.getPositionIds().size());
    assertEquals(positionId.getObjectId(), loadedNode.getPositionIds().get(0));
  }
View Full Code Here

    assertEquals(PREMIUM_TIME, trade.getPremiumTime());
    assertEquals(TRADE_TIME, trade.getTradeTime());
    assertEquals(ATTRIBUTES, trade.getAttributes());

    // can't check the node ID as nodes are completely replaced
    ManageablePortfolioNode loadedRoot = _portfolioMaster.get(_savedPortfolio.getUniqueId()).getPortfolio().getRootNode();
    ManageablePortfolioNode loadedNode = loadedRoot.getChildNodes().get(0);
    assertEquals(1, loadedNode.getPositionIds().size());
    assertEquals(positionId.getObjectId(), loadedNode.getPositionIds().get(0));

    SecuritySearchRequest searchRequest = new SecuritySearchRequest();
    searchRequest.setExternalIdSearch(new ExternalIdSearch(underlyingId));
    SecuritySearchResult searchResult = _securityMaster.search(searchRequest);
    ManageableSecurity underlying = searchResult.getSingleSecurity();
View Full Code Here

TOP

Related Classes of com.opengamma.master.portfolio.ManageablePortfolioNode

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.