public override CompiledViewCalculationConfigurationImpl DeserializeImpl(IFudgeFieldContainer msg, IFudgeDeserializer deserializer)
        {
            string name = msg.GetString("name");
            Dictionary <ValueRequirement, ValueSpecification> marketDataRequirements = MapBuilder.FromFudgeMsg <ValueRequirement, ValueSpecification>(msg.GetMessage("marketDataRequirements"), deserializer);
            var computationTargets = new HashSet <ComputationTargetSpecification>(msg.GetMessage("computationTargets").GetAllByOrdinal(1).Select(deserializer.FromField <ComputationTargetSpecification>));

            IFudgeFieldContainer specMessage = msg.GetMessage("terminalOutputSpecifications");
            Dictionary <ValueSpecification, HashSet <ValueRequirement> > terminalOutputSpecifications = MapBuilder.FromFudgeMsg(specMessage, deserializer.FromField <ValueSpecification>, f => GetRequirementSet(f, deserializer));

            return(new CompiledViewCalculationConfigurationImpl(name, marketDataRequirements, computationTargets, terminalOutputSpecifications));
        }
Exemple #2
0
        public static VolatilityCubeData FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var dataPoints = MapBuilder.FromFudgeMsg(ffc.GetMessage("dataPoints"), deserializer.FromField<VolatilityPoint>, f => (double)f.Value);
            var otherValues = deserializer.FromField<SnapshotDataBundle>(ffc.GetByName("otherData"));

            Dictionary<Pair<Tenor, Tenor>, double> strikes = null;

            var strikesField = ffc.GetMessage("strikes");
            if (strikesField != null)
            {
                strikes = strikesField.Select(deserializer.FromField<StrikeEntry>).ToDictionary(s => new Pair<Tenor, Tenor>(new Tenor(s.SwapTenor), new Tenor(s.OptionExpiry)), s => s.Strike);
            }
            return new VolatilityCubeData(dataPoints, otherValues, strikes);
        }
        public static VolatilityCubeData FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var dataPoints  = MapBuilder.FromFudgeMsg(ffc.GetMessage("dataPoints"), deserializer.FromField <VolatilityPoint>, f => (double)f.Value);
            var otherValues = deserializer.FromField <SnapshotDataBundle>(ffc.GetByName("otherData"));

            Dictionary <Pair <Tenor, Tenor>, double> strikes = null;

            var strikesField = ffc.GetMessage("strikes");

            if (strikesField != null)
            {
                strikes = strikesField.Select(deserializer.FromField <StrikeEntry>).ToDictionary(s => new Pair <Tenor, Tenor>(new Tenor(s.SwapTenor), new Tenor(s.OptionExpiry)), s => s.Strike);
            }
            return(new VolatilityCubeData(dataPoints, otherValues, strikes));
        }
        public static ManageableMarketDataSnapshot FromFudgeMsg(IFudgeFieldContainer ffc,
                                                                IFudgeDeserializer deserializer)
        {
            var      uidString = ffc.GetString("uniqueId");
            UniqueId uid       = uidString == null ? null : UniqueId.Parse(uidString);

            var surfaceMessage = ffc.GetMessage("volatilitySurfaces");
            Dictionary <VolatilitySurfaceKey, ManageableVolatilitySurfaceSnapshot> surfaces;

            if (surfaceMessage == null)
            {
                //Handle old format
                surfaces = new Dictionary <VolatilitySurfaceKey, ManageableVolatilitySurfaceSnapshot>();
            }
            else
            {
                surfaces = MapBuilder.FromFudgeMsg <VolatilitySurfaceKey, ManageableVolatilitySurfaceSnapshot>(surfaceMessage, deserializer);
            }
            var manageableMarketDataSnapshot = new ManageableMarketDataSnapshot(
                ffc.GetString("basisViewName"),
                deserializer.FromField <ManageableUnstructuredMarketDataSnapshot>(ffc.GetByName("globalValues")),
                MapBuilder.FromFudgeMsg <YieldCurveKey, ManageableYieldCurveSnapshot>(ffc.GetMessage("yieldCurves"), deserializer),
                MapBuilder.FromFudgeMsg <VolatilityCubeKey, ManageableVolatilityCubeSnapshot>(ffc.GetMessage("volatilityCubes"), deserializer),
                surfaces,
                uid

                )
            {
                Name = ffc.GetString("name")
            };

            return(manageableMarketDataSnapshot);
        }
        protected override InMemoryViewComputationResultModel BuildObject(IFudgeFieldContainer msg, IFudgeDeserializer deserializer, Dictionary <string, ViewCalculationResultModel> configurationMap, UniqueId viewProcessId, UniqueId viewCycleId, DateTimeOffset inputDataTimestamp, DateTimeOffset resultTimestamp, TimeSpan calculationDuration)
        {
            var liveDataMsg = msg.GetMessage("liveData");
            List <ComputedValue> liveData = liveDataMsg == null ? null : liveDataMsg.GetAllByOrdinal(1).Select(deserializer.FromField <ComputedValue>).ToList();

            return(new InMemoryViewComputationResultModel(viewProcessId, viewCycleId, inputDataTimestamp, resultTimestamp, configurationMap, liveData, calculationDuration));
        }
        public override ComputationTarget DeserializeImpl(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var computationTargetType = EnumBuilder <ComputationTargetType> .Parse(ffc.GetMessage("type").GetString(1));

            object value = GetValue(deserializer, ffc.GetByName("value"));

            return(new ComputationTarget(computationTargetType, value));
        }
 public static VolatilityCubeDefinition FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
 {
     return(new VolatilityCubeDefinition(
                deserializer.FromField <List <string> >(ffc.GetByName("swapTenors")).Select(s => new Tenor(s)).ToList(),
                deserializer.FromField <List <string> >(ffc.GetByName("optionExpiries")).Select(s => new Tenor(s)).ToList(),
                ffc.GetMessage("relativeStrikes").Select(f => f.Value).Cast <double>().ToList()
                ));
 }
 public static ChangeEvent FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
 {
     var changeType = EnumBuilder<ChangeType>.Parse(ffc.GetMessage("type").GetString(1));
     var beforeField = ffc.GetString("beforeId");
     var beforeId = beforeField == null ? null : UniqueId.Parse(beforeField);
     var afterField = ffc.GetString("afterId");
     var afterId = afterField == null ? null : UniqueId.Parse(afterField);
     var versionField = ffc.GetByName("versionInstant");
     var versionInstant = (FudgeDateTime) versionField.Value;
     return new ChangeEvent(changeType,
         beforeId,
         afterId,
         new Instant(versionInstant));
 }
