private IRFutureOptionTrade createIRFutureOptionTrade() {

    String exchange = "TestExchange";
    ExerciseType exerciseType = new EuropeanExerciseType();
    double pointValue = Double.NaN;
    boolean margined = true;
    double strike = 0.99;
    OptionType optionType = OptionType.PUT;
    ExternalId irFutureId = Iterables.getOnlyElement(_irFuture.getExternalIdBundle());
    IRFutureOptionSecurity irFutureOption =
        new IRFutureOptionSecurity(
            exchange,
            _irFuture.getExpiry(),
            exerciseType,
            irFutureId,
            pointValue,
            margined,
            _irFuture.getCurrency(),
            strike,
            optionType);
    // Need this for time series lookup
    irFutureOption.setExternalIdBundle(
        ExternalSchemes.syntheticSecurityId("Test future option").toBundle());

    Counterparty counterparty =
        new SimpleCounterparty(ExternalId.of(Counterparty.DEFAULT_SCHEME, "COUNTERPARTY"));
    BigDecimal tradeQuantity = BigDecimal.valueOf(1);
    SimpleTrade trade =
        new SimpleTrade(irFutureOption, tradeQuantity, counterparty, TRADE_DATE, TRADE_TIME);
    trade.setPremium(10.0);
    trade.setPremiumCurrency(Currency.USD);
    return new IRFutureOptionTrade(trade);
  }
Exemplo n.º 2
0
 private static void readTrades(
     final FudgeDeserializer deserializer, final FudgeMsg message, final SimplePosition position) {
   if (message != null) {
     for (FudgeField field : message) {
       if (field.getValue() instanceof FudgeMsg) {
         final SimpleTrade trade =
             TradeBuilder.buildObjectImpl(deserializer, (FudgeMsg) field.getValue());
         trade.setParentPositionId(position.getUniqueId());
         position.addTrade(trade);
       }
     }
   }
 }
  @Override
  public Set<ComputedValue> execute(
      FunctionExecutionContext executionContext,
      FunctionInputs inputs,
      ComputationTarget target,
      Set<ValueRequirement> desiredValues) {

    // 1. Get the expiry _time_ from the trade
    SimpleTrade trade =
        (SimpleTrade) target.getTrade(); // confirms that the ComputationTargetType == TRADE
    EquityVarianceSwapSecurity security = (EquityVarianceSwapSecurity) trade.getSecurity();
    double expiry =
        TimeCalculator.getTimeBetween(
            executionContext.getValuationClock().zonedDateTime(),
            security.getLastObservationDate());

    // ExternalId id = security.getSpotUnderlyingIdentifier();

    // 2. Get the discount curve and spot value
    Object discountObject = inputs.getValue(getDiscountRequirement(security));
    if (discountObject == null) {
      throw new OpenGammaRuntimeException("Could not get Discount Curve");
    }
    YieldAndDiscountCurve discountCurve = (YieldAndDiscountCurve) discountObject;

    Object spotObject = inputs.getValue(getSpotRequirement(security));
    if (spotObject == null) {
      throw new OpenGammaRuntimeException("Could not get Underlying's Spot value");
    }
    double spot = (Double) spotObject;

    // 3. Compute the forward
    final double discountFactor = discountCurve.getDiscountFactor(expiry);
    Validate.isTrue(
        discountFactor != 0,
        "The discount curve has returned a zero value for a discount bond. Check rates.");
    final double forward = spot / discountFactor;

    ValueSpecification valueSpec = getValueSpecification(security);
    return Collections.singleton(new ComputedValue(valueSpec, forward));
  }
 public void testTrade() {
   SimpleTrade trade = new SimpleTrade();
   trade.setUniqueId(UniqueId.of("A", "B"));
   trade.setQuantity(BigDecimal.valueOf(12.34d));
   trade.setSecurityLink(new SimpleSecurityLink(ExternalId.of("E", "F")));
   trade.setCounterparty(new SimpleCounterparty(ExternalId.of("G", "H")));
   trade.setTradeDate(LocalDate.of(2011, 1, 5));
   trade.setTradeTime(OffsetTime.parse("14:30+02:00"));
   assertEncodeDecodeCycle(Trade.class, trade);
 }
  @SuppressWarnings("deprecation")
  public void testTrade_withPremium() {
    SimpleTrade trade = new SimpleTrade();
    trade.setUniqueId(UniqueId.of("A", "B"));
    trade.setQuantity(BigDecimal.valueOf(12.34d));
    trade.setSecurityLink(new SimpleSecurityLink(ObjectId.of("E", "F")));
    trade.setCounterparty(new SimpleCounterparty(ExternalId.of("G", "H")));
    trade.setTradeDate(LocalDate.of(2011, 1, 5));
    trade.setTradeTime(OffsetTime.parse("14:30+02:00"));

    // set premium
    trade.setPremium(100.00);
    trade.setPremiumCurrency(Currency.USD);
    trade.setPremiumDate(LocalDate.of(2011, 1, 6));
    trade.setPremiumTime(OffsetTime.parse("15:30+02:00"));
    assertEncodeDecodeCycle(Trade.class, trade);
  }
  public void testFull() {
    SimpleTrade trade = new SimpleTrade();
    trade.setUniqueId(UniqueId.of("A", "B"));
    trade.setQuantity(BigDecimal.valueOf(12.34d));
    trade.setSecurityLink(new SimpleSecurityLink(ExternalId.of("E", "F")));
    trade.setCounterparty(new SimpleCounterparty(ExternalId.of("G", "H")));
    trade.setTradeDate(LocalDate.of(2011, 1, 5));
    trade.setTradeTime(OffsetTime.parse("14:30+02:00"));

    // set premium
    trade.setPremium(100.00);
    trade.setPremiumCurrency(Currency.USD);
    trade.setPremiumDate(LocalDate.of(2011, 1, 6));
    trade.setPremiumTime(OffsetTime.parse("15:30+02:00"));

    // set attributes
    trade.addAttribute("A", "B");
    trade.addAttribute("C", "D");
    assertEncodeDecodeCycle(Trade.class, trade);
  }