示例#1
0
 protected Result(
     final org.fudgemsg.mapping.FudgeDeserializationContext fudgeContext,
     final org.fudgemsg.FudgeMsg fudgeMsg) {
   super(fudgeContext, fudgeMsg);
   org.fudgemsg.FudgeField fudgeField;
   fudgeField = fudgeMsg.getByName(RESULT_KEY);
   if (fudgeField == null)
     throw new IllegalArgumentException(
         "Fudge message is not a Result - field 'result' is not present");
   try {
     _result =
         fudgeContext.fieldValueToObject(
             com.opengamma.engine.view.calcnode.CalculationJobResult.class, fudgeField);
   } catch (IllegalArgumentException e) {
     throw new IllegalArgumentException(
         "Fudge message is not a Result - field 'result' is not CalculationJobResult message", e);
   }
   fudgeField = fudgeMsg.getByName(READY_KEY);
   if (fudgeField != null) {
     try {
       final com.opengamma.engine.view.calcnode.msg.Ready fudge1;
       fudge1 =
           com.opengamma.engine.view.calcnode.msg.Ready.fromFudgeMsg(
               fudgeContext, fudgeMsg.getFieldValue(org.fudgemsg.FudgeMsg.class, fudgeField));
       setReady(fudge1);
     } catch (IllegalArgumentException e) {
       throw new IllegalArgumentException(
           "Fudge message is not a Result - field 'ready' is not Ready message", e);
     }
   }
 }
 @Override
 public CycleExecutionFailedCall buildObject(FudgeDeserializationContext context, FudgeMsg msg) {
   ViewCycleExecutionOptions cycleExecutionOptions =
       context.fieldValueToObject(
           ViewCycleExecutionOptions.class, msg.getByName(EXECUTION_OPTIONS_FIELD));
   FudgeField exceptionField = msg.getByName(EXCEPTION_FIELD);
   Exception exception =
       exceptionField != null ? context.fieldValueToObject(Exception.class, exceptionField) : null;
   return new CycleExecutionFailedCall(cycleExecutionOptions, exception);
 }
 @Override
 public StandardSmileSurfaceDataBundle buildObject(
     final FudgeDeserializer deserializer, final FudgeMsg message) {
   final ForwardCurve forwardCurve =
       deserializer.fieldValueToObject(
           ForwardCurve.class, message.getByName(FORWARD_CURVE_FIELD_NAME));
   final double[] expiries =
       deserializer.fieldValueToObject(double[].class, message.getByName(EXPIRIES_FIELD_NAME));
   final double[][] strikes =
       deserializer.fieldValueToObject(double[][].class, message.getByName(STRIKES_FIELD_NAME));
   final double[][] vols =
       deserializer.fieldValueToObject(double[][].class, message.getByName(VOLS_FIELD_NAME));
   final boolean isCallData = message.getBoolean(IS_CALL_FIELD_NAME);
   return new StandardSmileSurfaceDataBundle(forwardCurve, expiries, strikes, vols, isCallData);
 }
  @Override
  public YieldCurveBundle buildObject(
      final FudgeDeserializer deserializer, final FudgeMsg message) {
    // note name in curve & name in bundle may be different!
    final List<FudgeField> curveFields = message.getAllByName(CURVES_FIELD_NAME);
    final List<FudgeField> curveNameFields = message.getAllByName(CURVES_NAME_FIELD_NAME);
    final List<FudgeField> ccyFields = message.getAllByName(CURRENCY_FIELD_NAME);
    final List<FudgeField> ccyCurveFields = message.getAllByName(CURRENCY_CURVE_FIELD_NAME);
    final Map<String, YieldAndDiscountCurve> curves = new LinkedHashMap<>(curveFields.size());
    final Map<String, Currency> curveCurrencys = Maps.newHashMapWithExpectedSize(ccyFields.size());
    final FXMatrix fxMatrix =
        deserializer.fieldValueToObject(FXMatrix.class, message.getByName(FX_MATRIX_FIELD_NAME));
    for (int i = 0; i < curveFields.size(); i++) {
      final YieldAndDiscountCurve curve =
          deserializer.fieldValueToObject(YieldAndDiscountCurve.class, curveFields.get(i));
      final String name = deserializer.fieldValueToObject(String.class, curveNameFields.get(i));
      curves.put(name, curve);
    }
    for (int i = 0; i < ccyFields.size(); i++) {
      final String name = deserializer.fieldValueToObject(String.class, ccyCurveFields.get(i));
      final Currency ccy = deserializer.fieldValueToObject(Currency.class, ccyFields.get(i));
      curveCurrencys.put(name, ccy);
    }

    return new YieldCurveBundle(fxMatrix, curveCurrencys, curves);
  }
