Exemplo 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);
  }
 @Override
 public List<ExternalId> getIds(Trade trade) {
   Security security = trade.getSecurity();
   if (security instanceof FinancialSecurity) {
     return ((FinancialSecurity) security).accept(_visitor);
   }
   return null;
 }
Exemplo n.º 3
0
 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);
   }
 }