Package com.opengamma.master.position

Examples of com.opengamma.master.position.ManageablePosition


   * directly update a position that has no trades
   */
  @Test
  public void updatePositionWithNoTrade() {
    ManageableSecurity security = _securityMaster.add(new SecurityDocument(BlotterTestUtils.FX_FORWARD)).getSecurity();
    ManageablePosition position = new ManageablePosition();
    position.setQuantity(BigDecimal.ONE);
    position.setSecurityLink(new ManageableSecurityLink(security.getUniqueId()));
    ManageablePosition savedPosition = _positionMaster.add(new PositionDocument(position)).getPosition();

    BeanDataSource updatedTradeData = createTradeData("counterparty", "updatedCounterparty",
                                                      "tradeDate", "2012-12-22",
                                                      "premium", "4321");
    BeanDataSource updatedSecurityData = BlotterTestUtils.overrideBeanData(BlotterTestUtils.FX_FORWARD_DATA_SOURCE,
                                                                           "payCurrency", "AUD",
                                                                           "payAmount", "200");

    _builder.updatePosition(savedPosition.getUniqueId(), updatedTradeData, updatedSecurityData, null);
    ManageablePosition loadedPosition = _positionMaster.get(savedPosition.getUniqueId()).getPosition();
    assertEquals(1, loadedPosition.getTrades().size());
    ManageableTrade trade = loadedPosition.getTrades().get(0);
    assertEquals("updatedCounterparty", trade.getCounterpartyExternalId().getValue());
    assertEquals(LocalDate.of(2012, 12, 22), trade.getTradeDate());
    assertEquals(4321d, trade.getPremium());
    FXForwardSecurity updatedSecurity = (FXForwardSecurity) _securityMaster.get(trade.getSecurityLink().getObjectId(),
                                                                                VersionCorrection.LATEST).getSecurity();
View Full Code Here


  @Test
  public void test_add_add() {
    Instant now = Instant.now(_posMaster.getClock());
   
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument test = _posMaster.add(doc);
   
    UniqueId uniqueId = test.getUniqueId();
    assertNotNull(uniqueId);
    assertEquals("DbPos", uniqueId.getScheme());
    assertTrue(uniqueId.isVersioned());
    assertTrue(Long.parseLong(uniqueId.getValue()) >= 1000);
    assertEquals("0", uniqueId.getVersion());
    assertEquals(now, test.getVersionFromInstant());
    assertEquals(null, test.getVersionToInstant());
    assertEquals(now, test.getCorrectionFromInstant());
    assertEquals(null, test.getCorrectionToInstant());
    ManageablePosition testPosition = test.getPosition();
    assertNotNull(testPosition);
    assertEquals(uniqueId, testPosition.getUniqueId());
    assertEquals(BigDecimal.TEN, testPosition.getQuantity());
    ExternalIdBundle secKey = testPosition.getSecurityLink().getExternalId();
    assertEquals(1, secKey.size());
    assertTrue(secKey.getExternalIds().contains(ExternalId.of("A", "B")));
  }
View Full Code Here

  @Test
  public void test_addWithOneTrade_add() {
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
   
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV")));
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument test = _posMaster.add(doc);
   
    Instant now = Instant.now(_posMaster.getClock());
    UniqueId uniqueId = test.getUniqueId();
    assertNotNull(uniqueId);
    assertEquals("DbPos", uniqueId.getScheme());
    assertTrue(uniqueId.isVersioned());
    assertTrue(Long.parseLong(uniqueId.getValue()) >= 1000);
    assertEquals("0", uniqueId.getVersion());
    assertEquals(now, test.getVersionFromInstant());
    assertEquals(null, test.getVersionToInstant());
    assertEquals(now, test.getCorrectionFromInstant());
    assertEquals(null, test.getCorrectionToInstant());
    ManageablePosition testPosition = test.getPosition();
    assertNotNull(testPosition);
    assertEquals(uniqueId, testPosition.getUniqueId());
    assertEquals(BigDecimal.TEN, testPosition.getQuantity());
    ExternalIdBundle secKey = testPosition.getSecurityLink().getExternalId();
    assertEquals(1, secKey.size());
    assertTrue(secKey.getExternalIds().contains(ExternalId.of("A", "B")));
   
    assertNotNull(testPosition.getTrades());
    assertEquals(1, testPosition.getTrades().size());
    ManageableTrade testTrade = testPosition.getTrades().get(0);
    assertNotNull(testTrade);
    assertEquals(BigDecimal.TEN, testTrade.getQuantity());
    assertEquals(tradeDate, testTrade.getTradeDate());
    assertEquals(tradeTime, testTrade.getTradeTime());
    assertEquals(ExternalId.of("CPS", "CPV"), testTrade.getCounterpartyExternalId());
View Full Code Here

  public void test_addWithOnePremiumTrade_add() {
   
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
   
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    ManageableTrade trade = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    trade.setPremium(1000000.00);
    trade.setPremiumCurrency(Currency.USD);
    trade.setPremiumDate(tradeDate.plusDays(1));
    trade.setPremiumTime(tradeTime);
    position.getTrades().add(trade);
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument test = _posMaster.add(doc);
   
    Instant now = Instant.now(_posMaster.getClock());
    UniqueId uniqueId = test.getUniqueId();
    assertNotNull(uniqueId);
    assertEquals("DbPos", uniqueId.getScheme());
    assertTrue(uniqueId.isVersioned());
    assertTrue(Long.parseLong(uniqueId.getValue()) >= 1000);
    assertEquals("0", uniqueId.getVersion());
    assertEquals(now, test.getVersionFromInstant());
    assertEquals(null, test.getVersionToInstant());
    assertEquals(now, test.getCorrectionFromInstant());
    assertEquals(null, test.getCorrectionToInstant());
    ManageablePosition testPosition = test.getPosition();
    assertNotNull(testPosition);
    assertEquals(uniqueId, testPosition.getUniqueId());
    assertEquals(BigDecimal.TEN, testPosition.getQuantity());
    ExternalIdBundle secKey = testPosition.getSecurityLink().getExternalId();
    assertEquals(1, secKey.size());
    assertTrue(secKey.getExternalIds().contains(ExternalId.of("A", "B")));
   
    assertNotNull(testPosition.getTrades());
    assertEquals(1, testPosition.getTrades().size());
    ManageableTrade testTrade = testPosition.getTrades().get(0);
    assertNotNull(testTrade);
    assertEquals(BigDecimal.TEN, testTrade.getQuantity());
    assertEquals(tradeDate, testTrade.getTradeDate());
    assertEquals(tradeTime, testTrade.getTradeTime());
    assertEquals(ExternalId.of("CPS", "CPV"), testTrade.getCounterpartyExternalId());
View Full Code Here

    assertEquals(tradeTime, testTrade.getPremiumTime());
  }

  @Test
  public void test_addWithOnePremiumTrade_addThenGet() {
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
   
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
   
    ManageableTrade trade = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    trade.setPremium(1000000.00);
    trade.setPremiumCurrency(Currency.USD);
    trade.setPremiumDate(tradeDate.plusDays(1));
    trade.setPremiumTime(tradeTime);
   
    position.getTrades().add(trade);
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument added = _posMaster.add(doc);
    assertNotNull(added);
View Full Code Here

  public void test_addWithTwoTrades_add() {
    Instant now = Instant.now(_posMaster.getClock());
   
    OffsetDateTime offsetDateTime = OffsetDateTime.now();
   
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "C"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(600).toOffsetTime(), ExternalId.of("CPS", "CPV")));
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "D"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(500).toOffsetTime(), ExternalId.of("CPS", "CPV")));
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument test = _posMaster.add(doc);
   
    UniqueId portfolioId = test.getUniqueId();
    assertNotNull(portfolioId);
    assertEquals("DbPos", portfolioId.getScheme());
    assertTrue(portfolioId.isVersioned());
    assertTrue(Long.parseLong(portfolioId.getValue()) >= 1000);
    assertEquals("0", portfolioId.getVersion());
    assertEquals(now, test.getVersionFromInstant());
    assertEquals(null, test.getVersionToInstant());
    assertEquals(now, test.getCorrectionFromInstant());
    assertEquals(null, test.getCorrectionToInstant());
    ManageablePosition testPosition = test.getPosition();
    assertNotNull(testPosition);
    assertEquals(portfolioId, testPosition.getUniqueId());
    assertEquals(BigDecimal.TEN, testPosition.getQuantity());
    ExternalIdBundle secKey = testPosition.getSecurityLink().getExternalId();
    assertEquals(1, secKey.size());
    assertTrue(secKey.getExternalIds().contains(ExternalId.of("A", "B")));
   
    assertNotNull(testPosition.getTrades());
    assertTrue(testPosition.getTrades().size() == 2);
    for (ManageableTrade testTrade : testPosition.getTrades()) {
      assertNotNull(testTrade);
      UniqueId tradeId = testTrade.getUniqueId();
      assertNotNull(tradeId);
      assertEquals("DbPos", portfolioId.getScheme());
      assertTrue(portfolioId.isVersioned());
View Full Code Here

    for (final SwapSecurity swap : swaps) {
      final SecurityDocument swapToAddDoc = new SecurityDocument();
      swapToAddDoc.setSecurity(swap);
      securityMaster.add(swapToAddDoc);
      final ManageablePosition swapPosition = new ManageablePosition(BigDecimal.ONE, swap.getExternalIdBundle());
      final PositionDocument addedDoc = positionMaster.add(new PositionDocument(swapPosition));
      rootNode.addPosition(addedDoc.getUniqueId());
    }
    portfolioMaster.add(portfolioDoc);
  }
