/// <summary> /// Maps from decimal price units to a other types, mainly for display purposes.. /// </summary> /// <param name="toQuote">The basic quotation to be mapped to ie de-normalised.</param> /// <param name="convertFromType">The type to convert from: only implemented for decimals.</param> /// <returns></returns> public static BasicQuotation DeNormalisePriceUnits(BasicQuotation toQuote, string convertFromType) { const string rateQuotationType = PriceableSimpleRateAsset.RateQuotationType; if (toQuote.measureType.Value != rateQuotationType || (convertFromType != "DecimalRate" && convertFromType != "DecimalValue")) { return(BasicQuotationHelper.Clone(toQuote)); } switch (toQuote.quoteUnits.Value) { case "IRFuturesPrice": //Format for this is 9500. { return(BasicQuotationHelper.Create(100 - toQuote.value * 100, rateQuotationType, toQuote.quoteUnits.Value)); } case "Volatility": //Format for this is 7.00 { return(BasicQuotationHelper.Create(toQuote.value * 100, rateQuotationType, toQuote.quoteUnits.Value)); } case "Rate": //Format for this is 7.00 { return(BasicQuotationHelper.Create(toQuote.value * 100, rateQuotationType, toQuote.quoteUnits.Value)); } case "DecimalValue": case "DecimalVolatility": case "LognormalVolatility": case "NormalVolatility": case "DecimalRate": //Format is .07 { return(BasicQuotationHelper.Create(toQuote.value, rateQuotationType, toQuote.quoteUnits.Value)); } case "DecimalSpread": //Format is .07 { return(BasicQuotationHelper.Create(toQuote.value, rateQuotationType, toQuote.quoteUnits.Value)); } case "FuturesPrice": //Format is 95.00 { return(BasicQuotationHelper.Create(100 - toQuote.value * 100, rateQuotationType, toQuote.quoteUnits.Value)); } case "Premium": case "DirtyPrice": case "Price": //Format is in units. { return(BasicQuotationHelper.Create(toQuote.value, rateQuotationType, toQuote.quoteUnits.Value)); } case "ForwardValue": //Format is in units. { return(BasicQuotationHelper.Create(toQuote.value, rateQuotationType, toQuote.quoteUnits.Value)); } case "FxRate": //Format is in units. { return(BasicQuotationHelper.Create(toQuote.value, rateQuotationType, toQuote.quoteUnits.Value)); } default: { return(BasicQuotationHelper.Create(toQuote.value, rateQuotationType, toQuote.quoteUnits.Value)); } } }
/// <summary> /// Maps from price units other than decimals, to a decimal for consumption primarily by a rate curve. /// </summary> /// <param name="rateQuotationType">The rate quotation type. eg MarketQuote, Spread or Volatility.</param> /// <param name="fromQuote">The basic quotation to be mapped from ie normalised.</param> /// <param name="convertToType">The type to convert to: only implemented for decimals.</param> /// <returns></returns> public static BasicQuotation NormaliseGeneralPriceUnits(String rateQuotationType, BasicQuotation fromQuote, String convertToType) { if (fromQuote.measureType.Value != "MarketQuote" || convertToType != "DecimalRate" && convertToType != "DecimalValue") { return(BasicQuotationHelper.Clone(fromQuote)); } switch (fromQuote.quoteUnits.Value) { case "IRFuturesPrice": //Format for this is 9500. { return(BasicQuotationHelper.Create((100 - fromQuote.value) / 100, rateQuotationType, convertToType)); } case "Volatility": //Format for this is 7.00 { return(BasicQuotationHelper.Create(fromQuote.value / 100, rateQuotationType, convertToType)); } case "Rate": //Format for this is 7.00 { return(BasicQuotationHelper.Create(fromQuote.value / 100, rateQuotationType, convertToType)); } case "DecimalValue": case "DecimalVolatility": case "LognormalVolatility": case "NormalVolatility": case "DecimalRate": //Format is .07 { return(BasicQuotationHelper.Create(fromQuote.value, rateQuotationType, convertToType)); } case "DecimalSpread": //Format is .07 { return(BasicQuotationHelper.Create(fromQuote.value, rateQuotationType, convertToType)); } case "FuturesPrice": //Format is 95.00 { return(BasicQuotationHelper.Create((100 - fromQuote.value) / 100, rateQuotationType, convertToType)); } case "Premium": case "DirtyPrice": case "Price": //Format is .07 { return(BasicQuotationHelper.Create(fromQuote.value, rateQuotationType, convertToType)); } case "ForwardValue": //Format is .07 { return(BasicQuotationHelper.Create(fromQuote.value, rateQuotationType, convertToType)); } case "FxRate": //Format is in units. { return(BasicQuotationHelper.Create(fromQuote.value, rateQuotationType, convertToType)); } default: { return(BasicQuotationHelper.Create(fromQuote.value, rateQuotationType, convertToType)); } } }
protected RequestContext ConvertStandardAssetQuotesToProviderInstrFieldCodes( MDSRequestType requestType, QuotedAssetSet standardQuotedAssetSet) { // extract assets/quotes that require market quotes var standardAssets = new List <Asset>(); var standardQuotes = new List <BasicQuotation>(); { // build a request/response map (indexed by instrument id) var instrumentMap = new Dictionary <string, Asset>(); //List<Pair<Asset, BasicQuotation>> completeAssetQuotes = new List<Pair<Asset, BasicQuotation>>(); foreach (Asset asset in standardQuotedAssetSet.instrumentSet.Items) { instrumentMap[asset.id.ToLower()] = asset; } foreach (BasicAssetValuation quoteInstr in standardQuotedAssetSet.assetQuote) { string instrId = quoteInstr.objectReference.href; if (!instrumentMap.TryGetValue(instrId.ToLower(), out var asset)) { throw new ApplicationException($"Cannot find instrument '{instrId}' for assetQuote"); } foreach (BasicQuotation quoteField in quoteInstr.quote) { if (quoteField.valueSpecified) { // value provided - don't get from market //completeAssetQuotes.Add(new Pair<Asset, BasicQuotation>(asset, quoteField)); } else { // value not supplied - get from market BasicQuotation quote = BasicQuotationHelper.Clone(quoteField); standardAssets.Add(asset); standardQuotes.Add(quote); } } } } var requestItems = new List <RequestItem>(); var instrConversionMap = new Dictionary <string, string>(); var instrUniquenessMap = new Dictionary <string, string>(); var internalInstrIds = new List <string>(); var fieldConversionMap = new Dictionary <string, string>(); var fieldUniquenessMap = new Dictionary <string, string>(); var internalFieldIds = new List <string>(); Logger.LogDebug(" Mappings :"); for (int i = 0; i < standardAssets.Count; i++) { // map asset to provider instrument id Asset standardAsset = standardAssets[i]; string internalInstrId = standardAsset.id; internalInstrIds.Add(internalInstrId); string providerInstrId = _marketDataMap.Convert( MDSDictionaryType.Instrument, requestType, MDSProviderId.GlobalIB, ProviderId, internalInstrId, ConvertFailMode.ThrowException); // update 1-way map instrConversionMap[internalInstrId.ToLower()] = providerInstrId; instrUniquenessMap[providerInstrId.ToLower()] = providerInstrId; // map quote to provider field name BasicQuotation standardQuote = standardQuotes[i]; string internalFieldId = standardQuote.GetStandardFieldName(); internalFieldIds.Add(internalFieldId); string providerFieldId = _marketDataMap.Convert( MDSDictionaryType.FieldName, requestType, MDSProviderId.GlobalIB, ProviderId, internalFieldId, ConvertFailMode.ThrowException); // update 1-way map fieldConversionMap[internalFieldId.ToLower()] = providerFieldId; fieldUniquenessMap[providerFieldId.ToLower()] = providerFieldId; // get provider units string providerUnitsId = _marketDataMap.Convert( MDSDictionaryType.QuoteUnits, requestType, MDSProviderId.GlobalIB, ProviderId, String.Format("{0}/{1}", internalInstrId, internalFieldId), ConvertFailMode.ThrowException); var requestItem = new RequestItem { StandardAsset = standardAsset, StandardQuote = standardQuote, StandardUnits = PriceQuoteUnitsScheme.ParseEnumString(standardQuote.quoteUnits.Value), ProviderInstrumentId = providerInstrId, ProviderFieldName = providerFieldId, ProviderUnits = PriceQuoteUnitsScheme.ParseEnumString(providerUnitsId) }; requestItems.Add(requestItem); // debug Logger.LogDebug(" [{0}] '{1}/{2}' ({3}) --> '{4}/{5}' ({6})", i, internalInstrIds[i], internalFieldIds[i], standardQuote.quoteUnits.Value, instrConversionMap[internalInstrIds[i].ToLower()], fieldConversionMap[internalFieldIds[i].ToLower()], providerUnitsId); // end debug } var providerInstrIds = new List <string>(instrUniquenessMap.Values); var providerFieldIds = new List <string>(fieldUniquenessMap.Values); // build provider instr/field code sets - todo - for now just build 1 var results = new List <ProviderInstrFieldCodeSet>(); var result = new ProviderInstrFieldCodeSet(providerInstrIds, providerFieldIds); results.Add(result); return(new RequestContext { RequestItems = requestItems, ProviderInstrFieldCodeSets = results, InstrConversionMap = instrConversionMap, FieldConversionMap = fieldConversionMap }); }