示例#1
0
        /// <summary>
        /// Creates a QuotedAssetSet from a set of instrument ids and sides, all with measureType set to MarketQuote
        /// and QuoteUnits set to DecimalRate (useful for building market data requests).
        /// </summary>
        /// <param name="instrIds">The (m) instrument ids.</param>
        /// <param name="sides">The (n) sides.</param>
        /// <returns>An M * N matrix of assets/quotes in a QuotedAssetSet</returns>
        public static QuotedAssetSet Parse(string[] instrIds, string[] sides)
        {
            var assetList = new List <Asset>();
            var quoteList = new List <BasicAssetValuation>();

            foreach (string instrId in instrIds)
            {
                Asset asset = CreateAsset(instrId);
                assetList.Add(asset);
                foreach (string side in sides)
                {
                    BasicQuotation quote = BasicQuotationHelper.Create("MarketQuote", "DecimalRate", side);
                    quoteList.Add(new BasicAssetValuation
                    {
                        objectReference = new AnyAssetReference {
                            href = asset.id
                        },
                        quote = new[] { quote }
                    });
                }
            }
            return(new QuotedAssetSet
            {
                instrumentSet = assetList.ToArray(),
                assetQuote = quoteList.ToArray()
            });
        }
示例#2
0
        protected List <BasicAssetValuation> ConvertProviderResultsToStandardValuations(
            Dictionary <string, BasicQuotation> providerResults,
            RequestContext requestContext)
        {
            var results = new List <BasicAssetValuation>();

            // build standard results (and convert quote units)
            Logger.LogDebug("    Results     :");
            for (int i = 0; i < requestContext.RequestItems.Count; i++)
            {
                RequestItem         requestItem       = requestContext.RequestItems[i];
                Asset               standardAsset     = requestItem.StandardAsset;
                BasicQuotation      standardQuote     = requestItem.StandardQuote;
                string              standardInstrId   = standardAsset.id;
                string              standardFieldId   = standardQuote.GetStandardFieldName();
                PriceQuoteUnitsEnum standardQuoteUnit = requestItem.StandardUnits;
                PriceQuoteUnitsEnum providerQuoteUnit = requestItem.ProviderUnits;
                string              providerInstrId   = requestContext.InstrConversionMap[standardInstrId.ToLower()];
                string              providerFieldId   = requestContext.FieldConversionMap[standardFieldId.ToLower()];
                string              providerQuoteKey  = FormatProviderQuoteKey(providerInstrId, providerFieldId);
                if (providerResults.TryGetValue(providerQuoteKey, out var providerQuote))
                {
                    BasicQuotation convertedQuote;
                    if (providerQuote.valueSpecified)
                    {
                        // valid value returned
                        decimal convertedValue = PriceQuoteUnitsHelper.ConvertPriceQuoteUnitsValue(providerQuoteUnit, standardQuoteUnit, providerQuote.value);
                        convertedQuote = BasicQuotationHelper.Create(standardQuote, convertedValue);
                        // debug
                        Logger.LogDebug("      [{0}] '{1}/{2}' ({3}/{4}) [{5}] --> '{6}/{7}' ({8}/{9}) [{10}]", i,
                                        providerInstrId, providerFieldId, AssetMeasureEnum.MarketQuote, providerQuoteUnit, providerQuote.value,
                                        standardInstrId, standardFieldId, AssetMeasureEnum.MarketQuote, standardQuoteUnit, convertedQuote.value);
                        // end debug
                    }
                    else
                    {
                        // no value - copy error details
                        convertedQuote = providerQuote;
                        // debug
                        Logger.LogDebug("      [{0}] '{1}/{2}' ({3}/{4}) [{5}] --> '{6}/{7}' ({8}/{9}) [{10}]", i,
                                        providerInstrId, providerFieldId, providerQuote.measureType.Value, providerQuote.quoteUnits.Value, providerQuote.value,
                                        standardInstrId, standardFieldId, convertedQuote.measureType.Value, convertedQuote.quoteUnits.Value, convertedQuote.value);
                        // end debug
                    }
                    // add other provider info
                    convertedQuote.timeSpecified          = providerQuote.timeSpecified;
                    convertedQuote.time                   = providerQuote.time;
                    convertedQuote.valuationDateSpecified = providerQuote.valuationDateSpecified;
                    convertedQuote.valuationDate          = providerQuote.valuationDate;
                    convertedQuote.informationSource      = providerQuote.informationSource;
                    results.Add(new BasicAssetValuation {
                        objectReference = new AnyAssetReference {
                            href = standardAsset.id
                        },
                        quote = new[] { convertedQuote }
                    });
                }
            }
            return(results);
        }
        /// <summary>
        /// Creates a QuotedAssetSet from a set of instrument ids and sides, all with measureType set to MarketQuote
        /// and QuoteUnits set to DecimalRate (useful for building market data requests).
        /// </summary>
        /// <param name="instrIds">The (m) instrument ids.</param>
        /// <param name="sides">The (n) sides.</param>
        /// <returns>An M * N matrix of assets/quotes in a QuotedAssetSet</returns>
        public static QuotedAssetSet Parse(string[] instrIds, string[] sides)
        {
            var assetList = new List <Asset>();
            var quoteList = new List <BasicAssetValuation>();
            var types     = new List <ItemsChoiceType19>();

            foreach (string instrId in instrIds)
            {
                Asset asset = CreateAsset(instrId);
                assetList.Add(asset);
                quoteList.AddRange(sides.Select(side => BasicQuotationHelper.Create("MarketQuote", "DecimalRate", side)).Select(quote => new BasicAssetValuation
                {
                    objectReference = new AnyAssetReference {
                        href = asset.id
                    }, quote = new[] { quote }
                }));
                var properties    = new PriceableAssetProperties(asset.id);
                var assetTypeFpML = AssetTypeConvertor.ParseEnumStringToFpML(properties.AssetType.ToString());
                types.Add(assetTypeFpML);
            }
            var instrumentSet = new InstrumentSet {
                Items = assetList.ToArray(), ItemsElementName = types.ToArray()
            };

            return(new QuotedAssetSet
            {
                instrumentSet = instrumentSet,
                assetQuote = quoteList.ToArray()
            });
        }
        /// <summary>//TODO set the quote side enum.
        /// Finds the spread, if it exists, and add to the market quote. Otherwise returns 0.
        /// </summary>
        /// <param name="quotations">The quotations.</param>
        /// <returns></returns>
        public static BasicQuotation[] MarketQuoteRemoveSpreadAndNormalise(List <BasicQuotation> quotations)
        {
            //Get the market quote.
            var normalisedValue = BasicQuotationHelper.Create(0.0m, "MarketQuote", "DecimalRate");
            var value           = FindQuotationByMeasureType("MarketQuote", quotations);

            if (value != null)
            {
                normalisedValue = NormalisePriceUnits(value, "DecimalRate");
            }
            //Get the spread.
            var quote       = FindQuotationByMeasureType("Spread", quotations);
            var spreadValue = 0.0m;

            if (quote != null)
            {
                //This is to remove evidence of the spread.
                BasicQuotation normalisedspread = NormalisePriceUnits(quote, "DecimalRate");
                spreadValue = normalisedspread.value;
                ReplaceQuotationByMeasureType("Spread", quotations, 0.0m);
            }
            //return the sum.
            normalisedValue.value = normalisedValue.value + spreadValue;
            ReplaceQuotationByMeasureType("MarketQuote", quotations, normalisedValue.value);
            return(quotations.ToArray());
        }
