Package com.opengamma.core.position

Examples of com.opengamma.core.position.Portfolio


   * that only a small sample of each unique asset class is considered - this is to save time when there are many portfolios to consider.
   *
   * @param portfolio a portfolio containing a sample of asset class instances
   */
  public void processAvailablePortfolioOutputs(final Portfolio portfolio) {
    final Portfolio filtered;
    synchronized (_securityTypePortfolioFilter) {
      filtered = new PortfolioFilter(_securityTypePortfolioFilter).filter(portfolio);
    }
    if (filtered.getRootNode().getChildNodes().isEmpty() && filtered.getRootNode().getPositions().isEmpty()) {
      s_logger.debug("Ignoring {} ({})", portfolio.getName(), portfolio.getUniqueId());
    } else {
      s_logger.info("Calculating available outputs from {} ({})", portfolio.getName(), portfolio.getUniqueId());
      final AvailableOutputs outputs = new AvailablePortfolioOutputs(filtered, getFunctionRepository(), getFunctionExclusionGroups(), getMarketDataAvailability(), null);
      synchronized (_availableOutputsBySecurityType) {
View Full Code Here


    }
    if (currencies != null && currencies.length > 0) {
      instance.setCurrencies(currencies);
    }
    s_logger.info("Creating portfolio {}", portfolioName);
    final Portfolio portfolio = instance.createPortfolio(portfolioName);
    if (write) {
      s_logger.info("Writing portfolio to the database");
      final ManageablePortfolio newPortfolio = new ManageablePortfolio(portfolio.getName());
      newPortfolio.setAttributes(portfolio.getAttributes());
      newPortfolio.setRootNode(createPortfolioNode(context.getPositionMaster(), portfolio.getRootNode()));
      final PortfolioSearchRequest request = new PortfolioSearchRequest();
      request.setDepth(0);
      request.setIncludePositions(false);
      request.setName(portfolio.getName());
      final PortfolioSearchResult result = context.getPortfolioMaster().search(request);
      PortfolioDocument document = result.getFirstDocument();
      if (document != null) {
        s_logger.info("Overwriting portfolio {}", document.getUniqueId());
        document.setPortfolio(newPortfolio);
        context.getPortfolioMaster().update(document);
      } else {
        document = new PortfolioDocument(newPortfolio);
        context.getPortfolioMaster().add(document);
      }
    } else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("Portfolio {}", portfolioName);
        writePortfolio(securitySource, portfolio.getRootNode(), "");
      }
    }
  }
