Package com.opengamma.core.position

Examples of com.opengamma.core.position.Trade


          if (position.getSecurity() != null) {
            currency = _currenciesAggrFunction.classifyPosition(position);
          }
        } else if (ComputationTargetType.TRADE.isCompatible(computationTargetType)) {
          PositionSource positionSource = _toolContext.getPositionSource();
          Trade trade = positionSource.getTrade(uniqueId);
          if (trade.getSecurity() == null) {
            trade.getSecurityLink().resolve(_toolContext.getSecuritySource());
          }
          if (trade.getSecurity() != null) {
            currency = CurrenciesAggregationFunction.classifyBasedOnSecurity(trade.getSecurity(), _toolContext.getSecuritySource());
          }
        }
      }
      if (currency == null) {
        currency = CurrenciesAggregationFunction.NO_CURRENCY;
View Full Code Here


        return (Trade) f;
      }
      final Element e = _tradeCache.get(uniqueId);
      if (e != null) {
        s_logger.debug("getTradeByUniqueId: EHCache hit on {}", uniqueId);
        final Trade trade = (Trade) e.getObjectValue();
        f = _frontPositionOrTradeCache.putIfAbsent(uniqueId, trade);
        if (f instanceof Trade) {
          s_logger.debug("getTradeByUniqueId: Late front cache hit on {}", uniqueId);
          return (Trade) f;
        } else {
          return trade;
        }
      } else {
        s_logger.debug("getTradeByUniqueId: Cache miss on {}", uniqueId);
      }
    } else {
      s_logger.debug("getTradeByUniqueId: Pass through on {}", uniqueId);
    }
    final Trade trade = getUnderlying().getTrade(uniqueId);
    f = _frontPositionOrTradeCache.putIfAbsent(trade.getUniqueId(), trade);
    if (f instanceof Trade) {
      s_logger.debug("getTradeByUniqueId: Late front cache hit on {}", uniqueId);
      return (Trade) f;
    }
    _tradeCache.put(new Element(trade.getUniqueId(), trade));
    return trade;
  }
View Full Code Here

  public Set<ComputedValue> execute(FunctionExecutionContext executionContext,
                                    FunctionInputs inputs,
                                    ComputationTarget target,
                                    Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
    // 1. Unpack
    final Trade trade = target.getTrade();
    final Security security = trade.getSecurity();
    final LocalDate tradeDate = trade.getTradeDate();
    LocalDate valuationDate = ZonedDateTime.now(executionContext.getValuationClock()).toLocalDate();
    final boolean isNewTrade = tradeDate.equals(valuationDate);

    // Get desired TradeType: Open (traded before today), New (traded today) or All
    final ValueRequirement desiredValue = desiredValues.iterator().next();
    final String tradeType = desiredValue.getConstraint(PnLFunctionUtils.PNL_TRADE_TYPE_CONSTRAINT);
    if (tradeType == null) {
      s_logger.error("TradeType not set for: " + security.getName() +
          ". Choose one of {" + PnLFunctionUtils.PNL_TRADE_TYPE_OPEN + "," + PnLFunctionUtils.PNL_TRADE_TYPE_OPEN + "," + PnLFunctionUtils.PNL_TRADE_TYPE_ALL + "}");
    }

    // Create output specification. Check for trivial cases
    final ValueSpecification valueSpecification = new ValueSpecification(getValueRequirementName(), target.toSpecification(), desiredValue.getConstraints());
    if (isNewTrade && tradeType.equalsIgnoreCase(PnLFunctionUtils.PNL_TRADE_TYPE_OPEN) ||
        (!isNewTrade) && tradeType.equalsIgnoreCase(PnLFunctionUtils.PNL_TRADE_TYPE_NEW)) {
      return Sets.newHashSet(new ComputedValue(valueSpecification, 0.0));
    }

    // 2. Get inputs
    // For all TradeTypes, we'll require the live Price
    Double livePrice = calculateLivePrice(inputs, target);

    // For PNL, we need a reference price. We have two cases:
    // Open: will need the closing price and any carry
    // New: will need the trade price
    Double referencePrice;
    Double costOfCarry = 0.0;

    if (isNewTrade) {
      referencePrice = trade.getPremium();
      if (referencePrice == null) {
        throw new NullPointerException("New Trades require a premium to compute PNL on trade date. Premium was null for " + trade.getUniqueId());
      }
      if ((security instanceof InterestRateFutureSecurity || security instanceof IRFutureOptionSecurity) && (trade.getPremium() > 1.0)) {
        referencePrice /= 100.0;
      }
    } else {
      referencePrice = calculateReferencePrice(inputs, target);
      if (referencePrice == null) {
View Full Code Here

          return bundle.iterator().next() + " (" + position.getQuantity() + ")";
        } else {
          return position.getSecurity().getName() + " (" + position.getQuantity() + ")";
        }
      } else if (value instanceof Trade) {
        Trade trade = (Trade) value;
        return trade.getQuantity() + " on " + trade.getTradeDate();
      } else if (value instanceof Security) {
        Security security = (Security) value;
        return security.getName();
      }
    }
