Package com.opengamma.core.position.impl

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


    CSVReader csvReader = new CSVReader(new InputStreamReader(inStream));
    String[] tokens = null;
    int curIndex = 1;
    UniqueId positionId = UniqueId.of(portfolioId.getScheme(), Integer.toString(curIndex));
    while ((tokens = csvReader.readNext()) != null) {
      SimplePosition position = parseLine(tokens, positionId);
      if (position != null) {
        ((SimplePortfolioNode) portfolio.getRootNode()).addPosition(position);
        _positions.put(position.getUniqueId().getObjectId(), position);
        positionId = UniqueId.of(portfolioId.getScheme(), Integer.toString(++curIndex));
      }
    }
    s_logger.info("{} parsed stream with {} positions", portfolioId, portfolio.getRootNode().getPositions().size());
    return portfolio;
View Full Code Here


      securityIdentifiers.add(id);
    }
    ExternalIdBundle securityKey = ExternalIdBundle.of(securityIdentifiers);
    s_logger.debug("Loaded position: {} in {}", quantity, securityKey);
   
    return new SimplePosition(positionId, quantity, securityKey);
  }
View Full Code Here

      }

      @Override
      protected Position position(final Position position) {
        return new TargetResolverPosition(atVersionCorrection(VersionCorrection.LATEST), new LazyResolvedPosition(
            new LazyResolveContext(getSecuritySource(), null).atVersionCorrection(VersionCorrection.LATEST), new SimplePosition(position)));
      }

      @Override
      protected Trade trade(final Trade trade) {
        return new TargetResolverTrade(atVersionCorrection(VersionCorrection.LATEST), new LazyResolvedTrade(
View Full Code Here

    return SimpleSecurityLink.of(security);
  }

  private SimplePosition createPosition() {
    final Security security = createSecurity();
    final SimplePosition position = new SimplePosition(UniqueId.of("Position", Integer.toString(_positionId++)), BigDecimal.ONE, security) {

      private static final long serialVersionUID = 1L;

      @Override
      public void setUniqueId(final UniqueId uid) {
        // No-op
      }

    };
    position.setSecurityLink(security(security));
    final SimpleTrade trade = new SimpleTrade(security, BigDecimal.ONE, new SimpleCounterparty(ExternalId.of("Counterparty", "Mock")), TODAY, null) {

      private static final long serialVersionUID = 1L;

      @Override
      public void setUniqueId(final UniqueId uid) {
        if (getUniqueId() == null) {
          super.setUniqueId(uid);
        }
      }

    };
    trade.setUniqueId(UniqueId.of("Trade", Integer.toString(_tradeId++)));
    trade.setSecurityLink(security(security));
    addTarget(new ComputationTarget(ComputationTargetType.TRADE, trade(trade)));
    position.addTrade(trade);
    addTarget(new ComputationTarget(ComputationTargetType.POSITION, position(position)));
    return position;
  }
View Full Code Here

    new CompiledViewDefinitionWithGraphsImpl(null, null, null, null, null, null, 0);
  }

  public void testEmptyView() {
    final ExternalId secIdentifier = ExternalId.of("SEC", "1");
    final SimplePosition pos = new SimplePosition(new BigDecimal(1), secIdentifier);
    final SimplePortfolioNode pn = new SimplePortfolioNode("node");
    pn.addPosition(pos);
    final SimplePortfolio p = new SimplePortfolio(UniqueId.of("FOO", "BAR"), "portfolio");
    p.setRootNode(pn);
    final MockPositionSource positionSource = new MockPositionSource();
View Full Code Here

    assertEquals(0, compiledViewDefinition.getComputationTargets().size());
  }

  public void testSingleValueNoLiveData() {
    final ExternalId secIdentifier = ExternalId.of("SEC", "1");
    final SimplePosition pos = new SimplePosition(new BigDecimal(1), secIdentifier);
    final SimplePortfolioNode pn = new SimplePortfolioNode("node");
    pn.addPosition(pos);
    final SimplePortfolio p = new SimplePortfolio(UniqueId.of("FOO", "BAR"), "portfolio");
    p.setRootNode(pn);
    final MockPositionSource positionSource = new MockPositionSource();
View Full Code Here

  }

  public void testSingleValueExternalDependency() {
    final ExternalId secIdentifier1 = ExternalId.of("SEC", "1");
    final ExternalId secIdentifier2 = ExternalId.of("SEC", "2");
    final SimplePosition pos = new SimplePosition(new BigDecimal(1), secIdentifier1);
    final SimplePortfolioNode pn = new SimplePortfolioNode("node");
    pn.addPosition(pos);
    final SimplePortfolio p = new SimplePortfolio(UniqueId.of("FOO", "BAR"), "portfolio");
    p.setRootNode(pn);
    final MockPositionSource positionSource = new MockPositionSource();
View Full Code Here

    final PortfolioStructure resolver = new PortfolioStructure(positionSource);
    final SimplePortfolio portfolio = new SimplePortfolio(uid.get(), "Test");
    _root = new SimplePortfolioNode(uid.get(), "root");
    _child1 = new SimplePortfolioNode(uid.get(), "child 1");
    _child2 = new SimplePortfolioNode(uid.get(), "child 2");
    _position1 = new SimplePosition(uid.get(), new BigDecimal(10), ExternalId.of("Security", "Foo"));
    _child2.addPosition(_position1);
    _position2 = new SimplePosition(uid.get(), new BigDecimal(20), ExternalId.of("Security", "Bar"));
    _child2.addPosition(_position2);
    _child2.setParentNodeId(_child1.getUniqueId());
    _child1.addChildNode(_child2);
    _child1.setParentNodeId(_root.getUniqueId());
    _root.addChildNode(_child1);
    portfolio.setRootNode(_root);
    positionSource.addPortfolio(portfolio);
    _badChild = new SimplePortfolioNode(uid.get(), "child 3");
    _badChild.setParentNodeId(uid.get());
    _badPosition = new SimplePosition(uid.get(), new BigDecimal(10), ExternalId.of("Security", "Cow"));
    _context = new FunctionCompilationContext();
    _context.setPortfolioStructure(resolver);
  }
View Full Code Here

  private Portfolio _testPortfolio;
  private CompiledFunctionRepository _functionRepository;
  private MarketDataAvailabilityFilter _marketDataAvailability;

  private SimplePosition createPosition(final String securityType, final String currency, final String securityId) {
    final SimplePosition position = new SimplePosition();
    position.setUniqueId(UniqueId.of("Position", securityType + "-" + currency + "-" + securityId));
    position.setQuantity(BigDecimal.ONE);
    final SimpleSecurityLink link = new SimpleSecurityLink();
    link.setTarget(new Security() {

      @Override
      public ExternalIdBundle getExternalIdBundle() {
        return ExternalIdBundle.EMPTY;
      }

      @Override
      public String getName() {
        return currency;
      }

      @Override
      public String getSecurityType() {
        return securityType;
      }

      @Override
      public UniqueId getUniqueId() {
        return UniqueId.of("Security", securityType + "-" + currency + "-" + securityId);
      }

      @Override
      public Map<String, String> getAttributes() {
        return new HashMap<String, String>();
      }

      @Override
      public void setAttributes(final Map<String, String> attributes) {
      }

      @Override
      public void addAttribute(final String key, final String value) {
      }
    });
    position.setSecurityLink(link);
    return position;
  }
View Full Code Here

      if (secIdField != null) {
        secLink.setObjectId(deserializer.fieldValueToObject(ObjectId.class, secIdField));
      }
    }
   
    SimplePosition position = new SimplePosition();
    position.setSecurityLink(secLink);
    if (message.hasField(UNIQUE_ID_FIELD_NAME)) {
      FudgeField uniqueIdField = message.getByName(UNIQUE_ID_FIELD_NAME);
      if (uniqueIdField != null) {
        position.setUniqueId(deserializer.fieldValueToObject(UniqueId.class, uniqueIdField));
      }     
    }
    if (message.hasField(QUANTITY_FIELD_NAME)) {
      FudgeField quantityField = message.getByName(QUANTITY_FIELD_NAME);
      if (quantityField != null) {
        position.setQuantity(message.getFieldValue(BigDecimal.class, quantityField));
      }
    }
    if (message.hasField(ATTRIBUTES_FIELD_NAME)) {
      FudgeMsg attributesMsg = message.getMessage(ATTRIBUTES_FIELD_NAME);
      for (FudgeField fudgeField : attributesMsg) {
        String key = fudgeField.getName();
        Object value = fudgeField.getValue();
        if (key != null && value != null) {
          position.addAttribute(key, (String) value);
        }
      }
    }
    readTrades(deserializer, message.getFieldValue(FudgeMsg.class, message.getByName(TRADES_FIELD_NAME)), position);
    return position;
View Full Code Here

TOP

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

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.