Package com.opengamma.core.position.impl

Examples of com.opengamma.core.position.impl.SimplePortfolioNode


    ArgumentChecker.notNull(uniqueId, "uniqueId");
    final ManageablePortfolioNode manNode = getPortfolioMaster().getNode(uniqueId);
    if (manNode == null) {
      throw new DataNotFoundException("Unable to find node: " + uniqueId);
    }
    final SimplePortfolioNode node = new SimplePortfolioNode();
    convertNode(manNode, node, versionCorrection);
    return node;
  }
View Full Code Here


    position.addTrade(sampleTrade(attribSource));
    return position;
  }

  private static SimplePortfolioNode samplePortfolioNode(final AtomicInteger attribSource, final int depth) {
    final SimplePortfolioNode node = new SimplePortfolioNode();
    node.setName("Node " + attribSource.getAndIncrement());
    if (depth > 0) {
      node.addChildNode(samplePortfolioNode(attribSource, depth - 1));
      node.addChildNode(samplePortfolioNode(attribSource, depth - 1));
    }
    node.addPosition(samplePosition(attribSource));
    node.addPosition(samplePosition(attribSource));
    return node;
  }
View Full Code Here

    return node;
  }

  private static Portfolio samplePortfolio() {
    final AtomicInteger num = new AtomicInteger();
    final SimplePortfolioNode root = new SimplePortfolioNode();
    root.setName("Sample");
    root.addChildNode(samplePortfolioNode(num, 2));
    root.addChildNode(samplePortfolioNode(num, 2));
    return new SimplePortfolio(UniqueId.of("Test", "Sample"), "Sample", root);
  }
View Full Code Here

  public Portfolio aggregate(Portfolio inputPortfolio, String portfolioName) {
    ArgumentChecker.notEmpty(portfolioName, "portfolioName");
    List<Position> flattenedPortfolio = Lists.newArrayList();
    flatten(inputPortfolio.getRootNode(), flattenedPortfolio);
    final SimplePortfolioNode root = new SimplePortfolioNode(portfolioName);
    for (List<AggregationFunction<?>> aggregationFunctions : _aggregationFunctionsList) {
      final SimplePortfolioNode aggregateRoot = new SimplePortfolioNode(buildPortfolioNodeName(aggregationFunctions));
      aggregate(aggregateRoot, flattenedPortfolio, new ArrayDeque<>(aggregationFunctions));
      root.addChildNode(aggregateRoot);
    }
    return new SimplePortfolio(portfolioName, root);
  }
View Full Code Here

          buckets.put(name, list);
        }
      }
    }
    for (String bucketName : buckets.keySet()) {
      SimplePortfolioNode newNode = new SimplePortfolioNode();
      newNode.setParentNodeId(inputNode.getUniqueId());
      newNode.setName(bucketName);
      inputNode.addChildNode(newNode);
      List<Position> bucket = buckets.get(bucketName);
      Collections.sort(bucket, nextFunction.getPositionComparator());
      if (functionList.isEmpty() || bucket.isEmpty()) { //IGN-138 - don't build huge empty portfolios
        for (Position position : bucket) {
          newNode.addPosition(position);
        }
      } else {
        aggregate(newNode, bucket, new ArrayDeque<>(functionList)); // make a copy for each bucket.
      }
    }
View Full Code Here

  private Portfolio createPortfolioForNode(PortfolioNode node) {

    return new SimplePortfolio(
        UniqueId.of("RESTRICTED_PORTFOLIO", "PF_" + s_portfolioId++),
        node.getName(),
        new SimplePortfolioNode(node));
  }
View Full Code Here

        return Optional.of(node);
      case DENY:
        return Optional.absent();
      default:

        SimplePortfolioNode newRoot =
            new SimplePortfolioNode(UniqueId.of("RESTRICTED_NODE", "PN_" + s_portfolioNodeId++),
                                    node.getName() + " [restricted]");
        newRoot.addPositions(node.getPositions());

        for (Map.Entry<PortfolioNode, PortfolioPermission> entry : getAccessibleChildNodes(node, checker).entrySet()) {
          PortfolioNode childNode = entry.getValue() == ALLOW ?
              entry.getKey() :
              buildRestrictedRootNode(checker, entry.getKey()).get();
          newRoot.addChildNode(childNode);
        }

        return Optional.of(newRoot);
    }
  }
View Full Code Here

    return _wildcardIndicator;
  }

  //------------------------------------------------------------------------
  private static SimplePortfolioNode copyNode(final PortfolioNode node, final Integer maxNodes, final Integer maxPositions) {
    final SimplePortfolioNode copy = new SimplePortfolioNode(node.getUniqueId(), node.getName());
    if (maxNodes != null && maxNodes > 0) {
      final List<PortfolioNode> childNodes = node.getChildNodes();
      int size = childNodes.size();
      if (size > 0) {
        if (size > maxNodes) {
          size = maxNodes;
        }
        for (int i = 0; i < size; i++) {
          copy.addChildNode(copyNode(childNodes.get(i), maxNodes, maxPositions));
        }
      }
    } else if (maxNodes == null) {
      for (final PortfolioNode child : node.getChildNodes()) {
        copy.addChildNode(copyNode(child, maxNodes, maxPositions));
      }
    }
    if (maxPositions != null && maxPositions > 0) {
      final List<Position> positions = node.getPositions();
      int size = positions.size();
      if (size > 0) {
        if (size > maxPositions) {
          size = maxPositions;
        }
        for (int i = 0; i < size; i++) {
          copy.addPosition(positions.get(i));
        }
      }
    } else if (maxPositions == null) {
      copy.addPositions(node.getPositions());
    }
    return copy;
  }
View Full Code Here

public class NodeCheckingPortfolioFilterTest {

  @Test
  public void testSingleNodePortfolioIsUnalteredWhenAllNodesAreAllowed() {

    SimplePortfolioNode root = nodeTree(1);
    Portfolio pf = new SimplePortfolio("node-1", root);

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createAllowNodeChecker()).generateRestrictedPortfolio(pf);
    assertThat(portfolio == pf, is(true));
  }
View Full Code Here

  }

  @Test
  public void testMultiNodePortfolioIsUnalteredWhenAllNodesAreAllowed() {

    SimplePortfolioNode root = nodeTree(1, nodeTree(2, nodeTree(4)), nodeTree(3));
    Portfolio pf = new SimplePortfolio("node-1", root);

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createAllowNodeChecker()).generateRestrictedPortfolio(pf);
    assertThat(portfolio == pf, is(true));
  }
View Full Code Here

TOP

Related Classes of com.opengamma.core.position.impl.SimplePortfolioNode

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.