Package com.opengamma.master.portfolio

Examples of com.opengamma.master.portfolio.ManageablePortfolioNode$Meta


  protected void createPortfolio(final Collection<ExternalId> tickers) {

    // 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;
      }
      final String sector = SECTORS.get(gics.getSectorCode());
      final String industryGroup = gics.getIndustryGroupCode();
      final String industry = gics.getIndustryCode();
      final String subIndustry = gics.getSubIndustryCode();

      // create portfolio structure
      ManageablePortfolioNode sectorNode = rootNode.findNodeByName(sector);
      if (sectorNode == null) {
        s_logger.debug("Creating node for sector {}", sector);
        sectorNode = new ManageablePortfolioNode(sector);
        rootNode.addChildNode(sectorNode);
      }
      ManageablePortfolioNode groupNode = sectorNode.findNodeByName("Group " + industryGroup);
      if (groupNode == null) {
        s_logger.debug("Creating node for industry group {}", industryGroup);
        groupNode = new ManageablePortfolioNode("Group " + industryGroup);
        sectorNode.addChildNode(groupNode);
      }
      ManageablePortfolioNode industryNode = groupNode.findNodeByName("Industry " + industry);
      if (industryNode == null) {
        s_logger.debug("Creating node for industry {}", industry);
        industryNode = new ManageablePortfolioNode("Industry " + industry);
        groupNode.addChildNode(industryNode);
      }
      ManageablePortfolioNode subIndustryNode = industryNode.findNodeByName("Sub industry " + subIndustry);
      if (subIndustryNode == null) {
        s_logger.debug("Creating node for sub industry {}", subIndustry);
        subIndustryNode = new ManageablePortfolioNode("Sub industry " + subIndustry);
        industryNode.addChildNode(subIndustryNode);
      }

      // create the position and add it to the master
      final ManageablePosition position = createPositionAndTrade(security);
      final PositionDocument addedPosition = addPosition(position);

      // add the position reference (the unique identifier) to portfolio
      subIndustryNode.addPosition(addedPosition.getUniqueId());
    }

    // adds the complete tree structure to the master
    addPortfolio(portfolio);
  }
View Full Code Here


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

      String portfolioName = "Portfolio";
      PortfolioDocument a = new PortfolioDocument();
      a.setPortfolio( new ManageablePortfolio(portfolioName));
      _prtMaster.add(a);
      for (int j = 0;j<10;j++){
        ManageablePortfolioNode child = new ManageablePortfolioNode("X");
        child.addChildNode(new ManageablePortfolioNode("Y"));
        a.getPortfolio().getRootNode().addChildNode(child);
        _prtMaster.update(a);
      }
     
      PortfolioDocument b = new PortfolioDocument();
      b.setPortfolio( new ManageablePortfolio(portfolioName));
      for (int j = 0;j<10;j++){
        ManageablePortfolioNode childB = new ManageablePortfolioNode("X");
        childB.addChildNode(new ManageablePortfolioNode("Y"));
        b.getPortfolio().getRootNode().addChildNode(childB);
      }
      _prtMaster.add(b);
 
      for (int j = 0;j<10;j++){
        ManageablePortfolioNode child = new ManageablePortfolioNode("X");
        child.addChildNode(new ManageablePortfolioNode("Y"));
        a.getPortfolio().getRootNode().addChildNode(child);
        _prtMaster.update(a);
       
        PortfolioSearchRequest request = new PortfolioSearchRequest();
        request.setName(portfolioName);
View Full Code Here

    position.addTrade(createTrade(security));
    return position;
  }
 
  private ManageablePortfolioNode createNode(final String nodeName, final Collection<? extends ManageableSecurity> securities) {
    final ManageablePortfolioNode node = new ManageablePortfolioNode(nodeName);
    for (ManageableSecurity security : securities) {
      final ManageablePosition position = createPosition(security);
      node.addPosition(_positions.add(new PositionDocument(position)).getObjectId());
    }
    return node;
  }