Exemple #9
0
        public static ChangeEvent FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var changeType = EnumBuilder <ChangeType> .Parse(ffc.GetMessage("type").GetString(1));

            var beforeField    = ffc.GetString("beforeId");
            var beforeId       = beforeField == null ? null : UniqueId.Parse(beforeField);
            var afterField     = ffc.GetString("afterId");
            var afterId        = afterField == null ? null : UniqueId.Parse(afterField);
            var versionField   = ffc.GetByName("versionInstant");
            var versionInstant = (FudgeDateTime)versionField.Value;

            return(new ChangeEvent(changeType,
                                   beforeId,
                                   afterId,
                                   new Instant(versionInstant)));
        }
        public static MultipleCurrencyAmount FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var currencies = ffc.GetMessage("currencies").Select(f => (string)f.Value).Select(Currency.Create).ToList();
            var amounts    = (double[])ffc.GetByName("amounts").Value;

            if (currencies.Count != amounts.Length)
            {
                throw new ArgumentException("Mismatched labels and value", "ffc");
            }
            var dict = new SortedDictionary <Currency, CurrencyAmount>();

            for (int i = 0; i < currencies.Count; i++)
            {
                dict.Add(currencies[i], new CurrencyAmount(currencies[i], amounts[i]));
            }
            return(new MultipleCurrencyAmount(dict));
        }
        private ComponentRepository GetComponentRepository(IFudgeFieldContainer configMsg)
        {
            var componentInfos = new Dictionary<ComponentKey, ComponentInfo>();
            foreach (var userDataField in configMsg.GetMessage("infos"))
            {
                if (!(userDataField.Value is IFudgeFieldContainer))
                {
                    continue;
                }

                var component = (IFudgeFieldContainer)userDataField.Value;
                var uri = new Uri(_rootUri, component.GetString("uri"));
                var componentKey = new ComponentKey(component.GetString("type"), component.GetString("classifier"));
                Dictionary<string, string> attributes = component.GetMessage("attributes").ToDictionary(f => f.Name, f => (string) f.Value);
                componentInfos.Add(componentKey, new ComponentInfo(componentKey, uri, attributes));
            }
            return new ComponentRepository(componentInfos);
        }
