public Portfolio filter(final Portfolio inputPortfolio) {
   return new SimplePortfolio(
       UniqueId.of(
           inputPortfolio.getUniqueId().getScheme(),
           buildPortfolioName(inputPortfolio.getUniqueId().getValue())),
       buildPortfolioName(inputPortfolio.getName()),
       filter(inputPortfolio.getRootNode()));
 }
Example #2
0
 private static List<PortfolioRow> flattenPortfolio(final Portfolio portfolio) {
   List<PortfolioRow> rows = new ArrayList<PortfolioRow>();
   if (portfolio == null) {
     return rows;
   }
   flattenPortfolio(portfolio.getRootNode(), null, 0, portfolio.getName(), rows);
   return rows;
 }
 /**
  * Resolves the securities in the portfolio at the given version-correction.
  *
  * @param portfolio the portfolio to resolve, not null
  * @param executorService the threading service, not null
  * @param securitySource the security source, not null
  * @param versionCorrection the version-correction for security resolution, not null
  * @return the resolved portfolio, not null
  */
 public static Portfolio resolvePortfolio(
     final Portfolio portfolio,
     final ExecutorService executorService,
     final SecuritySource securitySource,
     final VersionCorrection versionCorrection) {
   Portfolio cloned = new SimplePortfolio(portfolio);
   new SecurityLinkResolver(executorService, securitySource, versionCorrection)
       .resolveSecurities(cloned.getRootNode());
   return cloned;
 }
  /**
   * Adds portfolio targets to the dependency graphs as required, and fully resolves the portfolio
   * structure.
   *
   * @param compilationContext the context of the view definition compilation
   * @param versionCorrection the version-correction at which to operate, not null
   * @param forcePortfolioResolution {@code true} if there are external portfolio targets, false
   *     otherwise
   * @return the fully-resolved portfolio structure if any portfolio targets were required, null
   *     otherwise.
   */
  protected static Portfolio execute(
      ViewCompilationContext compilationContext,
      VersionCorrection versionCorrection,
      boolean forcePortfolioResolution) {
    // Everything we do here is geared towards the avoidance of resolution (of portfolios,
    // positions, securities)
    // wherever possible, to prevent needless dependencies (on a position master, security master)
    // when a view never
    // really has them.

    if (!isPortfolioOutputEnabled(compilationContext.getViewDefinition())) {
      // Doesn't even matter if the portfolio can't be resolved - we're not outputting anything at
      // the portfolio level
      // (which might be because the user knows the portfolio can't be resolved right now) so there
      // are no portfolio
      // targets to add to the dependency graph.
      return null;
    }

    Portfolio portfolio =
        forcePortfolioResolution ? getPortfolio(compilationContext, versionCorrection) : null;

    for (ViewCalculationConfiguration calcConfig :
        compilationContext.getViewDefinition().getAllCalculationConfigurations()) {
      if (calcConfig.getAllPortfolioRequirements().size() == 0) {
        // No portfolio requirements for this calculation configuration - avoid further processing.
        continue;
      }

      // Actually need the portfolio now
      if (portfolio == null) {
        portfolio = getPortfolio(compilationContext, versionCorrection);
      }

      DependencyGraphBuilder builder = compilationContext.getBuilders().get(calcConfig.getName());

      // Cache PortfolioNode, Trade and Position entities
      CachingComputationTargetResolver resolver =
          compilationContext.getServices().getComputationTargetResolver();
      resolver.cachePortfolioNodeHierarchy(portfolio.getRootNode());
      cacheTradesPositionsAndSecurities(resolver, portfolio.getRootNode());

      // Add portfolio requirements to the dependency graph
      PortfolioCompilerTraversalCallback traversalCallback =
          new PortfolioCompilerTraversalCallback(builder, calcConfig);
      PortfolioNodeTraverser.depthFirst(traversalCallback).traverse(portfolio.getRootNode());
    }

    return portfolio;
  }
 /**
  * Resolves the securities.
  *
  * @param compilationContext the compilation context containing the view being compiled, not null
  * @param portfolio the portfolio to update, not null
  * @param versionCorrection the version-correction at which to resolve the securities, not null
  * @return the updated portfolio, not null
  */
 private static Portfolio resolveSecurities(
     ViewCompilationContext compilationContext,
     Portfolio portfolio,
     VersionCorrection versionCorrection) {
   OperationTimer timer =
       new OperationTimer(s_logger, "Resolving all securities for {}", portfolio.getName());
   try {
     new SecurityLinkResolver(compilationContext, versionCorrection)
         .resolveSecurities(portfolio.getRootNode());
   } catch (Exception e) {
     throw new OpenGammaRuntimeException(
         "Unable to resolve all securities for portfolio " + portfolio.getName());
   } finally {
     timer.finished();
   }
   return portfolio;
 }