示例#5
0
 @Override
 public DoubleMatrix2D buildObject(
     final FudgeDeserializer deserializer, final FudgeMsg message) {
   final double[][] data =
       deserializer.fieldValueToObject(double[][].class, message.getByName(DATA_FIELD_NAME));
   return new DoubleMatrix2D(data);
 }
示例#6
0
 private void checkSecurityMessage(final FudgeMsgEnvelope fme) {
   assertNotNull(fme);
   final FudgeMsg msg = fme.getMessage();
   assertNotNull(msg);
   FudgeMsgFormatter.outputToSystemOut(msg);
   final FudgeMsg security =
       msg.getFieldValue(FudgeMsg.class, msg.getByName(SECURITYSOURCE_SECURITY));
   assertNotNull(security);
 }
 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
 public Position buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
   final SimplePosition position = buildObjectImpl(deserializer, message);
   final FudgeField parentField = message.getByName(FIELD_PARENT);
   final UniqueId parentId =
       (parentField != null) ? deserializer.fieldValueToObject(UniqueId.class, parentField) : null;
   if (parentId != null) {
     position.setParentNodeId(parentId);
   }
   return position;
 }
 @Override
 public SimpleHistoricalTimeSeries buildObject(FudgeDeserializer deserializer, FudgeMsg message) {
   UniqueId uniqueId = null;
   LocalDateDoubleTimeSeries timeseries = null;
   if (message.getByName(UNIQUE_ID_FIELD_NAME) != null) {
     uniqueId =
         deserializer.fieldValueToObject(UniqueId.class, message.getByName(UNIQUE_ID_FIELD_NAME));
   }
   if (message.hasField(TIMESERIES_FIELD_NAME)) {
     Object fieldValue = deserializer.fieldValueToObject(message.getByName(TIMESERIES_FIELD_NAME));
     if (fieldValue instanceof LocalDateDoubleTimeSeries) {
       timeseries = (LocalDateDoubleTimeSeries) fieldValue;
     }
   }
   if (uniqueId != null && timeseries != null) {
     return new SimpleHistoricalTimeSeries(uniqueId, timeseries);
   } else {
     throw new OpenGammaRuntimeException(
         "Cannot deserialize " + message + " to SimpleHistoricalTimeSeries");
   }
 }
  @Override
  public CalculationJobItem buildObject(FudgeDeserializer deserializer, FudgeMsg message) {

    ComputationTargetSpecification computationTargetSpecification =
        deserializer.fudgeMsgToObject(ComputationTargetSpecification.class, message);
    Validate.notNull(
        computationTargetSpecification,
        "Fudge message is not a CalculationJobItem - field 'computationTargetSpecification' is not present");

    String functionUniqueId = message.getString(FUNCTION_UNIQUE_ID_FIELD_NAME);
    Validate.notNull(
        functionUniqueId,
        "Fudge message is not a CalculationJobItem - field 'functionUniqueIdentifier' is not present");

    FudgeField fudgeField = message.getByName(FUNCTION_PARAMETERS_FIELD_NAME);
    Validate.notNull(
        fudgeField,
        "Fudge message is not a CalculationJobItem - field 'functionParameters' is not present");
    FunctionParameters functionParameters =
        deserializer.fieldValueToObject(FunctionParameters.class, fudgeField);

    final long[] inputIdentifiers = (long[]) message.getByName(INPUT_FIELD_NAME).getValue();

    List<ValueRequirement> desiredValues = new ArrayList<ValueRequirement>();
    for (FudgeField field : message.getAllByName(DESIRED_VALUE_FIELD_NAME)) {
      FudgeMsg valueMsg = (FudgeMsg) field.getValue();
      ValueRequirement desiredValue =
          deserializer.fudgeMsgToObject(ValueRequirement.class, valueMsg);
      desiredValues.add(desiredValue);
    }

    return CalculationJobItem.create(
        functionUniqueId,
        functionParameters,
        computationTargetSpecification,
        inputIdentifiers,
        desiredValues);
  }
 @Override
 public FixedIncomeStripWithSecurity buildObject(
     FudgeDeserializationContext context, FudgeMsg message) {
   StripInstrumentType type =
       context.fieldValueToObject(StripInstrumentType.class, message.getByName("type"));
   Tenor tenor = context.fieldValueToObject(Tenor.class, message.getByName("tenor"));
   Tenor resolvedTenor =
       context.fieldValueToObject(Tenor.class, message.getByName("resolvedTenor"));
   ZonedDateTimeBuilder zonedDateTimeBuilder = new ZonedDateTimeBuilder();
   ZonedDateTime maturity =
       zonedDateTimeBuilder.buildObject(context, message.getMessage("maturity"));
   Identifier identifier =
       context.fieldValueToObject(Identifier.class, message.getByName("identifier"));
   Security security = (Security) context.fieldValueToObject(message.getByName("security"));
   if (type == StripInstrumentType.FUTURE) {
     int numFutures = message.getInt("numFutures");
     return new FixedIncomeStripWithSecurity(
         type, tenor, resolvedTenor, numFutures, maturity, identifier, security);
   } else {
     return new FixedIncomeStripWithSecurity(
         type, tenor, resolvedTenor, maturity, identifier, security);
   }
 }