Exemple #12
0
        public static ManageableVolatilityCubeSnapshot FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var values         = MapBuilder.FromFudgeMsg <VolatilityPoint, ValueSnapshot>(ffc.GetMessage("values"), deserializer);
            var othervalues    = deserializer.FromField <ManageableUnstructuredMarketDataSnapshot>(ffc.GetByName("otherValues"));
            var strikesMessage = ffc.GetMessage("strikes");

            Dictionary <Pair <Tenor, Tenor>, ValueSnapshot> strikes;

            if (strikesMessage == null)
            {
                strikes = new Dictionary <Pair <Tenor, Tenor>, ValueSnapshot>();
            }
            else
            {
                strikes = MapBuilder.FromFudgeMsg(strikesMessage, DeserializeKey, deserializer.FromField <ValueSnapshot>);
            }
            return(new ManageableVolatilityCubeSnapshot(values, othervalues, strikes));
        }
        private ComponentRepository GetComponentRepository(IFudgeFieldContainer configMsg)
        {
            var componentInfos = new Dictionary <ComponentKey, ComponentInfo>();

            foreach (var userDataField in configMsg.GetMessage("infos"))
            {
                if (!(userDataField.Value is IFudgeFieldContainer))
                {
                    continue;
                }

                var component    = (IFudgeFieldContainer)userDataField.Value;
                var uri          = new Uri(_rootUri, component.GetString("uri"));
                var componentKey = new ComponentKey(component.GetString("type"), component.GetString("classifier"));
                Dictionary <string, string> attributes = component.GetMessage("attributes").ToDictionary(f => f.Name, f => (string)f.Value);
                componentInfos.Add(componentKey, new ComponentInfo(componentKey, uri, attributes));
            }
            return(new ComponentRepository(componentInfos));
        }
 private static HashSet <T> DeserializeSet <T>(IFudgeDeserializer deserializer, IFudgeFieldContainer ffc, string fieldName) where T : class
 {
     return(new HashSet <T>(ffc.GetMessage(fieldName).GetAllByOrdinal(1).Select(deserializer.FromField <T>)));
 }
        public static ManageableVolatilitySurfaceSnapshot FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var values = MapBuilder.FromFudgeMsg <Pair <object, object>, ValueSnapshot>(ffc.GetMessage("values"), deserializer);

            return(new ManageableVolatilitySurfaceSnapshot(values));
        }
        public override DoubleLabelledMatrix2D DeserializeImpl(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            string xTitle      = ffc.GetString("xTitle");
            string yTitle      = ffc.GetString("yTitle");
            string valuesTitle = ffc.GetString("valuesTitle");

            IFudgeFieldContainer msg = ffc.GetMessage(MatrixField);

            var xLabelTypes  = new Queue <string>();
            var xLabelValues = new Queue <IFudgeField>();
            var yLabelTypes  = new Queue <string>();
            var yLabelValues = new Queue <IFudgeField>();

            var xKeys   = new List <double>();
            var xLabels = new List <object>();
            var yKeys   = new List <double>();
            var yLabels = new List <object>();
            var values  = new List <List <double> >();

            bool newRow = true;
            int  count  = -1;

            foreach (var field in msg)
            {
                switch (field.Ordinal)
                {
                case XLabelTypeOrdinal:
                    xLabelTypes.Enqueue((string)field.Value);
                    break;

                case XKeyOrdinal:
                    xKeys.Add((double)field.Value);
                    break;

                case XLabelOrdinal:
                    xLabelValues.Enqueue(field);
                    break;

                case YLabelTypeOrdinal:
                    newRow = true;
                    count++;
                    yLabelTypes.Enqueue((string)field.Value);
                    break;

                case YKeyOrdinal:
                    yKeys.Add((double)field.Value);
                    break;

                case YLabelOrdinal:
                    yLabelValues.Enqueue(field);
                    break;

                case ValueOrdinal:
                    var value = (double)field.Value;
                    if (newRow)
                    {
                        var row = new List <double> {
                            value
                        };
                        values.Add(row);
                        newRow = false;
                    }
                    else
                    {
                        values[count].Add(value);
                    }
                    break;
                }

                var typeMap = (IFudgeTypeMappingStrategy)deserializer.Context.GetProperty(ContextProperties.TypeMappingStrategyProperty);
                if (xLabelTypes.Any() && xLabelValues.Any())
                {
                    // Have a type and a value, which can be consumed
                    string      labelType  = xLabelTypes.Dequeue();
                    IFudgeField labelValue = xLabelValues.Dequeue();

                    object label = Deserialize(deserializer, typeMap, labelType, labelValue);
                    xLabels.Add(label);
                }
                if (yLabelTypes.Any() && yLabelValues.Any())
                {
                    // Have a type and a value, which can be consumed
                    string      labelType  = yLabelTypes.Dequeue();
                    IFudgeField labelValue = yLabelValues.Dequeue();

                    object label = Deserialize(deserializer, typeMap, labelType, labelValue);
                    yLabels.Add(label);
                }
            }
            int matrixRowSize    = yKeys.Count;
            int matrixColumnSize = xKeys.Count;
            var xKeysArray       = new double[matrixColumnSize];
            var xLabelsArray     = new object[matrixColumnSize];
            var yKeysArray       = new double[matrixRowSize];
            var yLabelsArray     = new object[matrixRowSize];

            var valuesArray = new double[matrixRowSize][];

            for (int i = 0; i < matrixRowSize; i++)
            {
                yKeysArray[i]   = yKeys[i];
                yLabelsArray[i] = yLabels[i];
                for (int j = 0; j < matrixColumnSize; j++)
                {
                    if (i == 0)
                    {
                        xKeysArray[j]   = xKeys[j];
                        xLabelsArray[j] = xLabels[j];
                    }
                    if (valuesArray[i] == null)
                    {
                        valuesArray[i] = new double[matrixColumnSize];
                    }
                    valuesArray[i][j] = values[i][j];
                }
            }
            return(new DoubleLabelledMatrix2D(xKeysArray, yKeysArray, xLabelsArray, yLabelsArray, valuesArray, xTitle, yTitle, valuesTitle));
        }