示例#5
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> ParseSurface(string instrumentId, decimal value)
        {
            const string rateQuotationType = PriceableCapRateAsset.VolatilityQuotationType;
            SimpleFra    underlyingAsset;
            var          results             = instrumentId.Split('-');
            var          instrument          = results[1];
            var          listBasicQuotations = new List <BasicQuotation>();
            var          asset = EnumHelper.Parse <AssetTypesEnum>(instrument);

            switch (asset)
            {
            case AssetTypesEnum.BillCaplet:
            case AssetTypesEnum.BillFloorlet:
            case AssetTypesEnum.Floorlet:
            case AssetTypesEnum.Caplet:
            {
                var index = results[3];
                underlyingAsset = new SimpleFra {
                    id = instrumentId, startTerm = PeriodHelper.Parse(results[2])
                };
                underlyingAsset.endTerm
                    = underlyingAsset.startTerm.Sum(PeriodHelper.Parse(index));
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalVolatility"));
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {instrument} is not supported");
            }
            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray())));
        }
示例#6
0
        /// <summary>
        /// Parses the assetIdentifiers.
        /// </summary>
        /// <param name="assetIdentifiers"></param>
        /// <param name="values"></param>
        /// <param name="adjustments"></param>
        /// <returns></returns>
        public static FxRateSet ParseToFxRateSet(string[] assetIdentifiers, decimal[] values, decimal[] adjustments)
        {
            if (assetIdentifiers.Length != values.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(values), "the rates do not match the number of assets");
            }
            if (adjustments != null && assetIdentifiers.Length != adjustments.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(values), "the rates do not match the number of assets");
            }
            var          quotedAssetSetFactory = new QuotedAssetSetFactory();
            const string rateQuotationType     = PriceableCommoditySpot.RateQuotationType;
            int          index = 0;

            foreach (string assetIdentifier in assetIdentifiers)
            {
                var bav
                    = new BasicAssetValuation
                    {
                    objectReference = new AnyAssetReference {
                        href = assetIdentifier
                    }
                    };
                var addOn = adjustments?[index] ?? 0.0m;
                var bqs   = new List <BasicQuotation>
                {
                    BasicQuotationHelper.Create(values[index] + addOn, rateQuotationType, "DecimalRate")
                };
                bav.quote = bqs.ToArray();
                quotedAssetSetFactory.AddAssetAndQuotes(Parse(assetIdentifier), bav);
                index++;
            }
            return(quotedAssetSetFactory.CreateFxRateSet());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableSimpleRateAsset"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="amount">The amount.</param>
 /// <param name="effectiveDate">The effective date.</param>
 /// <param name="riskMaturityDate">The risk maturity date.</param>
 protected PriceableSimpleRateAsset(string id, Decimal amount, DateTime effectiveDate, DateTime riskMaturityDate)
 {
     Notional        = amount;
     ModelIdentifier = "SimpleAsset";
     Id = id;
     AdjustedStartDate = effectiveDate;
     RiskMaturityDate  = riskMaturityDate;
     MarketQuote       = BasicQuotationHelper.Create(0.0m, "Spread", "DecimalRate");
 }
