Package com.opengamma.core.position

Examples of com.opengamma.core.position.Portfolio


      for (final String calcConfigName : viewDefinition.getAllCalculationConfigurationNames()) {
        ViewCalculationConfiguration calcConfig = viewDefinition.getCalculationConfiguration(calcConfigName);
        final ValueMappings valueMappings = new ValueMappings(_compiledViewDef);
        final ViewCalculationResultModel calculationResult = _viewComputationResultModel.getCalculationResult(calcConfigName);
        final Map<String, Set<Pair<String, ValueProperties>>> portfolioRequirementsBySecurityType = calcConfig.getPortfolioRequirementsBySecurityType();
        Portfolio portfolio = _compiledViewDef.getPortfolio();
        PortfolioNodeTraverser traverser = new DepthFirstPortfolioNodeTraverser(new PortfolioNodeTraversalCallback() {
         
          @Override
          public void preOrderOperation(PortfolioNode parentNode, Position position) {
            UniqueId positionId = position.getUniqueId().toLatest();
            // then construct a chained target spec pointing at a specific position.
            ComputationTargetSpecification breadcrumbTargetSpec = ComputationTargetSpecification.of(parentNode).containing(ComputationTargetType.POSITION, positionId);
            ComputationTargetSpecification targetSpec = ComputationTargetSpecification.of(position);
            Map<Pair<String, ValueProperties>, ComputedValueResult> values = calculationResult.getValues(targetSpec);
            String securityType = position.getSecurity().getSecurityType();
            Set<Pair<String, ValueProperties>> valueRequirements = portfolioRequirementsBySecurityType.get(securityType);
            s_logger.error("Processing valueRequirement " + valueRequirements + " for security type " + securityType);
            if (valueRequirements != null) {
              for (Pair<String, ValueProperties> valueRequirement : valueRequirements) {
                ColumnRequirementBySecurityType keyBySec = ColumnRequirementBySecurityType.of(securityType, ColumnRequirement.of(valueRequirement.getFirst(), valueRequirement.getSecond()));
                ValueRequirement valueReq = new ValueRequirement(valueRequirement.getFirst(), breadcrumbTargetSpec, valueRequirement.getSecond());
                ColumnRequirement key = ColumnRequirement.of(valueRequirement.getFirst(), valueRequirement.getSecond());
                ValueSpecification valueSpec = valueMappings.getValueSpecification(calcConfigName, valueReq);
                if (valueSpec == null) {
                  s_logger.error("Couldn't get reverse value spec mapping from requirement: " + valueReq.toString());
                  incCount(_failureCountBySec, keyBySec);
                  incCount(_failureCount, key);
                  _failures.increment();                 
                } else {
                  ObjectsPair<String, ValueProperties> valueKey = Pair.of(valueSpec.getValueName(), valueSpec.getProperties());
                  ComputedValueResult computedValueResult = values != null ? values.get(valueKey) : null;
                  if (computedValueResult != null) {
                    if (computedValueResult.getValue() instanceof MissingValue) {
                      incCount(_errorCountBySec, keyBySec);
                      incCount(_errorCount, key);
                      _errors.increment();
                    } else {
                      incCount(_successCountBySec, keyBySec);
                      incCount(_successCount, key);
                      _successes.increment();
                    }
                  } else {
                    incCount(_failureCountBySec, keyBySec);
                    incCount(_failureCount, key);
                    _failures.increment();
                  }
                }
                incCount(_totalCountBySec, keyBySec);
                incCount(_totalCount, key);
                _total.increment();
              }
            }
          }
         
          @Override
          public void preOrderOperation(PortfolioNode portfolioNode) {
          }
         
          @Override
          public void postOrderOperation(PortfolioNode parentNode, Position position) {
          }
         
          @Override
          public void postOrderOperation(PortfolioNode portfolioNode) {
          }
         
          private <T> void incCount(Map<T, MutableInt> countMap,
                                T key) {
            if (!countMap.containsKey(key)) {
              countMap.put(key, new MutableInt(1));
            } else {
              countMap.get(key).increment();
            }         
          }
        });
        traverser.traverse(portfolio.getRootNode());       
      }
      convertToJMXComposites();   
    } catch (NullPointerException npe) {
      s_logger.error("NPE", npe);
    }
View Full Code Here


  @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

  @Test
  public void testEmptyPortfolioIsReturnedWhenAllNodesAreDenied() {

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

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createDenyNodeChecker()).generateRestrictedPortfolio(pf);

    assertThat(portfolio.getRootNode().size(), is(0));
    assertThat(portfolio.getName(), is("Access Denied"));
  }
