Package com.opengamma.master.position

Examples of com.opengamma.master.position.ManageableTrade


@Test(groups = TestGroup.UNIT)
public class WebPositionResourceTest extends AbstractWebPositionResourceTestCase {

  @Test
  public void testGetPositionWithTrades() throws Exception {
    final ManageableTrade trade = new ManageableTrade(BigDecimal.valueOf(50), SEC_ID, LocalDate.parse("2011-12-07"), OffsetTime.of(LocalTime.of(15, 4), ZONE_OFFSET), COUNTER_PARTY);
    trade.setPremium(10.0);
    trade.setPremiumCurrency(Currency.USD);
    trade.setPremiumDate(LocalDate.parse("2011-12-08"));
    trade.setPremiumTime(OffsetTime.of(LocalTime.of(15, 4), ZONE_OFFSET));

    final ManageablePosition manageablePosition = new ManageablePosition(trade.getQuantity(), SEC_ID);
    manageablePosition.addTrade(trade);
    final PositionDocument addedPos = _positionMaster.add(new PositionDocument(manageablePosition));

    final WebPositionResource positionResource = _webPositionsResource.findPosition(addedPos.getUniqueId().toString());
    final String json = positionResource.getJSON();
View Full Code Here


    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
   
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
   
    ManageableTrade trade1 = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    trade1.addAttribute("key11", "value11");
    trade1.addAttribute("key12", "value12");
    position.addTrade(trade1);
   
    ManageableTrade trade2 = new ManageableTrade(BigDecimal.TEN, ExternalId.of("C", "D"), tradeDate, tradeTime, ExternalId.of("CPS2", "CPV2"));
    trade2.addAttribute("key21", "value21");
    trade2.addAttribute("key22", "value22");
    position.addTrade(trade2);
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    _posMaster.add(doc);
    assertNotNull(trade1.getUniqueId());
    assertNotNull(trade2.getUniqueId());
   
    PositionSearchRequest requestByTrade = new PositionSearchRequest();
    requestByTrade.addTradeObjectId(trade1.getUniqueId().getObjectId());
   
    PositionSearchResult test = _posMaster.search(requestByTrade);
View Full Code Here

    position.addAttribute("PA3", "C");
   
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
   
    ManageableTrade trade1 = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    trade1.addAttribute("key11", "value11");
    trade1.addAttribute("key12", "value12");
    position.addTrade(trade1);
   
    ManageableTrade trade2 = new ManageableTrade(BigDecimal.TEN, ExternalId.of("C", "D"), tradeDate, tradeTime, ExternalId.of("CPS2", "CPV2"));
    trade2.addAttribute("key21", "value21");
    trade2.addAttribute("key22", "value22");
    position.addTrade(trade2);
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    _posMaster.add(doc);
    assertNotNull(trade1.getUniqueId());
    assertNotNull(trade2.getUniqueId());
   
    PositionSearchRequest requestByTrade = new PositionSearchRequest();
    requestByTrade.addTradeObjectId(trade1.getUniqueId().getObjectId());
   
    PositionSearchResult test = _posMaster.search(requestByTrade);
View Full Code Here

    InMemorySecurityMaster securityMaster = new InMemorySecurityMaster();
    securityMaster.add(new SecurityDocument(APPLE_SECURITY));
    securityMaster.add(new SecurityDocument(INTEL_SECURITY));
    BigDecimal quantity = BigDecimal.valueOf(20);
    ManageablePosition position = new ManageablePosition(quantity, APPLE_SECURITY.getExternalIdBundle());
    position.addTrade(new ManageableTrade(quantity,
                                          APPLE_BUNDLE,
                                          LocalDate.of(2012, 12, 1),
                                          OffsetTime.of(LocalTime.of(9, 30), ZoneOffset.UTC),
                                          ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "existingCpty")));
    _savedPosition = _positionMaster.add(new PositionDocument(position)).getPosition();
View Full Code Here

   * node has a position in a different security of the same type
   */
  @Test
  public void addTradeNoExistingPosition() {
    UniqueId tradeId = _tradeBuilder.addTrade(createTradeData("INTC US Equity", null), _savedNode.getUniqueId());
    ManageableTrade testTrade = _positionMaster.getTrade(tradeId);
    assertEquals(LocalDate.of(2012, 12, 21), testTrade.getTradeDate());
    assertEquals(OffsetTime.of(LocalTime.of(14, 25), ZoneOffset.UTC), testTrade.getTradeTime());
    assertEquals(INTEL_BUNDLE, testTrade.getSecurityLink().getExternalId());
    assertEquals(1234d, testTrade.getPremium());
    assertEquals(Currency.USD, testTrade.getPremiumCurrency());
    assertEquals(LocalDate.of(2012, 12, 22), testTrade.getPremiumDate());
    assertEquals(OffsetTime.of(LocalTime.of(13, 30), ZoneOffset.UTC), testTrade.getPremiumTime());
    assertEquals(BigDecimal.valueOf(30), testTrade.getQuantity());
    assertEquals(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "cptyName"), testTrade.getCounterpartyExternalId());
    assertTrue(testTrade.getAttributes().isEmpty());

    ManageablePosition testPosition = _positionMaster.get(testTrade.getParentPositionId()).getPosition();
    assertEquals(INTEL_BUNDLE, testPosition.getSecurityLink().getExternalId());
    assertEquals(testTrade.getQuantity(), testPosition.getQuantity());
    assertEquals(1, testPosition.getTrades().size());
    assertEquals(testTrade, testPosition.getTrades().get(0));

    ManageablePortfolio testPortfolio = _portfolioMaster.get(_savedNode.getPortfolioId()).getPortfolio();
    ManageablePortfolioNode testNode = testPortfolio.getRootNode().getChildNodes().get(0);
View Full Code Here