示例#8
0
        /////<summary>
        /////</summary>
        /////<returns></returns>
        //public decimal GetSpotRate()
        //{
        //    var fxVal = (FxCurveValuation)GetFpMLData().Second;
        //    BasicAssetValuation spotRateAsset = (from spotRateAssets in fxVal.spotRate.assetQuote
        //                                         where spotRateAssets.objectReference.href.EndsWith("-Equity-SP", StringComparison.InvariantCultureIgnoreCase)//TODO FIX This!
        //                                         select spotRateAssets).Single();
        //    decimal spotRate = spotRateAsset.quote[0].value;
        //    return spotRate;
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace">THe client namespace</param>
        /// <param name="equityId">THe curve asset.</param>
        /// <param name="fixingCalendar"></param>
        /// <param name="rollCalendar"></param>
        /// <param name="baseDate"></param>
        /// <returns></returns>
        protected static DateTime GetSettlementDate(ILogger logger, ICoreCache cache, string nameSpace,
                                                    EquityCurveIdentifier equityId, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar, DateTime baseDate)
        {
            BasicAssetValuation bav = BasicAssetValuationHelper.Create(BasicQuotationHelper.Create(0, "MarketQuote", PriceQuoteUnitsEnum.Price.ToString()));
            var assetId             = BuildSpotAssetId(equityId);
            var priceableAsset      = (IPriceableEquityAssetController)PriceableAssetFactory.Create(logger, cache, nameSpace, assetId, baseDate, bav, fixingCalendar, rollCalendar);

            return(priceableAsset.GetRiskMaturityDate());
        }
        /// <summary>
        /// Finds the spread, if it exists, and add to the market quote. Otherwise returns 0.
        /// </summary>
        /// <param name="measureType">Type of the measure.</param>
        /// <param name="quotations">The quotations.</param>
        /// <returns></returns>
        public static BasicQuotation GetMarketQuoteAndNormalise(string measureType, IList <BasicQuotation> quotations)
        {
            //Get the market quote.
            var normalisedValue = BasicQuotationHelper.Create(0.0m, measureType, "DecimalRate");
            var value           = FindQuotationByMeasureType(measureType, quotations);

            if (value != null)
            {
                normalisedValue = NormalisePriceUnits(value, "DecimalRate");
            }
            return(normalisedValue);
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="rollCalendar"></param>
        /// <param name="baseDate"></param>
        /// <returns></returns>
        public DateTime GetSpotDate(ILogger logger, ICoreCache cache, string nameSpace,
                                    IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar, DateTime baseDate)
        {
            BasicAssetValuation bav = BasicAssetValuationHelper.Create(BasicQuotationHelper.Create(0, "MarketQuote"));
            string identifier       = Currency1 + Currency2 + "-FxSpot-SP";//Currency2 would normally be USD.
            var    priceableAsset   = (IPriceableFxAssetController)PriceableAssetFactory.Create(logger, cache, nameSpace, identifier, baseDate, bav, fixingCalendar, rollCalendar);

            if (priceableAsset != null)
            {
                return(priceableAsset.GetRiskMaturityDate());
            }
            return(FxCurve1.GetSpotDate());//TODO Default to the first curve. Should merge the two!
        }
示例#11
0
        static public IAssetControllerData CreateModelData(string[] metrics, DateTime baseDate, IMarketEnvironment market)
        {
            var bav = new BasicAssetValuation();

            var quotes = new BasicQuotation[metrics.Length];
            var index  = 0;

            foreach (var metric in metrics)
            {
                quotes[index] = BasicQuotationHelper.Create(0.0m, metric);
                index++;
            }
            bav.quote = quotes;
            return(new AssetControllerData(bav, baseDate, market));
        }
示例#12
0
        /// <summary>
        /// Sets the rate.
        /// </summary>
        /// <param name="bq">The spread.</param>
        private static BasicQuotation GetSpread(BasicQuotation bq)
        {
            BasicQuotation spread;

            if (String.Compare(bq.measureType.Value, "MarketQuote", StringComparison.OrdinalIgnoreCase) == 0)
            {
                spread       = BasicQuotationHelper.Create("Spread", bq.quoteUnits.Value);
                spread.value = bq.value;
            }
            else
            {
                throw new ArgumentException("Quotation must be of type {0}", RateQuotationType);
            }
            return(spread.measureType.Value == "Spread" ? spread : null);
        }
示例#13
0
        /// <summary>
        /// Creates the specified assets in a quoted asset set.
        /// </summary>
        /// <param name="assetIdentifiers">The asset identifiers.</param>
        /// <param name="values">The adjusted rates.</param>
        /// <param name="measureTypes">The measure types. Currently supports MarketQuote and Volatility.</param>
        /// <param name="priceQuoteUnits">The price quote units. Currently supports Rates and LogNormalVolatility.</param>
        /// <param name="includeMarketQuoteValues">An include flag. If false, then the market quotes are set as null.</param>
        /// <returns></returns>
        public static QuotedAssetSet Parse(string[] assetIdentifiers, Decimal[] values,
                                           String[] measureTypes, String[] priceQuoteUnits, bool includeMarketQuoteValues)
        {
            if (assetIdentifiers.Length != values.Length && assetIdentifiers.Length != priceQuoteUnits.Length && (assetIdentifiers.Length != measureTypes.Length))
            {
                throw new ArgumentOutOfRangeException(nameof(values), "The rates do not match the number of assets");
            }
            var quotedAssetSetFactory = new QuotedAssetSetFactory();

            foreach (string assetIdentifier in assetIdentifiers.Distinct())
            {
                int index = 0;
                var bav
                    = new BasicAssetValuation
                    {
                    objectReference = new AnyAssetReference {
                        href = assetIdentifier
                    }
                    };
                var bqs = new List <BasicQuotation>();
                foreach (string ids in assetIdentifiers)
                {
                    index++;
                    if (ids != assetIdentifier)
                    {
                        continue;
                    }
                    BasicQuotation bq;
                    if (measureTypes[index - 1] == AssetMeasureEnum.MarketQuote.ToString() && !includeMarketQuoteValues)
                    {
                        bq = BasicQuotationHelper.Create(measureTypes[index - 1],
                                                         priceQuoteUnits[index - 1]);
                        bqs.Add(bq);
                    }
                    else
                    {
                        bq = BasicQuotationHelper.Create(values[index - 1], measureTypes[index - 1],
                                                         priceQuoteUnits[index - 1]);
                        bqs.Add(bq);
                    }
                }
                bav.quote = bqs.ToArray();
                quotedAssetSetFactory.AddAssetAndQuotes(Parse(assetIdentifier), bav);
            }
            return(quotedAssetSetFactory.Create());
        }
示例#14
0
        /// <summary>
        /// Replaces the type of the quotation by measure.
        /// </summary>
        /// <param name="measureType">Type of the measure.</param>
        /// <param name="quotations">The quotations.</param>
        /// <param name="value">The value to replace.</param>
        /// <returns></returns>
        public static BasicQuotation[] ReplaceQuotationByMeasureType(string measureType, List <BasicQuotation> quotations, Decimal value)
        {
            var val = quotations.Find(quotationItem => String.Compare(quotationItem.measureType.Value, measureType, StringComparison.OrdinalIgnoreCase) == 0);

            if (val != null)
            {
                var idx =
                    quotations.FindIndex(
                        quotationItem => String.Compare(quotationItem.measureType.Value, measureType, StringComparison.OrdinalIgnoreCase) == 0);
                quotations[idx].value = value;
            }
            else
            {
                var quote = BasicQuotationHelper.Create(value, measureType, "DecimalRate");
                quotations.Add(quote);
            }
            return(quotations.ToArray());
        }
示例#15
0
 /// <summary>
 /// Parses the string info into an asset.
 /// </summary>
 /// <param name="instrumentId"></param>
 /// <param name="value"></param>
 /// <param name="measureType"></param>
 /// <param name="priceQuoteUnits"></param>
 /// <returns></returns>
 public static Pair <Asset, BasicAssetValuation> CreateAssetPair(string instrumentId, decimal[] value, string[] measureType, string[] priceQuoteUnits)
 {
     if (value.Length == priceQuoteUnits.Length && value.Length == measureType.Length)
     {
         var underlyingAsset     = Parse(instrumentId);
         var listBasicQuotations = new List <BasicQuotation>();
         var counter             = 0;
         foreach (var val in value)
         {
             listBasicQuotations.Add(BasicQuotationHelper.Create(val, measureType[counter],
                                                                 priceQuoteUnits[counter]));
             counter++;
         }
         return(new Pair <Asset, BasicAssetValuation>(underlyingAsset,
                                                      BasicAssetValuationHelper.Create(underlyingAsset.id,
                                                                                       listBasicQuotations.ToArray
                                                                                           ())));
     }
     throw new System.Exception("Unequal number of values and priceQuoteUnits.");
 }
示例#16
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="bondTypeId">The type of bond.</param>
        /// <param name="coupon">The coupon rate</param>
        /// <param name="daycount">The daycount.</param>
        /// <param name="frequency">The frequency.</param>
        /// <param name="ytm">The ytm.</param>
        /// <param name="maturityDate">The maturity date.</param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> ParseBond(string bondTypeId, DateTime maturityDate, decimal coupon, string daycount, string frequency, decimal ytm)
        {
            const string rateQuotationType = "MarketQuote";
            var          bondId            = bondTypeId + '-' + coupon + '-' + maturityDate.ToShortDateString();
            var          underlyingAsset   = new Bond
            {
                id                  = bondId,
                maturity            = maturityDate,
                maturitySpecified   = true,
                couponRate          = coupon,
                couponRateSpecified = true,
                dayCountFraction    = DayCountFractionHelper.Parse(daycount),
                paymentFrequency    = PeriodHelper.Parse(frequency)
            };
            var listBasicQuotations = new List <BasicQuotation>
            {
                BasicQuotationHelper.Create(ytm, rateQuotationType, "DecimalRate")
            };

            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray())));
        }
示例#17
0
        /// <summary>//TODO set the quote side enum.
        /// Finds the spread, if it exists, and add to the market quote. Otherwise returns 0.
        /// </summary>
        /// <param name="quotations">The quotations.</param>
        /// <returns></returns>
        public static BasicQuotation GetMarketQuotePriceAddSpreadAndNormalise(IList <BasicQuotation> quotations)
        {
            //Get the market quote.
            var normalisedValue = BasicQuotationHelper.Create(0.0m, "MarketQuote", "Price");
            var value           = FindQuotationByMeasureType("MarketQuote", quotations);

            if (value != null)
            {
                normalisedValue = NormalisePriceUnits(value, "Price");
            }
            //Get the spread.
            var normalisedspread = BasicQuotationHelper.Create(0.0m, "Spread", "Price");
            var quote            = FindQuotationByMeasureType("Spread", quotations);

            if (quote != null)
            {
                normalisedspread = NormalisePriceUnits(quote, "Price");
            }
            //return the sum.
            normalisedValue.value = normalisedValue.value + normalisedspread.value;
            return(normalisedValue);
        }