View Full Code Here

    final ManageablePortfolioNode newNode = new ManageablePortfolioNode(node.getName());
    for (final PortfolioNode child : node.getChildNodes()) {
      newNode.addChildNode(createPortfolioNode(positionMaster, child));
    }
    for (final Position position : node.getPositions()) {
      final ManageablePosition newPosition = new ManageablePosition();
      newPosition.setAttributes(position.getAttributes());
      newPosition.setQuantity(position.getQuantity());
      newPosition.setSecurityLink(new ManageableSecurityLink(position.getSecurityLink()));
      for (final Trade trade : position.getTrades()) {
        newPosition.addTrade(new ManageableTrade(trade));
      }
      newNode.addPosition(positionMaster.add(new PositionDocument(newPosition)).getUniqueId());
    }
    return newNode;
  }
View Full Code Here

      final SecurityDocument swaptionToAddDoc = new SecurityDocument();
      final SwaptionSecurity swaption = entry.getKey();
      swaptionToAddDoc.setSecurity(swaption);
      securityMaster.add(swaptionToAddDoc);
      securityMaster.add(swapToAddDoc);
      final ManageablePosition swaptionPosition = new ManageablePosition(BigDecimal.ONE, swaption.getExternalIdBundle());
      final PositionDocument addedDoc = positionMaster.add(new PositionDocument(swaptionPosition));
      rootNode.addPosition(addedDoc.getUniqueId());
    }
    portfolioMaster.add(portfolioDoc);
  }
View Full Code Here

    for (final FXForwardSecurity fxForward : fxForwards) {
      final SecurityDocument fxForwardToAddDoc = new SecurityDocument();
      fxForwardToAddDoc.setSecurity(fxForward);
      securityMaster.add(fxForwardToAddDoc);
      final ManageablePosition fxForwardPosition = new ManageablePosition(BigDecimal.ONE, fxForward.getExternalIdBundle());
      final PositionDocument addedDoc = positionMaster.add(new PositionDocument(fxForwardPosition));
      rootNode.addPosition(addedDoc.getUniqueId());
    }
    portfolioMaster.add(portfolioDoc);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.master.position.ManageablePosition

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.