@Override
 public int hashCode() {
   final int prime = 31;
   int result = super.hashCode();
   result = prime * result + ((_callExpiry == null) ? 0 : _callExpiry.hashCode());
   long temp;
   temp = Double.doubleToLongBits(_callStrike);
   result = prime * result + (int) (temp ^ (temp >>> 32));
   result = prime * result + ((_putExpiry == null) ? 0 : _putExpiry.hashCode());
   temp = Double.doubleToLongBits(_putStrike);
   result = prime * result + (int) (temp ^ (temp >>> 32));
   return result;
 }
 @Override
 public String toString() {
   String result = "European swaption cash delivery: \n";
   result += "Expiry date: " + _expiry.toString() + ", Long: " + _isLong;
   result += "\nUnderlying swap: \n" + _underlyingSwap.toString();
   return result;
 }
 public int hashCode() {
   int hc = super.hashCode();
   hc *= 31;
   if (_chooseDate != null) hc += _chooseDate.hashCode();
   hc = (hc * 31) + (int) _underlyingStrike;
   hc *= 31;
   if (_underlyingExpiry != null) hc += _underlyingExpiry.hashCode();
   return hc;
 }
 public void toFudgeMsg(
     final org.fudgemsg.mapping.FudgeSerializationContext fudgeContext,
     final org.fudgemsg.MutableFudgeMsg msg) {
   super.toFudgeMsg(fudgeContext, msg);
   if (_chooseDate != null) {
     fudgeContext.addToMessage(msg, CHOOSE_DATE_KEY, null, _chooseDate);
   }
   msg.add(UNDERLYING_STRIKE_KEY, null, _underlyingStrike);
   if (_underlyingExpiry != null) {
     final org.fudgemsg.MutableFudgeMsg fudge1 =
         org.fudgemsg.mapping.FudgeSerializationContext.addClassHeader(
             fudgeContext.newMessage(),
             _underlyingExpiry.getClass(),
             com.opengamma.util.time.Expiry.class);
     _underlyingExpiry.toFudgeMsg(fudgeContext, fudge1);
     msg.add(UNDERLYING_EXPIRY_KEY, null, fudge1);
   }
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + _expiry.hashCode();
   result = prime * result + (_isLong ? 1231 : 1237);
   result = prime * result + _underlyingSwap.hashCode();
   return result;
 }
 @Override
 public SwaptionCashFixedIbor toDerivative(
     final ZonedDateTime date, final String... yieldCurveNames) {
   Validate.notNull(date, "date");
   Validate.notNull(yieldCurveNames, "yield curve names");
   final DayCount actAct = DayCountFactory.INSTANCE.getDayCount("Actual/Actual ISDA");
   final double expiryTime = actAct.getDayCountFraction(date, _expiry.getExpiry());
   final double settlementTime = actAct.getDayCountFraction(date, _settlementDate);
   final FixedCouponSwap<? extends Payment> underlyingSwap =
       _underlyingSwap.toDerivative(date, yieldCurveNames);
   return SwaptionCashFixedIbor.from(expiryTime, underlyingSwap, settlementTime, _isLong);
 }
 @Test(groups = {"bbgSecurityFutureTests"})
 public void euroBondFuture() throws Exception {
   ExternalIdBundle euroBund =
       ExternalIdBundle.of(ExternalSchemes.bloombergTickerSecurityId("RXA Comdty"));
   Security bond = _securityProvider.getSecurity(euroBund);
   assertNotNull(bond);
   assertTrue(bond instanceof BondFutureSecurity);
   BondFutureSecurity euroBondFuture = (BondFutureSecurity) bond;
   assertEquals("FUTURE", euroBondFuture.getSecurityType());
   assertEquals("Bond", euroBondFuture.getContractCategory());
   assertEquals(EUR, euroBondFuture.getCurrency());
   String displayName = euroBondFuture.getName();
   assertNotNull(displayName);
   assertTrue(displayName.contains("EURO-BUND FUTURE"));
   Expiry expiry = euroBondFuture.getExpiry();
   assertNotNull(expiry);
   assertTrue(expiry.toInstant().isAfter(getTodayInstant()));
   assertEquals("XEUR", euroBondFuture.getTradingExchange());
   assertEquals("XEUR", euroBondFuture.getSettlementExchange());
   // assert identifiers are set
   Collection<ExternalId> identifiers = euroBondFuture.getExternalIdBundle().getExternalIds();
   assertNotNull(identifiers);
   assertTrue(identifiers.size() >= EXPECTED_IDENTIFICATION_SCHEME.length);
   ExternalIdBundle identifierBundle = ExternalIdBundle.of(identifiers);
   for (ExternalScheme expectedIDScheme : EXPECTED_IDENTIFICATION_SCHEME) {
     assertNotNull(identifierBundle.getExternalId(expectedIDScheme));
   }
   // assert deliverables are not empty
   Collection<BondFutureDeliverable> basket = euroBondFuture.getBasket();
   assertNotNull(basket);
   for (BondFutureDeliverable bondFutureDeliverable : basket) {
     ExternalIdBundle bundle = bondFutureDeliverable.getIdentifiers();
     assertNotNull(bundle);
     assertNotNull(bundle.getExternalId(ExternalSchemes.BLOOMBERG_BUID));
     assertTrue(bondFutureDeliverable.getConversionFactor() > 0);
   }
 }
 /**
  * @param callStrike The strike of the potential call option
  * @param putStrike The strike of the potential put option
  * @param chooseDate The choice date (expiry) of the chooser option
  * @param callExpiry The expiry date of the potential call option
  * @param putExpiry The expiry date of the potential put option
  */
 public ComplexChooserOptionDefinition(
     final Expiry chooseDate,
     final double callStrike,
     final Expiry callExpiry,
     final double putStrike,
     final Expiry putExpiry) {
   super(null, chooseDate, null);
   Validate.notNull(callExpiry);
   Validate.notNull(putExpiry);
   ArgumentChecker.notNegative(callStrike, "call strike");
   ArgumentChecker.notNegative(putStrike, "put strike");
   if (callExpiry.getExpiry().isBefore(chooseDate.getExpiry())) {
     throw new IllegalArgumentException("Call expiry must be after the choose date");
   }
   if (putExpiry.getExpiry().isBefore(chooseDate.getExpiry())) {
     throw new IllegalArgumentException("Put expiry must be after the choose date");
   }
   _callStrike = callStrike;
   _putStrike = putStrike;
   _callExpiry = callExpiry;
   _putExpiry = putExpiry;
   _callDefinition = new EuropeanVanillaOptionDefinition(callStrike, callExpiry, true);
   _putDefinition = new EuropeanVanillaOptionDefinition(putStrike, putExpiry, false);
 }
 @Test
 public void test() {
   assertEquals(PUT.getPeriodEnd(), PERIOD_END);
   assertFalse(PUT.isReverse());
   ExtremeSpreadOptionDefinition other =
       new ExtremeSpreadOptionDefinition(EXPIRY, false, PERIOD_END, false);
   assertEquals(other, PUT);
   assertEquals(other.hashCode(), PUT.hashCode());
   other =
       new ExtremeSpreadOptionDefinition(
           EXPIRY, false, new Expiry(DateUtils.getDateOffsetWithYearFraction(DATE, 0.15)), false);
   assertFalse(other.equals(PUT));
   other = new ExtremeSpreadOptionDefinition(EXPIRY, false, PERIOD_END, true);
   assertFalse(other.equals(PUT));
   assertEquals(PUT.getTimeFromPeriodEnd(EXPIRY.getExpiry()), 0.725, 0);
   assertEquals(PUT.getTimeFromPeriodEnd(DATE), -0.275, 0);
 }
 public boolean equals(final Object o) {
   if (o == this) return true;
   if (!(o instanceof SimpleChooserPayoffStyle)) return false;
   SimpleChooserPayoffStyle msg = (SimpleChooserPayoffStyle) o;
   if (_chooseDate != null) {
     if (msg._chooseDate != null) {
       if (!_chooseDate.equals(msg._chooseDate)) return false;
     } else return false;
   } else if (msg._chooseDate != null) return false;
   if (_underlyingStrike != msg._underlyingStrike) return false;
   if (_underlyingExpiry != null) {
     if (msg._underlyingExpiry != null) {
       if (!_underlyingExpiry.equals(msg._underlyingExpiry)) return false;
     } else return false;
   } else if (msg._underlyingExpiry != null) return false;
   return super.equals(msg);
 }
 protected SimpleChooserPayoffStyle(
     final org.fudgemsg.mapping.FudgeDeserializationContext fudgeContext,
     final org.fudgemsg.FudgeMsg fudgeMsg) {
   super(fudgeContext, fudgeMsg);
   org.fudgemsg.FudgeField fudgeField;
   fudgeField = fudgeMsg.getByName(CHOOSE_DATE_KEY);
   if (fudgeField == null)
     throw new IllegalArgumentException(
         "Fudge message is not a SimpleChooserPayoffStyle - field 'chooseDate' is not present");
   try {
     _chooseDate =
         fudgeContext.fieldValueToObject(javax.time.calendar.ZonedDateTime.class, fudgeField);
   } catch (IllegalArgumentException e) {
     throw new IllegalArgumentException(
         "Fudge message is not a SimpleChooserPayoffStyle - field 'chooseDate' is not ZonedDateTime typedef",
         e);
   }
   fudgeField = fudgeMsg.getByName(UNDERLYING_STRIKE_KEY);
   if (fudgeField == null)
     throw new IllegalArgumentException(
         "Fudge message is not a SimpleChooserPayoffStyle - field 'underlyingStrike' is not present");
   try {
     _underlyingStrike = fudgeMsg.getFieldValue(Double.class, fudgeField);
   } catch (IllegalArgumentException e) {
     throw new IllegalArgumentException(
         "Fudge message is not a SimpleChooserPayoffStyle - field 'underlyingStrike' is not double",
         e);
   }
   fudgeField = fudgeMsg.getByName(UNDERLYING_EXPIRY_KEY);
   if (fudgeField == null)
     throw new IllegalArgumentException(
         "Fudge message is not a SimpleChooserPayoffStyle - field 'underlyingExpiry' is not present");
   try {
     _underlyingExpiry =
         com.opengamma.util.time.Expiry.fromFudgeMsg(
             fudgeContext, fudgeMsg.getFieldValue(org.fudgemsg.FudgeMsg.class, fudgeField));
   } catch (IllegalArgumentException e) {
     throw new IllegalArgumentException(
         "Fudge message is not a SimpleChooserPayoffStyle - field 'underlyingExpiry' is not Expiry message",
         e);
   }
 }
  // -------------------------------------------------------------------------
  @Override
  protected ManageableSecurity createSecurity(FudgeMsg fieldData) {
    String expiryDate = fieldData.getString(FIELD_FUT_LAST_TRADE_DT);
    String futureTradingHours = fieldData.getString(FIELD_FUT_TRADING_HRS);
    String micExchangeCode = fieldData.getString(FIELD_ID_MIC_PRIM_EXCH);
    String currencyStr = fieldData.getString(FIELD_CRNCY);
    String underlyingTicker = fieldData.getString(FIELD_UNDL_SPOT_TICKER);
    String name = fieldData.getString(FIELD_FUT_LONG_NAME);
    String bbgUnique = fieldData.getString(FIELD_ID_BBG_UNIQUE);
    String marketSector = fieldData.getString(FIELD_MARKET_SECTOR_DES);
    String unitAmount = fieldData.getString(FIELD_FUT_VAL_PT);

    if (!isValidField(bbgUnique)) {
      s_logger.warn("bbgUnique is null, cannot construct EquityFutureSecurity");
      return null;
    }
    if (!isValidField(expiryDate)) {
      s_logger.warn("expiry date is null, cannot construct EquityFutureSecurity");
      return null;
    }
    if (!isValidField(futureTradingHours)) {
      s_logger.warn("futures trading hours is null, cannot construct EquityFutureSecurity");
      return null;
    }
    if (!isValidField(micExchangeCode)) {
      s_logger.warn("settlement exchange is null, cannot construct EquityFutureSecurity");
      return null;
    }
    if (!isValidField(currencyStr)) {
      s_logger.info("currency is null, cannot construct EquityFutureSecurity");
      return null;
    }
    ExternalId underlying = null;
    if (underlyingTicker != null) {
      underlying = SecurityUtils.bloombergTickerSecurityId(underlyingTicker + " " + marketSector);
    }

    Currency currency = Currency.parse(currencyStr);

    Expiry expiry = decodeExpiry(expiryDate, futureTradingHours);
    if (expiry == null) {
      return null;
    }

    // FIXME: Case - treatment of Settlement Date
    s_logger.warn(
        "Creating EquityFutureSecurity - settlementDate set equal to expiryDate. Missing lag.");
    ZonedDateTime settlementDate = expiry.getExpiry();

    EquityFutureSecurity security =
        new EquityFutureSecurity(
            expiry,
            micExchangeCode,
            micExchangeCode,
            currency,
            Double.valueOf(unitAmount),
            settlementDate,
            underlying);

    if (isValidField(name)) {
      security.setName(BloombergDataUtils.removeDuplicateWhiteSpace(name, " "));
    }
    // set identifiers
    parseIdentifiers(fieldData, security);
    return security;
  }