示例#18
0
        /// <summary>
        /// Gets the spot date relative to the date provided.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace"></param>
        /// <param name="baseDate"></param>
        /// <param name="fixingCalendar"></param>
        /// <param name="rollCalendar"></param>
        /// <returns></returns>
        public DateTime GetSpotDate(ILogger logger, ICoreCache cache, string nameSpace, DateTime baseDate,
                                    IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
        {
            //var bq = BasicQuotationHelper.Create(.79m, "MarketQuote"); no magic constants in code
            var bq  = BasicQuotationHelper.Create(0, "MarketQuote");
            var bav = BasicAssetValuationHelper.Create(bq);
            //var quotedCurrencyPair = commodityCurveId.QuotedCurrencyPair;
            var quotedCurrencyPair = ((FpML.V5r10.Reporting.FxCurve)GetFpMLData().First).quotedCurrencyPair;
            var identifier         = quotedCurrencyPair.currency1.Value + quotedCurrencyPair.currency2.Value + "-CommoditySpot-SP";
            var fxspot             = new FxRateAsset
            {
                id       = identifier,
                currency = new IdentifiedCurrency {
                    Value = quotedCurrencyPair.currency1.Value
                },
                quotedCurrencyPair = quotedCurrencyPair
            };

            var priceableAsset = (IPriceableCommodityAssetController)PriceableAssetFactory.Create(logger, cache, nameSpace, fxspot.id, baseDate, bav, fixingCalendar, rollCalendar);
            var spot           = priceableAsset.GetRiskMaturityDate();

            return(spot);
        }
示例#19
0
        /// <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));
            }
            }
        }