View Full Code Here

    }
    return node;
  }
 
  private void createPortfolio(final String portfolioName, final Iterable<ManageablePortfolioNode> nodes) {
    final ManageablePortfolioNode rootNode = new ManageablePortfolioNode("ROOT");
    final ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName, rootNode);
    for (ManageablePortfolioNode node : nodes) {
      rootNode.addChildNode(node);
    }
    _portfolios.add(new PortfolioDocument(portfolio));
  }
View Full Code Here

      return startNode;
    }

    for (ManageablePortfolioNode childNode : startNode.getChildNodes()) {
      if (path[0].equals(childNode.getName())) {
        ManageablePortfolioNode result = findNode((String[]) ArrayUtils.subarray(path, 1, path.length), childNode);
        if (result != null) {
          return result;
        }
      }
    }
View Full Code Here

    }
    return null;
  }
 
  private ManageablePortfolioNode getOrCreateNode(String[] path, ManageablePortfolioNode startNode) {
    ManageablePortfolioNode node = startNode;
    for (String p : path) {
      ManageablePortfolioNode foundNode = null;
      for (ManageablePortfolioNode n : node.getChildNodes()) {
        if (n.getName().equals(p)) {
          foundNode = n;
          break;
        }
      }
      if (foundNode == null) {
        ManageablePortfolioNode newNode = new ManageablePortfolioNode(p);
        node.addChildNode(newNode);
        node = newNode;
      } else {
        node = foundNode;
      }
View Full Code Here

    _portfolioDocument = portSearchResult.getFirstDocument();

    // If it doesn't, create it (add)
    if (_portfolioDocument == null) {
      // Create a new root node
      ManageablePortfolioNode rootNode = new ManageablePortfolioNode(portfolioName);

      ManageablePortfolio portfolio = new ManageablePortfolio(portfolioName, rootNode);
      _portfolioDocument = new PortfolioDocument();
      _portfolioDocument.setPortfolio(portfolio);
      _portfolioDocument = _portfolioMaster.add(_portfolioDocument);
      _originalRoot = null;
      _originalNode = null;

      // Set current node to the root node
      _currentNode = rootNode;

      // If it does, create a new version of the existing portfolio (update)
    } else {
      ManageablePortfolio portfolio = _portfolioDocument.getPortfolio();
      _originalRoot = portfolio.getRootNode();
      _originalNode = _originalRoot;

      if (_keepCurrentPositions) {
        // Use the original root node
        portfolio.setRootNode(cloneTree(_originalRoot));
        _portfolioDocument.setPortfolio(portfolio);

        // Set current node to the root node
        _currentNode = portfolio.getRootNode();
      } else {
        // Create a new root node
        ManageablePortfolioNode rootNode;
        rootNode = JodaBeanUtils.clone(_originalRoot);
        rootNode.setChildNodes(new ArrayList<ManageablePortfolioNode>());
        rootNode.setPositionIds(new ArrayList<ObjectId>());
        portfolio.setRootNode(rootNode);
        _portfolioDocument.setPortfolio(portfolio);

        // Set current node to the root node
        _currentNode = rootNode;
View Full Code Here

      }
    }
  }

  private static ManageablePortfolioNode cloneTree(final ManageablePortfolioNode originalRoot) {
    ManageablePortfolioNode newRoot = JodaBeanUtils.clone(originalRoot);
    newRoot.setChildNodes(new ArrayList<ManageablePortfolioNode>());
    for (ManageablePortfolioNode child : originalRoot.getChildNodes()) {
      newRoot.addChildNode(cloneTree(child));
    }
    return newRoot;
  }
View Full Code Here

   
    ArgumentChecker.notNull(rowParser, "rowParser");
    _rowParser = rowParser;

    // create virtual manageable portfolio
    _currentNode = new ManageablePortfolioNode("Root");
    _portfolio = new ManageablePortfolio("Portfolio", _currentNode);
    _currentNode.setPortfolioId(_portfolio.getUniqueId());

    _includeTrades = includeTrades;
  }
View Full Code Here

TOP

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

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.