Exemple #17
0
 public static VolatilityCubeDefinition FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
 {
     return new VolatilityCubeDefinition(
         deserializer.FromField<List<string>>(ffc.GetByName("swapTenors")).Select(s => new Tenor(s)).ToList(),
         deserializer.FromField<List<string>>(ffc.GetByName("optionExpiries")).Select(s => new Tenor(s)).ToList(),
         ffc.GetMessage("relativeStrikes").Select(f => f.Value).Cast<double>().ToList()
         );
 }
        public override TMatrix DeserializeImpl(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            string labelsTitle = ffc.GetString("labelsTitle");
            string valuesTitle = ffc.GetString("valuesTitle");

            var msg = ffc.GetMessage(MatrixField);

            var labelTypes  = new Queue <string>();
            var labelValues = new Queue <IFudgeField>();

            IList <TKey>   keys   = new List <TKey>();
            IList <object> labels = new List <object>();
            IList <double> values = new List <double>();

            foreach (IFudgeField field in msg)
            {
                switch (field.Ordinal)
                {
                case LabelTypeOrdinal:
                    labelTypes.Enqueue((string)field.Value);
                    break;

                case KeyOrdinal:
                    TKey key = GetKey(field);
                    keys.Add(key);
                    break;

                case LabelOrdinal:
                    labelValues.Enqueue(field);
                    break;

                case ValueOrdinal:
                    values.Add((double)field.Value);
                    break;
                }

                if (labelTypes.Count != 0 && labelValues.Count != 0)
                {
                    // Have a type and a value, which can be consumed
                    string      labelTypeName = labelTypes.Dequeue();
                    IFudgeField labelValue    = labelValues.Dequeue();

                    switch (labelTypeName)
                    {
                    case "java.lang.String":
                        var value = (string)labelValue.Value;
                        labels.Add(value);
                        break;

                    case "com.opengamma.util.time.Tenor":
                        //TODO DOTNET-14 this is serialized as a string here
                        string period = (string)labelValue.Value;
                        labels.Add(new Tenor(period));
                        break;

                    case "com.opengamma.util.money.Currency":
                        string iso = (string)labelValue.Value;
                        labels.Add(Currency.Create(iso));
                        break;

                    case "com.opengamma.id.ExternalId":
                        string str = (string)labelValue.Value;
                        labels.Add(ExternalId.Parse(str));
                        break;

                    default:
                        //TODO work out whether this is right (and fast enough) in the general case
                        var typeMapper =
                            (IFudgeTypeMappingStrategy)
                            Context.GetProperty(ContextProperties.TypeMappingStrategyProperty);
                        Type labelType = typeMapper.GetType(labelTypeName);

                        object label = deserializer.FromField(labelValue, labelType);
                        labels.Add(label);
                        break;
                    }
                }
            }

            var constructorInfo = typeof(TMatrix).GetConstructor(new[]
            {
                typeof(IList <TKey>),
                typeof(IList <object>),                                                         //TODO type up this (if the java side does)
                typeof(IList <double>),
                typeof(string),
                typeof(string),
            });

            return((TMatrix)constructorInfo.Invoke(new object[] { keys, labels, values, labelsTitle, valuesTitle }));
        }
 public override ComputationCacheResponse DeserializeImpl(IFudgeFieldContainer msg, IFudgeDeserializer deserializer)
 {
     return(new ComputationCacheResponse(msg.GetMessage("results").Select(f => GetValue(f, deserializer)).ToList()));
 }
        public static SnapshotDataBundle FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var map = MapBuilder.FromFudgeMsg(ffc.GetMessage("dataPoints"), f => UniqueId.Parse((string)f.Value), f => (double)f.Value);

            return(new SnapshotDataBundle(map));
        }