示例#20
0
        /// <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>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="properties"></param>
        /// <param name="expiries"></param>
        /// <param name="vols"></param>
        /// <param name="inputInstruments"></param>
        /// <param name="inputSwapRates"></param>
        /// <param name="inputBlackVolRates"></param>
        protected ExpiryTermStrikeVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, DateTime[] expiries, double[] vols,
                                                    string[] inputInstruments, double[] inputSwapRates, double[] inputBlackVolRates)
        {
            Algorithm = PropertyHelper.ExtractAlgorithm(properties);
            PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties);
            var surfaceId    = (VolatilitySurfaceIdentifier)PricingStructureIdentifier;
            var expiryLength = expiries.Length;
            var pointIndex   = 0;
            var points       = new PricingStructurePoint[expiryLength];

            _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey());
            for (var expiryIndex = 0; expiryIndex < expiryLength; expiryIndex++)
            {
                // extract the current expiry
                var expiryKeyPart = expiries[expiryIndex];
                var key           = new ExpiryTenorStrikeKey(expiryKeyPart.ToString(CultureInfo.InvariantCulture), 0);
                _matrixIndexHelper.Add(key, pointIndex);
                // Add the value to the points array (dataPoints entry in the matrix)
                var coordinates = new PricingDataPointCoordinate[1];
                coordinates[0] = new PricingDataPointCoordinate {
                    expiration = new TimeDimension[1]
                };
                coordinates[0].expiration[0] = new TimeDimension {
                    Items = new object[] { expiries[expiryIndex] }
                };
                var pt = new PricingStructurePoint
                {
                    value          = (decimal)vols[expiryIndex],
                    valueSpecified = true,
                    coordinate     = coordinates,
                };
                points[pointIndex++] = pt;
            }
            // Record the row/column sizes of the inputs
            _matrixRowCount           = expiries.Length;
            _matrixColumnCount        = 1;
            PricingStructure          = CreateVolatilityRepresentation(surfaceId);
            PricingStructureValuation = CreateDataPoints(points, surfaceId);
            if (inputInstruments != null)
            {
                int inputCount  = inputInstruments.GetUpperBound(0);
                var assetQuotes = new List <BasicAssetValuation>();
                var assetSet    = new List <Asset>();
                var itemsList   = new List <ItemsChoiceType19>();
                for (int i = 0; i <= inputCount; i++)
                {
                    var assetProperties = new PriceableAssetProperties(inputInstruments[i]);
                    assetSet.Add(new SimpleIRSwap {
                        id = inputInstruments[i], term = assetProperties.TermTenor
                    });
                    var rateQuote = BasicQuotationHelper.Create((decimal)inputSwapRates[i], AssetMeasureEnum.MarketQuote, PriceQuoteUnitsEnum.DecimalRate);
                    var volQuote  = BasicQuotationHelper.Create((decimal)inputBlackVolRates[i], AssetMeasureEnum.Volatility, PriceQuoteUnitsEnum.LogNormalVolatility);
                    assetQuotes.Add(new BasicAssetValuation
                    {
                        objectReference = new AnyAssetReference {
                            href = inputInstruments[i]
                        },
                        definitionRef = assetProperties.TermTenor.ToString(),
                        quote         = new[] { rateQuote, volQuote }
                    });
                    itemsList.Add(ItemsChoiceType19.simpleIrSwap);//TODO NOt actually correct.
                }
                var instrumentSet = new InstrumentSet {
                    Items = assetSet.ToArray(), ItemsElementName = itemsList.ToArray()
                };
                ((VolatilityMatrix)PricingStructureValuation).inputs
                    = new QuotedAssetSet {
                    assetQuote = assetQuotes.ToArray(), instrumentSet = instrumentSet
                    };
            }
            // Generate an interpolator to use
            double[] expiryTerms = expiries.Select(a => (surfaceId.BaseDate - a).TotalDays / 365d).ToArray();
            var      holder      = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, surfaceId.PricingStructureType, surfaceId.Algorithm);
            var      curveInterpolationMethod = InterpolationMethodHelper.Parse(holder.GetValue("CurveInterpolation"));

            Interpolator = new VolSurfaceInterpolator(expiryTerms, new double[] { 1 }, new Matrix(vols), curveInterpolationMethod, true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="tradeDate"></param>
        /// <param name="settlementDate">The payment settlement date.</param>
        /// <param name="settlementCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <param name="bondFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="bondType"></param>
        /// <param name="forecastRateInterpolation"></param>
        public BondTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate,
                                     DateTime settlementDate, IBusinessCalendar settlementCalendar, IBusinessCalendar paymentCalendar,
                                     BondTransaction bondFpML, string basePartyReference, string bondType, bool forecastRateInterpolation)
        {
            Multiplier = 1.0m;
            TradeDate  = tradeDate;
            BondType   = EnumHelper.Parse <BondTypesEnum>(bondType);
            logger.LogInfo("BondType set. Commence to build a bond transaction.");
            if (bondFpML == null)
            {
                return;
            }
            BuyerReference    = bondFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                bondFpML.notionalAmount.currency.Value
            };
            SellerReference = bondFpML.sellerPartyReference.href;
            BasePartyBuyer  = basePartyReference == bondFpML.buyerPartyReference.href;
            if (!BasePartyBuyer)
            {
                Multiplier = -1.0m;
            }
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            PaymentCalendar           = paymentCalendar;
            //Set the bond price information
            BondPrice = new BondPrice();
            if (bondFpML.price.accrualsSpecified)
            {
                BondPrice.accrualsSpecified = true;
                BondPrice.accruals          = bondFpML.price.accruals;
            }
            if (bondFpML.price.dirtyPriceSpecified)
            {
                BondPrice.dirtyPriceSpecified = true;
                BondPrice.dirtyPrice          = bondFpML.price.dirtyPrice;
            }
            BondPrice.cleanOfAccruedInterest = bondFpML.price.cleanOfAccruedInterest;
            BondPrice.cleanPrice             = bondFpML.price.cleanPrice;
            //Set the currencies
            CouponCurrency  = bondFpML.notionalAmount.currency;
            PaymentCurrency = bondFpML.notionalAmount.currency;//This could be another currency!
            //Set the notional information
            NotionalAmount = MoneyHelper.GetAmount(bondFpML.notionalAmount.amount, bondFpML.notionalAmount.currency.Value);
            //Determines the quotation and units
            QuoteType = BondPriceEnum.YieldToMaturity;
            //We need to get the ytm in until there is a bond market price/spread.
            if (BondPrice.dirtyPriceSpecified)
            {
                QuoteType = BondPriceEnum.DirtyPrice;
                Quote     = BasicQuotationHelper.Create(BondPrice.dirtyPrice, RateQuotationType);
            }
            //Get the instrument configuration information.
            var            assetIdentifier = bondFpML.bond.currency.Value + "-Bond-" + BondType;
            BondNodeStruct bondTypeInfo    = null;
            //TODO Set the swap curves for asset swap valuation.
            //
            //Gets the template bond type
            var instrument = InstrumentDataHelper.GetInstrumentConfigurationData(cache, nameSpace, assetIdentifier);

            if (instrument != null)
            {
                bondTypeInfo = instrument.InstrumentNodeItem as BondNodeStruct;
            }
            if (bondFpML.bond != null && bondTypeInfo != null)
            {
                if (SettlementCalendar == null)
                {
                    SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, bondTypeInfo.SettlementDate.businessCenters, nameSpace);
                }
                if (PaymentCalendar == null)
                {
                    PaymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, bondTypeInfo.BusinessDayAdjustments.businessCenters, nameSpace);
                }
                //Pre-processes the data for the priceable asset.
                var bond = XmlSerializerHelper.Clone(bondFpML.bond);
                Bond = bond;
                bondTypeInfo.Bond = Bond;
                //Set the curves to use for valuations.
                BondCurveName = CurveNameHelpers.GetBondCurveName(Bond.currency.Value, Bond.id);
                //THe discount curve is only for credit calculations.
                DiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Bond.currency.Value, true);
                if (bond.maturitySpecified)
                {
                    MaturityDate = bond.maturity;
                }
                SettlementDateConvention = bondTypeInfo.SettlementDate;
                BusinessDayAdjustments   = bondTypeInfo.BusinessDayAdjustments;
                ExDivDateConvention      = bondTypeInfo.ExDivDate;
                //This is done because the config data is not stored in the correct way. Need to add a price quote units.
                if (bond.couponRateSpecified)
                {
                    var coupon = bond.couponRate;
                    Bond.couponRate = coupon;
                }
                bondTypeInfo.Bond.faceAmount          = NotionalAmount.amount;
                bondTypeInfo.Bond.faceAmountSpecified = true;
                Bond.faceAmount = NotionalAmount.amount;
                if (Bond.maturitySpecified)
                {
                    RiskMaturityDate = Bond.maturity;
                }
                SettlementDate = settlementDate;
                if (!PaymentCurrencies.Contains(bondFpML.bond.currency.Value))
                {
                    PaymentCurrencies.Add(bondFpML.bond.currency.Value);
                }
                logger.LogInfo("Bond transaction has been successfully created.");
            }
            else
            {
                logger.LogInfo("Bond type data not available.");
            }
            //Set the underlying bond
            UnderlyingBond = new PriceableSimpleBond(tradeDate, bondTypeInfo, SettlementCalendar, PaymentCalendar, Quote, QuoteType);
            BondIssuer     = UnderlyingBond.Issuer;
            if (BondPrice.dirtyPriceSpecified)
            {
                UnderlyingBond.PurchasePrice = BondPrice.dirtyPrice / 100; //PriceQuoteUnits
            }
            //Set the coupons
            var bondId = Bond.id;//Could use one of the instrumentIds

            //bondStream is an interest Rate Stream but needs to be converted to a bond stream.
            //It automatically contains the coupon currency.
            Coupons = new PriceableBondCouponRateStream(logger, cache, nameSpace, bondId, tradeDate,
                                                        bondFpML.notionalAmount.amount, CouponStreamType.GenericFixedRate, Bond,
                                                        BusinessDayAdjustments, ForecastRateInterpolation, null, PaymentCalendar);
            //Add payments like the settlement price
            if (!BondPrice.dirtyPriceSpecified)
            {
                return;
            }
            var amount            = BondPrice.dirtyPrice * NotionalAmount.amount / 100;
            var settlementPayment = PaymentHelper.Create(BuyerReference, SellerReference, PaymentCurrency.Value, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, SettlementCalendar);
            //
            var finalPayment = PaymentHelper.Create(BondIssuer, BuyerReference, CouponCurrency.Value, NotionalAmount.amount, RiskMaturityDate);

            FinalRedemption =
                PriceableInstrumentsFactory.CreatePriceablePayment(basePartyReference, finalPayment, PaymentCalendar);
            AdditionalPayments.Add(FinalRedemption);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }
示例#23
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <param name="adjustment"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal?adjustment)
        {
            const string rateQuotationType       = PriceableSimpleRateAsset.RateQuotationType;
            const string volatilityQuotationType = PriceableCapRateAsset.VolatilityQuotationType;
            Asset        underlyingAsset;
            decimal      additional = 0.0m;

            if (adjustment != null)
            {
                additional = (decimal)adjustment;
            }
            var listBasicQuotations = new List <BasicQuotation>();
            var properties          = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            //This is in place to handle volatility curves where the tenor is the expiry.
            case AssetTypesEnum.Period:
            {
                //There is no underlying asset.
                underlyingAsset = null;
                listBasicQuotations.Add(BasicQuotationHelper.Create(instrumentId, value, volatilityQuotationType, "LognormalVolatility"));
                break;
            }

            case AssetTypesEnum.ZeroRate:
            {
                underlyingAsset = new Cash {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Caplet:
            case AssetTypesEnum.Floorlet:
            case AssetTypesEnum.BillCaplet:
            case AssetTypesEnum.BillFloorlet:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                underlyingAsset = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)      //TODO this restricts the perios to be the same!!!
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Swaption:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRCallFutureOption:
            case AssetTypesEnum.IRPutFutureOption:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFuture:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Volatility", "LognormalVolatility"));
                }
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                underlyingAsset = new FxRateAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "FxRate"));
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                underlyingAsset = new EquityAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                underlyingAsset = new Commodity {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                underlyingAsset = new Bond {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));        //Changed from DirtyPrice.
                break;
            }

            case AssetTypesEnum.Lease:
            {
                underlyingAsset = new Lease {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            var id = underlyingAsset?.id;

            if (underlyingAsset == null)
            {
                id = listBasicQuotations[0].id;
            }
            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(id, listBasicQuotations.ToArray())));
        }
        public override AssetValuation Calculate(IInstrumentControllerData modelData)
        {
            ModelData = modelData;
            AnalyticModelParameters = null;
            // 1. First derive the analytics to be evaluated via the stream controller model
            // NOTE: These take precedence of the child model metrics
            if (AnalyticsModel == null)
            {
                AnalyticsModel = new BondTransactionAnalytic();
            }
            var            bondControllerMetrics = ResolveModelMetrics(AnalyticsModel.Metrics);
            AssetValuation bondValuation;
            var            quotes = ModelData.AssetValuation.quote.ToList();

            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.AccrualFactor.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.AccrualFactor.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.FloatingNPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.FloatingNPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            if (AssetValuationHelper.GetQuotationByMeasureType(ModelData.AssetValuation, InstrumentMetrics.NPV.ToString()) == null)
            {
                var quote = QuotationHelper.Create(0.0m, InstrumentMetrics.NPV.ToString(), "DecimalValue");
                quotes.Add(quote);
            }
            ModelData.AssetValuation.quote = quotes.ToArray();
            var        marketEnvironment = modelData.MarketEnvironment;
            IRateCurve rateDiscountCurve = null;

            //2. Sets the evolution type for coupon and payment calculations.
            Coupons.PricingStructureEvolutionType = PricingStructureEvolutionType;
            Coupons.BucketedDates = BucketedDates;
            Coupons.Multiplier    = Multiplier;
            if (AdditionalPayments != null)
            {
                foreach (var payment in AdditionalPayments)
                {
                    payment.PricingStructureEvolutionType = PricingStructureEvolutionType;
                    payment.BucketedDates = BucketedDates;
                    payment.Multiplier    = Multiplier;
                }
            }
            //3. Aggregate the child metrics.
            List <AssetValuation> childValuations = new List <AssetValuation> {
                Coupons?.Calculate(modelData)
            };

            if (GetAdditionalPayments() != null)
            {
                var paymentControllers = new List <InstrumentControllerBase>(GetAdditionalPayments());
                childValuations.AddRange(paymentControllers.Select(payment => payment.Calculate(modelData)));
            }
            var childControllerValuations = AssetValuationHelper.AggregateMetrics(childValuations, new List <string>(Metrics), PaymentCurrencies);

            childControllerValuations.id = Id + ".BondCouponRateStreams";
            //4. Calc the asset as a little extra
            var metrics         = ResolveModelMetrics(AnalyticsModel.Metrics);
            var metricsAsString = metrics.Select(metric => metric.ToString()).ToList();
            var controllerData  = PriceableAssetFactory.CreateAssetControllerData(metricsAsString.ToArray(), modelData.ValuationDate, modelData.MarketEnvironment);

            UnderlyingBond.Multiplier = Multiplier;
            UnderlyingBond.Calculate(controllerData);
            //5. Now do the bond calculations.
            if (bondControllerMetrics.Count > 0)
            {
                CalculationResults = new BondTransactionResults();
                if (marketEnvironment.GetType() == typeof(MarketEnvironment))
                {
                    var bondCurve = (IBondCurve)modelData.MarketEnvironment.GetPricingStructure(BondCurveName);
                    if (bondCurve != null)
                    {
                        var marketDataType =
                            bondCurve.GetPricingStructureId().Properties.GetValue <string>(AssetMeasureEnum.MarketQuote.ToString(), false);
                        if (marketDataType != null && marketDataType == BondPriceEnum.YieldToMaturity.ToString())
                        {
                            IsYTMQuote = true;
                        }
                        //TODO handle the other cases like: AssetSwapSpread; DirtyPrice and ZSpread.
                        var mq = (decimal)bondCurve.GetYieldToMaturity(modelData.ValuationDate, SettlementDate);
                        Quote = BasicQuotationHelper.Create(mq, AssetMeasureEnum.MarketQuote.ToString(),
                                                            PriceQuoteUnitsEnum.DecimalRate.ToString());
                    }
                    rateDiscountCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(DiscountCurveName);
                }
                //Generate the vectors
                const bool isBuyerInd = true;
                var        analyticModelParameters = new BondTransactionParameters
                {
                    IsBuyerInd           = isBuyerInd,
                    AccrualYearFractions = GetCouponAccrualFactors(),
                    Multiplier           = Multiplier,
                    Quote                  = QuoteValue,
                    CouponRate             = UnderlyingBond.GetCouponRate(),
                    NotionalAmount         = UnderlyingBond.Notional,
                    Frequency              = UnderlyingBond.Frequency,
                    IsYTMQuote             = IsYTMQuote,
                    AccruedFactor          = UnderlyingBond.GetAccruedFactor(),
                    RemainingAccruedFactor = UnderlyingBond.GetRemainingAccruedFactor(),
                    PaymentDiscountFactors =
                        GetDiscountFactors(rateDiscountCurve, Coupons.StreamPaymentDates.ToArray(), modelData.ValuationDate),
                };
                //5. Get the Weightings
                analyticModelParameters.Weightings =
                    CreateWeightings(CDefaultWeightingValue, analyticModelParameters.PaymentDiscountFactors.Length);
                //6. Set the analytic input parameters and Calculate the respective metrics
                AnalyticModelParameters = analyticModelParameters;
                CalculationResults      = AnalyticsModel.Calculate <IBondTransactionResults, BondTransactionResults>(analyticModelParameters, metrics.ToArray());
                // Now merge back into the overall stream valuation
                var bondControllerValuation = GetValue(CalculationResults, modelData.ValuationDate);
                bondValuation = AssetValuationHelper.UpdateValuation(bondControllerValuation,
                                                                     childControllerValuations, ConvertMetrics(bondControllerMetrics), new List <string>(Metrics));
            }
            else
            {
                bondValuation = childControllerValuations;
            }
            // store inputs and results from this run
            CalculationPerformedIndicator = true;
            bondValuation.id = Id;
            return(bondValuation);
        }