示例#12
0
  // -------------------------------------------------------------------------
  @SuppressWarnings("unchecked")
  @Override
  public T buildObject(FudgeDeserializer deserializer, FudgeMsg outerMsg) {
    FudgeField fudgeField = outerMsg.getByName("inner");
    FudgeMsg msg = (FudgeMsg) fudgeField.getValue();

    final FudgeField classNameField = msg.getByOrdinal(FudgeSerializer.TYPES_HEADER_ORDINAL);
    final String className = (String) classNameField.getValue();
    try {
      final List<Object> parameters = newArrayList();
      parameters.add(null); // the omitted enclosing object
      for (FudgeField parameterField : msg.getAllByOrdinal(1)) {
        parameters.add(deserializer.fieldValueToObject(parameterField));
      }

      return (T)
          AccessController.doPrivileged(
              new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                  try {
                    final Class<?> innerClass = Class.forName(className);
                    final Constructor<?>[] ctors = innerClass.getDeclaredConstructors();
                    // We require that inner classes got only one ctor (anonymous inner classes will
                    // do)
                    // in order to avoid disambiguity
                    if (ctors.length == 1) {
                      final Constructor<?> ctor = ctors[0];
                      ctor.setAccessible(true); // solution
                      Object inner = ctor.newInstance(parameters.toArray());
                      return new AutoFudgable<Object>(inner);
                    }
                  } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                  } catch (InstantiationException e) {
                    throw new RuntimeException(e);
                  } catch (InvocationTargetException e) {
                    throw new RuntimeException(e);
                  } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                  }
                  return null;
                }
              });

    } catch (RuntimeException ex) {
      throw new FudgeRuntimeException("Unable to deserialize: " + className, ex);
    }
  }