  @Override
  public ManageableTrade createSecurityTrade(final QuantityGenerator quantity, final SecurityPersister persister, final NameGenerator counterPartyGenerator) {
    final ForwardSwapSecurity swap = createSecurity();
    if (swap != null) {
      return new ManageableTrade(quantity.createQuantity(), persister.storeSecurity(swap), swap.getTradeDate().toLocalDate(), swap.getTradeDate().toOffsetDateTime().toOffsetTime(),
          ExternalId.of(Counterparty.DEFAULT_SCHEME, counterPartyGenerator.createName()));
    } else {
      return null;
    }
  }
View Full Code Here

   * add a trade to a portfolio node that already has a position in the trade's security
   */
  @Test
  public void addTradeToExistingPosition() {
    UniqueId tradeId = _tradeBuilder.addTrade(createTradeData("AAPL US Equity", null), _savedNode.getUniqueId());
    ManageableTrade testTrade = _positionMaster.getTrade(tradeId);
    assertEquals(LocalDate.of(2012, 12, 21), testTrade.getTradeDate());
    assertEquals(OffsetTime.of(LocalTime.of(14, 25), ZoneOffset.UTC), testTrade.getTradeTime());
    assertEquals(APPLE_BUNDLE, testTrade.getSecurityLink().getExternalId());
    assertEquals(1234d, testTrade.getPremium());
    assertEquals(Currency.USD, testTrade.getPremiumCurrency());
    assertEquals(LocalDate.of(2012, 12, 22), testTrade.getPremiumDate());
    assertEquals(OffsetTime.of(LocalTime.of(13, 30), ZoneOffset.UTC), testTrade.getPremiumTime());
    assertEquals(BigDecimal.valueOf(30), testTrade.getQuantity());
    assertEquals(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "cptyName"), testTrade.getCounterpartyExternalId());
    assertTrue(testTrade.getAttributes().isEmpty());

    ManageablePosition testPosition = _positionMaster.get(testTrade.getParentPositionId()).getPosition();
    assertEquals(APPLE_BUNDLE, testPosition.getSecurityLink().getExternalId());
    assertEquals(BigDecimal.valueOf(50), testPosition.getQuantity());
    assertEquals(2, testPosition.getTrades().size());
    assertEquals(testTrade, testPosition.getTrades().get(1));

View Full Code Here

  /**
   * update a trade - the position's quantity should also be adjusted
   */
  @Test
  public void updateTrade() {
    ManageableTrade previousTrade = _savedPosition.getTrades().get(0);
    BeanDataSource tradeData = createTradeData("AAPL US Equity", previousTrade.getUniqueId().toString());
    UniqueId updatedId = _tradeBuilder.updateTrade(tradeData);

    ManageableTrade updatedTrade = _positionMaster.getTrade(updatedId);
    assertEquals(LocalDate.of(2012, 12, 21), updatedTrade.getTradeDate());
    assertEquals(OffsetTime.of(LocalTime.of(14, 25), ZoneOffset.UTC), updatedTrade.getTradeTime());
    assertEquals(APPLE_BUNDLE, updatedTrade.getSecurityLink().getExternalId());
    assertEquals(1234d, updatedTrade.getPremium());
    assertEquals(Currency.USD, updatedTrade.getPremiumCurrency());
    assertEquals(LocalDate.of(2012, 12, 22), updatedTrade.getPremiumDate());
    assertEquals(OffsetTime.of(LocalTime.of(13, 30), ZoneOffset.UTC), updatedTrade.getPremiumTime());
    assertEquals(BigDecimal.valueOf(30), updatedTrade.getQuantity());
    assertEquals(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "cptyName"), updatedTrade.getCounterpartyExternalId());
    assertTrue(updatedTrade.getAttributes().isEmpty());
  }
View Full Code Here

    _tradeBuilder.updatePosition(createTradeData("AAPL US Equity", null), savedPosition.getUniqueId());
    ManageablePosition updatedPosition = _positionMaster.get(savedPosition.getUniqueId().getObjectId(),
                                                             VersionCorrection.LATEST).getPosition();
    assertEquals(BigDecimal.valueOf(30), updatedPosition.getQuantity());
    assertEquals(1, updatedPosition.getTrades().size());
    ManageableTrade trade = updatedPosition.getTrades().get(0);
    assertEquals(LocalDate.of(2012, 12, 21), trade.getTradeDate());
    assertEquals(OffsetTime.of(LocalTime.of(14, 25), ZoneOffset.UTC), trade.getTradeTime());
    assertEquals(APPLE_BUNDLE, trade.getSecurityLink().getExternalId());
    assertEquals(1234d, trade.getPremium());
    assertEquals(Currency.USD, trade.getPremiumCurrency());
    assertEquals(LocalDate.of(2012, 12, 22), trade.getPremiumDate());
    assertEquals(OffsetTime.of(LocalTime.of(13, 30), ZoneOffset.UTC), trade.getPremiumTime());
    assertEquals(BigDecimal.valueOf(30), trade.getQuantity());
    assertEquals(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "cptyName"), trade.getCounterpartyExternalId());
    assertTrue(trade.getAttributes().isEmpty());
  }
View Full Code Here

  /**
   * update the trade and change the security - this should fail
   */
  @Test(expectedExceptions = IllegalArgumentException.class)
  public void updateTradeChangeSecurity() {
    ManageableTrade previousTrade = _savedPosition.getTrades().get(0);
    BeanDataSource tradeData = createTradeData("INTC US Equity", previousTrade.getUniqueId().toString());
    _tradeBuilder.updateTrade(tradeData);
  }
View Full Code Here

TOP

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

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.