示例#25
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <param name="adjustment"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal adjustment)
        {
            const string rateQuotationType = "MarketQuote";
            Asset        underlyingAsset;
            var          results             = instrumentId.Split('-');
            var          instrument          = results[1];
            var          listBasicQuotations = new List <BasicQuotation>();

            switch (instrument)
            {
            case "ZeroRate":
            {
                var zeroRate = new Cash {
                    id = instrumentId
                };
                underlyingAsset = zeroRate;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case "Xibor":
            case "OIS":
            {
                var tenor     = results[2];
                var rateIndex = new RateIndex {
                    id = instrumentId, term = Period.Parse(tenor)
                };
                underlyingAsset = rateIndex;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "IRSwap":
            case "XccySwap":
            case "SimpleIRSwap":
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = simpleIRSwap;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "Deposit":
            case "XccyDepo":
            case "BankBill":
            {
                var deposit = new Deposit {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = deposit;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "SimpleFra":
            case "Fra":
            case "BillFra":
            case "SpreadFra":
            {
                var index = results[3];
                var asset = new SimpleFra {
                    id = instrumentId, startTerm = Period.Parse(results[2])
                };

                asset.endTerm   = asset.startTerm.Sum(Period.Parse(index));
                underlyingAsset = asset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "IRCap":
            {
                var simpleIRCap = new SimpleIRSwap {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = simpleIRCap;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, "Premium", "Amount"));
                break;
            }

            case "IRFuture":
            {
                var future = new Future {
                    id = instrumentId
                };

                underlyingAsset = future;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                listBasicQuotations.Add(BasicQuotationHelper.Create(adjustment, "Volatility", "LognormalVolatility"));
                break;
            }

            case "CommodityFuture":
            {
                var future = new Future {
                    id = instrumentId
                };

                underlyingAsset = future;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case "CPIndex":
            {
                var tenor     = results[2];
                var rateIndex = new RateIndex {
                    id = instrumentId, term = Period.Parse(tenor)
                };
                underlyingAsset = rateIndex;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "SimpleCPISwap":
            case "CPISwap":
            case "ZCCPISwap":
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = simpleIRSwap;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "FxSpot":
            case "FxForward":
            {
                //  var tenor = results[2];
                var fxRateAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = fxRateAsset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "FxRate"));
                break;
            }

            case "CommoditySpot":
            case "CommodityForward":
            {
                var commodityAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = commodityAsset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "Price"));
                break;
            }

            case "Bond":
            {
                var asset = new Bond {
                    id = instrumentId
                };
                underlyingAsset = asset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DirtyPrice"));
                break;
            }

            default:
                throw new NotSupportedException(string.Format("Asset type {0} is not supported", instrument));
            }

            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray())));
        }
示例#26
0
        /// <summary>
        /// Calculates the specified model data.
        /// </summary>
        /// <param name="modelData">The model data.</param>
        /// <returns></returns>
        public override BasicAssetValuation Calculate(IAssetControllerData modelData)
        {
            ModelData      = modelData;
            AnalyticsModel = new BondAssetAnalytic();
            var metrics = MetricsHelper.GetMetricsToEvaluate(Metrics, AnalyticsModel.Metrics);
            // Determine if DFAM has been requested - if so that's all we evaluate - every other metric is ignored
            var metricsToEvaluate       = metrics.ToArray();
            var analyticModelParameters = new BondAssetParameters();

            CalculationResults = new BondAssetResults();
            var marketEnvironment = modelData.MarketEnvironment;
            //IRateCurve rate forecast curve = null;
            IRateCurve rateDiscountCurve = null;

            //0. Set the valuation date and recalculate the settlement date. This could mean regenerating all the coupon dates as well
            //Alternatively the bond can be recreated with a different base date = valuation date.
            //TODO Check that the dates are correct and that the last coupon date is used.
            //Set the purchase price.
            analyticModelParameters.PurchasePrice = PurchasePrice;
            //1. instantiate curve
            if (marketEnvironment.GetType() == typeof(SimpleMarketEnvironment))
            {
                rateDiscountCurve     = (IRateCurve)((ISimpleMarketEnvironment)marketEnvironment).GetPricingStructure();
                SwapDiscountCurveName = rateDiscountCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SimpleRateMarketEnvironment))
            {
                rateDiscountCurve     = ((ISimpleRateMarketEnvironment)marketEnvironment).GetRateCurve();
                SwapDiscountCurveName = rateDiscountCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(SwapLegEnvironment))
            {
                rateDiscountCurve     = ((ISwapLegEnvironment)marketEnvironment).GetDiscountRateCurve();
                SwapDiscountCurveName = rateDiscountCurve.GetPricingStructureId().UniqueIdentifier;
            }
            if (marketEnvironment.GetType() == typeof(MarketEnvironment))
            {
                var bondCurve = (IBondCurve)modelData.MarketEnvironment.GetPricingStructure(BondCurveName);
                if (bondCurve != null)
                {
                    var marketDataType =
                        bondCurve.GetPricingStructureId().Properties.GetValue <string>(AssetMeasureEnum.MarketQuote.ToString(), false);
                    if (marketDataType != null && marketDataType == BondPriceEnum.YieldToMaturity.ToString())
                    {
                        IsYTMQuote = true;
                    }
                    //TODO handle the other cases like: AssetSwapSpread; DirtyPrice and ZSpread.
                    var mq = (decimal)bondCurve.GetYieldToMaturity(modelData.ValuationDate, SettlementDate);
                    Quote = BasicQuotationHelper.Create(mq, AssetMeasureEnum.MarketQuote.ToString(),
                                                        PriceQuoteUnitsEnum.DecimalRate.ToString());
                }
                //The forecast rate curve will need to be set if it is a floating rate note.
                rateDiscountCurve = (IRateCurve)modelData.MarketEnvironment.GetPricingStructure(SwapDiscountCurveName);
            }
            //2. Set the rate and the Multiplier
            analyticModelParameters.Multiplier             = Multiplier;
            analyticModelParameters.Quote                  = QuoteValue;
            analyticModelParameters.CouponRate             = GetCouponRate();
            analyticModelParameters.NotionalAmount         = Notional;
            analyticModelParameters.Frequency              = Frequency;
            analyticModelParameters.IsYTMQuote             = IsYTMQuote;
            analyticModelParameters.AccruedFactor          = GetAccruedFactor();
            analyticModelParameters.RemainingAccruedFactor = GetRemainingAccruedFactor();
            //3. Get the discount factors
            analyticModelParameters.PaymentDiscountFactors =
                GetDiscountFactors(rateDiscountCurve, AdjustedPeriodDates, modelData.ValuationDate);
            //4. Get the respective year fractions
            analyticModelParameters.AccrualYearFractions = GetYearFractions();
            //5. Get the Weightings
            Weightings =
                CreateWeightings(CDefaultWeightingValue, analyticModelParameters.PaymentDiscountFactors.Length);
            analyticModelParameters.Weightings = Weightings;
            //6. Set the analytic input parameters and Calculate the respective metrics
            AnalyticModelParameters = analyticModelParameters;
            CalculationResults      =
                AnalyticsModel.Calculate <IBondAssetResults, BondAssetResults>(analyticModelParameters,
                                                                               metricsToEvaluate);
            return(GetValue(CalculationResults));
        }