示例#13
0
  protected static SimplePosition buildObjectImpl(
      final FudgeDeserializer deserializer, final FudgeMsg message) {
    SimpleSecurityLink secLink = new SimpleSecurityLink();
    if (message.hasField(FIELD_SECURITYKEY)) {
      FudgeField secKeyField = message.getByName(FIELD_SECURITYKEY);
      if (secKeyField != null) {
        secLink.setExternalId(deserializer.fieldValueToObject(ExternalIdBundle.class, secKeyField));
      }
    }
    if (message.hasField(FIELD_SECURITYID)) {
      FudgeField secIdField = message.getByName(FIELD_SECURITYID);
      if (secIdField != null) {
        secLink.setObjectId(deserializer.fieldValueToObject(ObjectId.class, secIdField));
      }
    }

    SimplePosition position = new SimplePosition();
    position.setSecurityLink(secLink);
    if (message.hasField(FIELD_UNIQUE_ID)) {
      FudgeField uniqueIdField = message.getByName(FIELD_UNIQUE_ID);
      if (uniqueIdField != null) {
        position.setUniqueId(deserializer.fieldValueToObject(UniqueId.class, uniqueIdField));
      }
    }
    if (message.hasField(FIELD_QUANTITY)) {
      FudgeField quantityField = message.getByName(FIELD_QUANTITY);
      if (quantityField != null) {
        position.setQuantity(message.getFieldValue(BigDecimal.class, quantityField));
      }
    }
    readTrades(
        deserializer,
        message.getFieldValue(FudgeMsg.class, message.getByName(FIELD_TRADES)),
        position);
    return position;
  }
 @Override
 public MulticurveProviderDiscount buildObject(
     final FudgeDeserializer deserializer, final FudgeMsg message) {
   final Map<Currency, YieldAndDiscountCurve> discountingCurves = new LinkedHashMap<>();
   final List<FudgeField> currencyFields = message.getAllByName(CURRENCY_FIELD);
   final List<FudgeField> discountingCurveFields = message.getAllByName(DISCOUNTING_CURVE_FIELD);
   for (int i = 0; i < currencyFields.size(); i++) {
     final Currency currency = Currency.of((String) currencyFields.get(i).getValue());
     final YieldAndDiscountCurve curve =
         deserializer.fudgeMsgToObject(
             YieldAndDiscountCurve.class, (FudgeMsg) discountingCurveFields.get(i).getValue());
     discountingCurves.put(currency, curve);
   }
   final Map<IborIndex, YieldAndDiscountCurve> forwardIborCurves = new LinkedHashMap<>();
   final List<FudgeField> indexIborFields = message.getAllByName(INDEX_IBOR_FIELD);
   final List<FudgeField> forwardIborCurveFields = message.getAllByName(INDEX_IBOR_CURVE);
   for (int i = 0; i < currencyFields.size(); i++) {
     final IborIndex index =
         deserializer.fudgeMsgToObject(
             IborIndex.class, (FudgeMsg) indexIborFields.get(i).getValue());
     final YieldAndDiscountCurve curve =
         deserializer.fudgeMsgToObject(
             YieldAndDiscountCurve.class, (FudgeMsg) forwardIborCurveFields.get(i).getValue());
     forwardIborCurves.put(index, curve);
   }
   final Map<IndexON, YieldAndDiscountCurve> forwardONCurves = new LinkedHashMap<>();
   final List<FudgeField> indexONFields = message.getAllByName(INDEX_ON_FIELD);
   final List<FudgeField> forwardONCurveFields = message.getAllByName(OVERNIGHT_CURVE_FIELD);
   for (int i = 0; i < currencyFields.size(); i++) {
     final IndexON index =
         deserializer.fudgeMsgToObject(
             IndexON.class, (FudgeMsg) indexONFields.get(i).getValue());
     final YieldAndDiscountCurve curve =
         deserializer.fudgeMsgToObject(
             YieldAndDiscountCurve.class, (FudgeMsg) forwardONCurveFields.get(i).getValue());
     forwardONCurves.put(index, curve);
   }
   final FXMatrix fxMatrix =
       deserializer.fieldValueToObject(FXMatrix.class, message.getByName(FX_MATRIX_FIELD));
   return new MulticurveProviderDiscount(
       discountingCurves, forwardIborCurves, forwardONCurves, fxMatrix);
 }
 @Override
 public InflationProviderDiscount buildObject(
     final FudgeDeserializer deserializer, final FudgeMsg message) {
   final MulticurveProviderDiscount yieldCurves =
       deserializer.fieldValueToObject(
           MulticurveProviderDiscount.class, message.getByName(YIELD_CURVES_FIELD));
   final List<FudgeField> indexFields = message.getAllByName(PRICE_INDEX_FIELD);
   final List<FudgeField> indexCurveFields = message.getAllByName(PRICE_INDEX_CURVE_FIELD);
   final Map<IndexPrice, PriceIndexCurve> priceIndexCurves = new LinkedHashMap<>();
   final int n = indexFields.size();
   for (int i = 0; i < n; i++) {
     final IndexPrice index =
         deserializer.fudgeMsgToObject(
             IndexPrice.class, (FudgeMsg) indexFields.get(i).getValue());
     final PriceIndexCurve curve =
         deserializer.fudgeMsgToObject(
             PriceIndexCurve.class, (FudgeMsg) indexCurveFields.get(i).getValue());
     priceIndexCurves.put(index, curve);
   }
   return new InflationProviderDiscount(yieldCurves, priceIndexCurves);
 }
 @Override
 public FXMatrix buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
   final List<FudgeField> currencies = message.getAllByName(CURRENCY_FIELD);
   final List<FudgeField> orders = message.getAllByName(ORDER_FIELD);
   final Map<Currency, Integer> map = new HashMap<>();
   for (int i = 0; i < currencies.size(); i++) {
     final Currency currency = Currency.of((String) currencies.get(i).getValue());
     final Integer order = ((Number) orders.get(i).getValue()).intValue();
     map.put(currency, order);
   }
   final List<FudgeField> entries = message.getAllByName(ENTRIES_FIELD);
   final List<FudgeField> arrays = message.getAllByName(FX_RATES_FIELD);
   final double[][] fxRates = new double[entries.size()][];
   for (int i = 0; i < entries.size(); i++) {
     final FudgeMsg msg = (FudgeMsg) arrays.get(i).getValue();
     final double[] row =
         deserializer.fieldValueToObject(double[].class, msg.getByName(ROW_FIELD));
     fxRates[i] = row;
   }
   return new FXMatrix(map, fxRates);
 }
示例#17
0
 public static Scaling fromFudgeMsg(final FudgeDeserializer deserializer, final FudgeMsg msg) {
   Double scalingFactor =
       deserializer.fieldValueToObject(Double.class, msg.getByName(SCALING_FACTOR));
   return new Scaling(scalingFactor);
 }