Package com.opengamma.core.position.impl

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


      // No portfolio requirements for this calculation configuration - avoid further processing.
      return;
    }
    final Portfolio portfolio = builder.getCompilationContext().getPortfolio();
    final PortfolioCompilerTraversalCallback traversalCallback = new PortfolioCompilerTraversalCallback(calcConfig, builder, context.getActiveResolutions(), includeEvents, excludeEvents);
    final PortfolioNodeTraverser traverser = PortfolioNodeTraverser.parallel(traversalCallback, context.getServices().getExecutorService());
    if (isStripedPortfolioRequirements()) {
      final Map<String, Set<Pair<String, ValueProperties>>> requirementsBySecurityType = traversalCallback.getPortfolioRequirementsBySecurityType();
      Map<String, Set<Pair<String, ValueProperties>>> requirementSubSet = Maps.newHashMapWithExpectedSize(requirementsBySecurityType.size());
      traversalCallback.setPortfolioRequirementsBySecurityType(requirementSubSet);
      for (Pair<String, ValueProperties> stripe : getStripes(requirementsBySecurityType)) {
        s_logger.debug("Adding {} portfolio requirement stripe", stripe);
        final Set<Pair<String, ValueProperties>> stripeRequirements = Collections.singleton(stripe);
        for (Map.Entry<String, Set<Pair<String, ValueProperties>>> securityTypeRequirement : requirementsBySecurityType.entrySet()) {
          if (securityTypeRequirement.getValue().contains(stripe)) {
            requirementSubSet.put(securityTypeRequirement.getKey(), stripeRequirements);
          } else {
            requirementSubSet.remove(securityTypeRequirement.getKey());
          }
        }
        traversalCallback.reset();
        traverser.traverse(portfolio.getRootNode());
        try {
          s_logger.debug("Waiting for stripe {} to complete", stripe);
          // TODO: Waiting for a completion state causes any progress tracker to abort (it sees 100% and stops). Need to rethink how to do the progress estimates.
          builder.waitForDependencyGraphBuild();
        } catch (InterruptedException e) {
          throw new OpenGammaRuntimeException("Interrupted during striped compilation", e);
        }
      }
    } else {
      s_logger.debug("Adding all portfolio requirements directly");
      traverser.traverse(portfolio.getRootNode());
    }
  }
View Full Code Here


        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

TOP

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

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.