View Full Code Here

    4 is allowed
    Portfolio should just contain 1, 2 & 4 (1 is a restricted version though)

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

    Map<Integer, PortfolioPermission> permissions = ImmutableMap.of(
        1, ALLOW,
        2, ALLOW,
        3, DENY,
        4, ALLOW);

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createMappedNodeChecker(permissions)).generateRestrictedPortfolio(pf);

    assertThat(portfolio.getName(), is("node-1 [restricted]"));



    PortfolioNode rootNode = portfolio.getRootNode();
    assertThat(rootNode.getName(), is("node-1 [restricted]"));
    List<PortfolioNode> children = rootNode.getChildNodes();
    assertThat(children.size(), is(2));
    assertThat(children.get(0).getName(), is("node-2"));
    assertThat(children.get(1).getName(), is("node-4"));
View Full Code Here

    4 is denied
    Portfolio should just contain 2

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

    Map<Integer, PortfolioPermission> permissions = ImmutableMap.of(
        1, ALLOW,
        2, ALLOW,
        3, DENY,
        4, DENY);

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createMappedNodeChecker(permissions)).generateRestrictedPortfolio(pf);

    assertThat(portfolio.getName(), is("node-2"));
    PortfolioNode rootNode = portfolio.getRootNode();
    assertThat(rootNode.getName(), is("node-2"));
    assertThat(rootNode.getChildNodes().size(), is(0));
  }
View Full Code Here

                          nodeTree(5,
                                   nodeTree(6),
                                   nodeTree(7))),
                 nodeTree(3),
                 nodeTree(4));
    Portfolio pf = new SimplePortfolio("node-1", root);

    Map<Integer, PortfolioPermission> permissions =
        ImmutableMap.<Integer, PortfolioPermission>builder()
            .put(1, ALLOW)
            .put(2, ALLOW)
            .put(3, DENY)
            .put(4, DENY)
            .put(5, ALLOW)
            .put(6, ALLOW)
            .put(7, ALLOW)
            .build();

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createMappedNodeChecker(permissions)).generateRestrictedPortfolio(pf);

    assertThat(portfolio.getName(), is("node-5"));
    PortfolioNode rootNode = portfolio.getRootNode();
    assertThat(rootNode.getName(), is("node-5"));
    List<PortfolioNode> children = rootNode.getChildNodes();
    assertThat(children.size(), is(2));
    assertThat(children.get(0).getName(), is("node-6"));
    assertThat(children.get(1).getName(), is("node-7"));
View Full Code Here

                                   nodeTree(15)),
                          nodeTree(8,
                                   nodeTree(16),
                                   nodeTree(17))));

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

    Map<Integer, PortfolioPermission> permissions =
        ImmutableMap.<Integer, PortfolioPermission> builder()
          .put(1, ALLOW)
          .put(2, ALLOW)
          .put(3, ALLOW)
          .put(4, ALLOW)
          .put(5, ALLOW)
          .put(6, ALLOW)
          .put(7, DENY)
          .put(8, ALLOW)
          .put(9, ALLOW)
          .put(10, ALLOW)
          .put(11, DENY)
          .put(12, ALLOW)
          .put(13, ALLOW)
          .put(14, ALLOW)
          .put(15, DENY)
          .put(16, DENY)
          .build();

    Portfolio portfolio = new NodeCheckingPortfolioFilter(createMappedNodeChecker(permissions)).generateRestrictedPortfolio(pf);

    assertThat(portfolio.getName(), is("node-1 [restricted]"));
    PortfolioNode rootNode = portfolio.getRootNode();
    assertThat(rootNode.getName(), is("node-1 [restricted]"));
    List<PortfolioNode> n1children = rootNode.getChildNodes();
    assertThat(n1children.size(), is(2));

    PortfolioNode n2 = n1children.get(0);
View Full Code Here

    functions.addFunction(new MockFunction("F3", new ComputationTarget(ComputationTargetType.SECURITY, createSecurity(UniqueId.of("Pos", "0"), ExternalId.of("Security", "Foo")))));
    return functions;
  }

  private CompiledViewDefinitionWithGraphs createCompiledViewDefinitionWithGraphs() {
    final Portfolio portfolio = createPortfolio();
    final ViewDefinition viewDefinition = createViewDefinition();
    final ViewCalculationConfiguration calcConfig = new ViewCalculationConfiguration(viewDefinition, "Default");
    viewDefinition.addViewCalculationConfiguration(calcConfig);
    final DependencyGraph graph = createDependencyGraph();
    final Collection<DependencyGraph> graphs = Collections.singleton(graph);
View Full Code Here

TOP

Related Classes of com.opengamma.core.position.Portfolio

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.