View Full Code Here

    if (manageablePortfolio == null) {
      s_logger.error("Portfolio " + portfolioName + " was not found");
      System.exit(1);
    }
    s_logger.info("Reloading portfolio from position source...");
    Portfolio portfolio = positionSource.getPortfolio(manageablePortfolio.getUniqueId(), VersionCorrection.LATEST);
    if (portfolio == null) {
      s_logger.error("Portfolio " + portfolioName + " was not found from PositionSource");
      System.exit(1);
    }
    s_logger.info("Done.");
    ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(20);
    s_logger.info("Resolving portfolio positions and securities...");
    Portfolio resolvedPortfolio = PortfolioCompiler.resolvePortfolio(portfolio, newFixedThreadPool, secSource);
    if (resolvedPortfolio == null) {
      s_logger.error("Portfolio " + portfolioName + " was not correctly resolved by PortfolioCompiler");
      System.exit(1);
    }
    s_logger.info("Resolution Complete.");
    PortfolioAggregator aggregator = new PortfolioAggregator(aggregationFunctions);
    s_logger.info("Beginning aggregation");
    Portfolio aggregatedPortfolio = aggregator.aggregate(resolvedPortfolio);
    s_logger.info("Aggregation complete, about to persist...");
    if (aggregatedPortfolio == null) {
      s_logger.error("Portfolio " + portfolioName + " was not correctly aggregated by the Portfolio Aggregator");
      System.exit(1);
    }
    SavePortfolio savePortfolio = new SavePortfolio(newFixedThreadPool, portfolioMaster, positionMaster);
    if (split) {
      for (PortfolioNode portfolioNode : aggregatedPortfolio.getRootNode().getChildNodes()) {
        String splitPortfolioName = portfolioName + " (" + aggregationName + " " + portfolioNode.getName() + ")";
        SimplePortfolioNode root = new SimplePortfolioNode("root");
        root.addChildNode(portfolioNode);
        Portfolio splitPortfolio = new SimplePortfolio(splitPortfolioName, root);
        splitPortfolio.setAttributes(aggregatedPortfolio.getAttributes());
        s_logger.info("Saving split portfolio " + portfolioName + "...");
        savePortfolio.savePortfolio(splitPortfolio, true);
      }

    } else {
View Full Code Here

   
    assertEquals(2, pm.getPortfolioIds().size());
   
    // Loaded correctly
    ObjectId[] portIds = pm.getPortfolioIds().toArray(new ObjectId[0]);
    Portfolio port1 = pm.getPortfolio(portIds[0].atVersion("0"), VersionCorrection.LATEST);
    assertEquals(6, port1.getRootNode().getPositions().size());  
    Portfolio port2 = pm.getPortfolio(portIds[1].atVersion("0"), VersionCorrection.LATEST);
    assertEquals(4, port2.getRootNode().getPositions().size());
    Portfolio port2b = pm.getPortfolio(portIds[1], VersionCorrection.LATEST);
    assertEquals(4, port2b.getRootNode().getPositions().size());
   
    // Unknown portfolio
    try {
      pm.getPortfolio(UniqueId.of("Wrong scheme", "Irrelevant value"), VersionCorrection.LATEST);
      fail();
View Full Code Here

  @Override
  public Portfolio getPortfolio(ObjectId objectId, VersionCorrection versionCorrection) {
    Object portfolio = _portfolios.get(objectId);
    if (portfolio instanceof File) {
      Portfolio created = loadPortfolio(objectId, (File) portfolio);
      _portfolios.replace(objectId, portfolio, created);
      portfolio = _portfolios.get(objectId);
    }
    if (portfolio instanceof Portfolio) {
      return (Portfolio) portfolio;
View Full Code Here

      portfolio.getRootNode().addPosition(addPosition(i));
    }
   
    UniqueId uniqueId = source.storePortfolio(portfolio);
   
    Portfolio result = source.getPortfolio(uniqueId, null);
    assertNotNull(result);
    assertEquals("Fibble", result.getName());
    assertNotNull(result.getRootNode());
    assertTrue((result.getRootNode().getChildNodes() == null) || result.getRootNode().getChildNodes().isEmpty());
    assertEquals(nPositions, result.getRootNode().getPositions().size());
  }
View Full Code Here

      portfolio.getRootNode().addPosition(addPosition(i));
    }
   
    UniqueId uniqueId = source.storePortfolio(portfolio);
   
    Portfolio result = source.getByName("Fibble");
    assertNotNull(result);
    assertEquals("Fibble", result.getName());
    assertEquals(uniqueId, result.getUniqueId());
  }
View Full Code Here

  public void largePerformanceTest() {
    NonVersionedRedisPositionSource source = new NonVersionedRedisPositionSource(getJedisPool(), getRedisPrefix());
    SimplePortfolio portfolio = new SimplePortfolio("Fibble");
    portfolio.setRootNode(new SimplePortfolioNode());
    UniqueId uniqueId = source.storePortfolio(portfolio);
    Portfolio p = source.getPortfolio(uniqueId, null);
   
    long start = System.nanoTime();
    final int NUM_POSITIONS = 50000;
    for (int i = 0; i < NUM_POSITIONS; i++) {
      source.addPositionToPortfolio(p, addPosition(i));
View Full Code Here

  public void portfolio_deep() {
    final DeepResolver deep = resolver().portfolio().deepResolver();
    assertNotNull(deep);
    ResolutionLogger logger = Mockito.mock(ResolutionLogger.class);
    final Portfolio portfolio = (Portfolio) deep.withLogger(PORTFOLIO, logger);
    assertNotNull(portfolio);
    assertNotSame(portfolio, PORTFOLIO);
    assertEquals(portfolio.getUniqueId(), PORTFOLIO.getUniqueId());
  }
View Full Code Here

@Test(groups = TestGroup.UNIT)
public class LoggedResolutionPortfolioTest {

  @SuppressWarnings("unchecked")
  public void getAttributes() {
    final Portfolio portfolio = Mockito.mock(Portfolio.class);
    final ResolutionLogger logger = Mockito.mock(ResolutionLogger.class);
    final Portfolio logged = new LoggedResolutionPortfolio(portfolio, logger);
    final Map<String, String> result = Mockito.mock(Map.class);
    Mockito.when(portfolio.getAttributes()).thenReturn(result);
    assertSame(logged.getAttributes(), result);
    Mockito.verifyZeroInteractions(logger);
  }
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.