Exemple #21
0
        public override T DeserializeImpl(IFudgeFieldContainer msg, IFudgeDeserializer deserializer)
        {
            UniqueId viewProcessId = GetUniqueId(msg, "viewProcessId");
            UniqueId viewCycleId   = GetUniqueId(msg, "viewCycleId");

            var      inputDataTimestamp  = GetToDateTimeOffsetWithDefault(msg, "valuationTime");
            var      resultTimestamp     = GetToDateTimeOffsetWithDefault(msg, "calculationTime");
            TimeSpan calculationDuration = DurationBuilder.Build(msg.GetMessage("calculationDuration")).GetValueOrDefault(); //TODO strict once PLAT-1683
            var      configurationMap    = new Dictionary <string, ViewCalculationResultModel>();
            var      keys   = new Queue <string>();
            var      values = new Queue <ViewCalculationResultModel>();

            foreach (var field in msg.GetMessage("results"))
            {
                switch (field.Ordinal)
                {
                case 1:
                    string key = field.GetString();
                    if (!values.Any())
                    {
                        keys.Enqueue(key);
                    }
                    else
                    {
                        configurationMap.Add(key, values.Dequeue());
                    }
                    break;

                case 2:
                    var mapAll = new Dictionary <ComputationTargetSpecification, ISet <ComputedValue> >();

                    foreach (var f in (IFudgeFieldContainer)field.Value)
                    {
                        var v = deserializer.FromField <ComputedValue>(f);

                        ComputationTargetSpecification target = v.Specification.TargetSpecification;

                        if (!mapAll.ContainsKey(target))
                        {
                            mapAll.Add(target, new HashSet <ComputedValue>());
                        }
                        mapAll[target].Add(v);
                    }

                    var value = new ViewCalculationResultModel(mapAll);

                    if (!keys.Any())
                    {
                        values.Enqueue(value);
                    }
                    else
                    {
                        configurationMap.Add(keys.Dequeue(), value);
                    }
                    break;

                default:
                    throw new ArgumentException();
                }
            }

            return(BuildObject(msg, deserializer, configurationMap, viewProcessId, viewCycleId, inputDataTimestamp, resultTimestamp, calculationDuration));
        }
        public override ValueProperties DeserializeImpl(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var withoutMessage = ffc.GetMessage("without");

            if (withoutMessage != null)
            {
                if (withoutMessage.Any())
                {
                    var without    = withoutMessage.Select(f => f.Value).Cast <string>();
                    var withoutSet = SmallSet <string> .Create(without);

                    return(new NearlyInfiniteValueProperties(withoutSet));
                }
                else
                {
                    return(InfiniteValueProperties.Instance);
                }
            }

            var withMessage = ffc.GetMessage("with");

            if (withMessage == null)
            {
                return(EmptyValueProperties.Instance);
            }

            var properties            = new Dictionary <string, ISet <string> >(withMessage.GetNumFields());
            HashSet <string> optional = null;

            foreach (var field in withMessage)
            {
                var name = string.Intern(field.Name); // Should be a small static set

                var fieldType = field.Type;
                if (Equals(fieldType, StringFieldType.Instance))
                {
                    var value = (string)field.Value;
                    properties.Add(name, SmallSet <string> .Create(value));
                }
                else if (Equals(fieldType, IndicatorFieldType.Instance))
                {
                    //withAny
                    properties.Add(name, new HashSet <string>());
                }
                else if (Equals(fieldType, FudgeMsgFieldType.Instance))
                {
                    var propMessage = (IFudgeFieldContainer)field.Value;
                    var hashSet     = new HashSet <string>();
                    foreach (var fudgeField in propMessage)
                    {
                        if (fudgeField.Value == IndicatorType.Instance)
                        {
                            if (fudgeField.Name != "optional")
                            {
                                throw new ArgumentException();
                            }
                            optional = optional ?? new HashSet <string>();
                            optional.Add(name);
                        }
                        else
                        {
                            string value = (string)fudgeField.Value;
                            hashSet.Add(value);
                        }
                    }
                    if (hashSet.Any())
                    {
                        properties.Add(name, hashSet);
                    }
                }
            }

            return(new FiniteValueProperties(properties, optional == null ? null : SmallSet <string> .Create(optional)));
        }
Exemple #23
0
 public static SnapshotDataBundle FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
 {
     var map = MapBuilder.FromFudgeMsg(ffc.GetMessage("dataPoints"), f => UniqueId.Parse((string)f.Value), f => (double)f.Value);
     return new SnapshotDataBundle(map);
 }