View Full Code Here

        if (index == 0) {
          return position.getSecurity();
        }
      }
    } else if (parent instanceof Trade) {
      Trade trade = (Trade) parent;
      if ((trade.getSecurity() != null) && (index == 0)) {
        return trade.getSecurity();
      }
    } // shouldn't encounter securities here as they are always leaf nodes.
    return null;
  }
View Full Code Here

      return portfolioNode.getChildNodes().size() + portfolioNode.getPositions().size();
    } else if (parent instanceof Position) {
      Position position = (Position) parent;
      return position.getTrades().size() == 0 ? 1 : position.getTrades().size();
    } else if (parent instanceof Trade) {
      Trade trade = (Trade) parent;
      if ((trade.getSecurity() != null)) {
        return 1;
      } else {
        return 0;
      }
    } else if (parent instanceof Security) {
View Full Code Here

      return portfolioNode.getChildNodes().size() == 0 && portfolioNode.getPositions().size() == 0;
    } else if (node instanceof Position) {
      Position position = (Position) node;
      return position.getTrades().size() == 0 && position.getSecurity() == null;
    } else if (node instanceof Trade) {
      Trade trade = (Trade) node;
      return trade.getSecurity() == null;
    } else if (node instanceof Security) {
      return true;
    } else {
      return true;
    }
View Full Code Here

        return -1;
      }
    } else if (parent instanceof Position) {
      Position parentPosition = (Position) parent;
      if (child instanceof Trade) {
        Trade childTrade = (Trade) child;
        return Lists.newArrayList(parentPosition.getTrades()).indexOf(childTrade); // indexOf returns -1 as expected by this interface if not present
      } else if (child instanceof Security) {
        return 0;
      }
    } else if (parent instanceof Trade) {
      Trade parentTrade = (Trade) parent;
      if (child instanceof Security) {
        return 0;
      } else {
        return -1;
      }
View Full Code Here

  @Override
  public void messageReceived(FudgeContext fudgeContext, FudgeMsgEnvelope msgEnvelope) {
   
    FudgeMsg msg = msgEnvelope.getMessage();
    s_logger.debug("Message received {}", msg);
    Trade trade = fudgeContext.fromFudgeMsg(Trade.class, msg);
    notifyListeners(trade);
  }
View Full Code Here

    SimplePortfolioNode node2 = new SimplePortfolioNode(id("node2"), "node2");
    ExternalId securityId = ExternalId.of("sec", "123");
    SimplePosition position = new SimplePosition(id("position"), BigDecimal.ONE, securityId);
    SimpleCounterparty counterparty = new SimpleCounterparty(ExternalId.of("cpty", "123"));
    SimpleSecurityLink securityLink = new SimpleSecurityLink(securityId);
    Trade trade = new SimpleTrade(securityLink, BigDecimal.ONE, counterparty, LocalDate.now(), OffsetTime.now());
    position.addTrade(trade);
    portfolio.setRootNode(root);
    node1.addPosition(position);
    node2.addPosition(position);
    root.addChildNode(node1);
View Full Code Here

TOP

Related Classes of com.opengamma.core.position.Trade

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.