示例#27
0
        /// <summary>
        /// Parses the data.
        /// </summary>
        /// <param name="instrumentIds"></param>
        /// <returns></returns>
        public static QuotedAssetSet Parse(string[] instrumentIds)
        {
            var quotedAssetSetFactory = new QuotedAssetSetFactory();

            const string rateQuotationType = "MarketQuote";

            for (var i = 0; i < instrumentIds.Length; i++)
            {
                Asset underlyingAsset;

                var instrumentId = instrumentIds[i];
                var results      = instrumentIds[i].Split('-');
                var instrument   = results[1];

                var listBasicQuotations = new List <BasicQuotation>();

                const string priceUnitDecimalRate = "DecimalRate";

                switch (instrument)
                {
                case "ZeroRate":
                {
                    underlyingAsset = new Cash {
                        id = instrumentId
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "Xibor":
                case "OIS":
                {
                    var tenor = results[2];
                    underlyingAsset = new RateIndex {
                        id = instrumentId, term = Period.Parse(tenor)
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "IRSwap":
                case "XccySwap":
                case "SimpleIRSwap":
                {
                    underlyingAsset = new SimpleIRSwap {
                        id = instrumentId, term = Period.Parse(results[2])
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "Deposit":
                case "XccyDepo":
                case "BankBill":
                {
                    underlyingAsset = new Deposit {
                        id = instrumentId, term = Period.Parse(results[2])
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "SimpleFra":
                case "Fra":
                case "BillFra":
                {
                    var index = results[3];
                    var asset = new SimpleFra {
                        id = instrumentId, startTerm = Period.Parse(results[2])
                    };

                    asset.endTerm   = asset.startTerm.Sum(Period.Parse(index));
                    underlyingAsset = asset;
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "IRFuture":
                {
                    underlyingAsset = new Future {
                        id = instrumentId
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    listBasicQuotations.Add(BasicQuotationHelper.Create("Volatility", "LognormalVolatility"));
                    break;
                }

                case "CPIndex":
                {
                    var tenor = results[2];
                    underlyingAsset = new RateIndex {
                        id = instrumentId, term = Period.Parse(tenor)
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "SimpleCPISwap":
                case "CPISwap":
                case "ZCCPISwap":
                {
                    underlyingAsset = new SimpleIRSwap {
                        id = instrumentId, term = Period.Parse(results[2])
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                default:
                    throw new NotSupportedException(string.Format("Asset type {0} is not supported", instrument));
                }

                quotedAssetSetFactory.AddAssetAndQuotes(underlyingAsset, BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray()));
            }
            return(quotedAssetSetFactory.Create());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="cache"></param>
        /// <param name="nameSpace"></param>
        /// <param name="tradeDate"></param>
        /// <param name="settlementDate">The payment settlement date.</param>
        /// <param name="settlementCalendar"></param>
        /// <param name="paymentCalendar"></param>
        /// <param name="bondFpML"></param>
        /// <param name="basePartyReference"></param>
        /// <param name="bondType"></param>
        /// <param name="forecastRateInterpolation"></param>
        public BondTransactionPricer(ILogger logger, ICoreCache cache, string nameSpace, DateTime tradeDate,
                                     DateTime settlementDate, IBusinessCalendar settlementCalendar, IBusinessCalendar paymentCalendar,
                                     BondTransaction bondFpML, string basePartyReference, string bondType, Boolean forecastRateInterpolation)
        {
            Multiplier = 1.0m;
            TradeDate  = tradeDate;
            BondType   = EnumHelper.Parse <BondTypesEnum>(bondType);
            logger.LogInfo("BondType set. Commence to build a bond transaction.");
            if (bondFpML == null)
            {
                return;
            }
            BuyerReference    = bondFpML.buyerPartyReference.href;
            PaymentCurrencies = new List <string> {
                bondFpML.notionalAmount.currency.Value
            };
            SellerReference = bondFpML.sellerPartyReference.href;
            BasePartyBuyer  = basePartyReference == bondFpML.buyerPartyReference.href;
            if (!BasePartyBuyer)
            {
                Multiplier = -1.0m;
            }
            ForecastRateInterpolation = forecastRateInterpolation;
            SettlementCalendar        = settlementCalendar;
            PaymentCalendar           = paymentCalendar;
            //Set the bond price information
            BondPrice = new BondPrice();
            if (bondFpML.price.accrualsSpecified)
            {
                BondPrice.accrualsSpecified = true;
                BondPrice.accruals          = bondFpML.price.accruals;
            }
            if (bondFpML.price.dirtyPriceSpecified)
            {
                BondPrice.dirtyPriceSpecified = true;
                BondPrice.dirtyPrice          = bondFpML.price.dirtyPrice;
            }
            BondPrice.cleanOfAccruedInterest = bondFpML.price.cleanOfAccruedInterest;
            BondPrice.cleanPrice             = bondFpML.price.cleanPrice;
            //Set the notional information
            NotionalAmount = MoneyHelper.GetAmount(bondFpML.notionalAmount.amount, bondFpML.notionalAmount.currency.Value);
            //Determines the quotation and units
            QuoteType = BondPriceEnum.YieldToMaturity;
            //We need to get the ytm in until there is a bond market price/spread.
            if (BondPrice.dirtyPriceSpecified)
            {
                QuoteType = BondPriceEnum.DirtyPrice;
                Quote     = BasicQuotationHelper.Create(BondPrice.dirtyPrice, RateQuotationType);
            }
            //Get the insturment configuration information.
            var            assetIdentifier = bondFpML.bond.currency.Value + "-Bond-" + BondType;
            BondNodeStruct bondTypeInfo    = null;
            var            instrument      = InstrumentDataHelper.GetInstrumentConfigurationData(cache, nameSpace, assetIdentifier);

            if (instrument != null)
            {
                bondTypeInfo = instrument.InstrumentNodeItem as BondNodeStruct;
            }
            if (bondFpML.bond != null && bondTypeInfo != null)
            {
                if (SettlementCalendar == null)
                {
                    SettlementCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, bondTypeInfo.SettlementDate.businessCenters, nameSpace);
                }
                if (PaymentCalendar == null)
                {
                    PaymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, bondTypeInfo.BusinessDayAdjustments.businessCenters, nameSpace);
                }
                //Preprocesses the data for the priceableasset.
                var bond = XmlSerializerHelper.Clone(bondFpML.bond);
                BondTypeInfo      = XmlSerializerHelper.Clone(bondTypeInfo);
                BondTypeInfo.Bond = bond;
                //This is done because the config data is not stored in the ciorrect way. Need to add a price quote units.
                if (bond.couponRateSpecified)
                {
                    var coupon = bond.couponRate;
                    BondTypeInfo.Bond.couponRate = coupon;
                }
                BondTypeInfo.Bond.faceAmount = NotionalAmount.amount;
                if (BondTypeInfo.Bond.maturitySpecified)
                {
                    RiskMaturityDate = BondTypeInfo.Bond.maturity;
                }
                SettlementDate = settlementDate;
                if (!PaymentCurrencies.Contains(bondFpML.bond.currency.Value))
                {
                    PaymentCurrencies.Add(bondFpML.bond.currency.Value);
                }
                logger.LogInfo("Bond transaction has been successfully created.");
            }
            else
            {
                logger.LogInfo("Bond type data not available.");
            }
            //Add payments like the settlement price
            if (!BondPrice.dirtyPriceSpecified)
            {
                return;
            }
            var amount            = BondPrice.dirtyPrice * NotionalAmount.amount / 100;
            var settlementPayment = PaymentHelper.Create("BondSettlemetAmount", BuyerReference, SellerReference, amount, SettlementDate);

            AdditionalPayments = PriceableInstrumentsFactory.CreatePriceablePayments(basePartyReference, new[] { settlementPayment }, SettlementCalendar);
            if (!PaymentCurrencies.Contains(settlementPayment.paymentAmount.currency.Value))
            {
                PaymentCurrencies.Add(settlementPayment.paymentAmount.currency.Value);
            }
        }