Esempio n. 1
0
  public InstrumentDefinition<?> convert(final Trade trade) {
    Validate.notNull(trade, "trade");
    Validate.isTrue(
        trade.getSecurity() instanceof IRFutureOptionSecurity,
        "Can only handle trades with security type IRFutureOptionSecurity");
    final Object securityDefinition =
        _securityConverter.convert((IRFutureOptionSecurity) trade.getSecurity());
    final int quantity =
        1; // trade.getQuantity().intValue(); TODO: correct when position/trade dilemma is solved.
    // TODO trade time or premium time?
    //    final ZonedDateTime tradeDate =
    // ZonedDateTime.of(trade.getPremiumDate().atTime(trade.getPremiumTime()),
    //        TimeZone.UTC); //TODO get the real time zone
    final ZonedDateTime tradeDate =
        ZonedDateTime.of(
            trade.getTradeDate().atTime(trade.getTradeTime()),
            TimeZone.UTC); // TODO get the real time zone

    final Double tradePrice = trade.getPremium();
    Validate.notNull(
        tradePrice,
        "IRFutureOption trade must have a premium set. The interpretation of premium is the market price, without unit, i.e. not %");
    // TODO: The premium is not the right place to store the trade price...

    if (securityDefinition instanceof InterestRateFutureOptionMarginSecurityDefinition) {
      final InterestRateFutureOptionMarginSecurityDefinition underlyingOption =
          (InterestRateFutureOptionMarginSecurityDefinition) securityDefinition;
      return new InterestRateFutureOptionMarginTransactionDefinition(
          underlyingOption, quantity, tradeDate, tradePrice);
    }
    final InterestRateFutureOptionPremiumSecurityDefinition underlyingOption =
        (InterestRateFutureOptionPremiumSecurityDefinition) securityDefinition;
    return new InterestRateFutureOptionPremiumTransactionDefinition(
        underlyingOption, quantity, tradeDate, tradePrice);
  }
Esempio n. 2
0
 @Override
 public Map<String, String> getAttributes() {
   Map<String, String> allAttributes = Maps.newHashMap();
   for (Trade trade : _trades) {
     allAttributes.putAll(trade.getAttributes());
   }
   return allAttributes;
 }
 private static void cacheTradesPositionsAndSecurities(
     final CachingComputationTargetResolver resolver, final PortfolioNode node) {
   final Collection<Position> positions = node.getPositions();
   resolver.cachePositions(positions);
   for (Position position : positions) {
     resolver.cacheSecurities(Collections.singleton(position.getSecurity()));
     for (Trade trade : position.getTrades()) {
       resolver.cacheSecurities(Collections.singleton(trade.getSecurity()));
     }
     resolver.cacheTrades(position.getTrades());
   }
   for (PortfolioNode child : node.getChildNodes()) {
     cacheTradesPositionsAndSecurities(resolver, child);
   }
 }
 @Override
 public List<ExternalId> getIds(Trade trade) {
   Security security = trade.getSecurity();
   if (security instanceof FinancialSecurity) {
     return ((FinancialSecurity) security).accept(_visitor);
   }
   return null;
 }
Esempio n. 5
0
 @Override
 public Object getValue(final Object object, final String name) {
   if (object instanceof Position) {
     final Position position = (Position) object;
     if ("trade".equals(name)) {
       final Collection<Trade> trades = position.getTrades();
       if (trades.size() == 1) {
         return trades.iterator().next();
       } else if (trades.isEmpty()) {
         return UserExpression.NA;
       } else {
         return new AnyTradeAttribute(trades);
       }
     } else {
       Object value = position.getAttributes().get(name);
       if (value != null) {
         return value;
       } else {
         for (Trade trade : position.getTrades()) {
           value = trade.getAttributes().get(name);
           if (value != null) {
             return value;
           }
         }
         return UserExpression.NA;
       }
     }
   } else if (object instanceof AnyTradeAttribute) {
     final AnyTradeAttribute trades = (AnyTradeAttribute) object;
     for (Trade trade : trades.getTrades()) {
       final Object value = trade.getAttributes().get(name);
       if (value != null) {
         return value;
       }
     }
     return UserExpression.NA;
   } else if (object instanceof Trade) {
     final Trade trade = (Trade) object;
     final Object value = trade.getAttributes().get(name);
     if (value != null) {
       return value;
     } else {
       return UserExpression.NA;
     }
   } else {
     return UserExpression.NA;
   }
 }