コード例 #1
0
ファイル: AssetHelper.cs プロジェクト: zhangz/Highlander.Net
        /// <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());
        }
コード例 #2
0
ファイル: AssetHelper.cs プロジェクト: zhangz/Highlander.Net
        /// <summary>
        /// Parses the data.
        /// </summary>
        /// <param name="instrumentIds"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static QuotedAssetSet Parse(string[] instrumentIds, decimal[] values)
        {
            var quotedAssetSetFactory = new QuotedAssetSetFactory();

            for (int i = 0; i < instrumentIds.Length; i++)
            {
                Pair <Asset, BasicAssetValuation> assetPair = Parse(instrumentIds[i], values[i], null);
                quotedAssetSetFactory.AddAssetAndQuotes(assetPair.First, assetPair.Second);
            }
            return(quotedAssetSetFactory.Create());
        }
コード例 #3
0
ファイル: AssetHelper.cs プロジェクト: zhangz/Highlander.Net
        /// <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());
        }
コード例 #4
0
ファイル: AssetHelper.cs プロジェクト: zhangz/Highlander.Net
        /// <summary>
        /// Parses the data.
        /// </summary>
        /// <param name="instrumentIds"></param>
        /// <param name="values"></param>
        /// <param name="adjustments"></param>
        /// <returns></returns>
        public static QuotedAssetSet ParseTenorSet(string[] instrumentIds, decimal[] values, decimal[] adjustments)
        {
            var quotedAssetSetFactory = new QuotedAssetSetFactory();

            if (adjustments != null)
            {
                for (int i = 0; i < instrumentIds.Length; i++)
                {
                    Pair <Asset, BasicAssetValuation> assetPair = Parse(instrumentIds[i], values[i], adjustments[i]);
                    quotedAssetSetFactory.AddAssetAndQuotes(assetPair.First, assetPair.Second);
                }
            }
            else
            {
                for (int i = 0; i < instrumentIds.Length; i++)
                {
                    Pair <Asset, BasicAssetValuation> assetPair = Parse(instrumentIds[i], values[i], null);
                    quotedAssetSetFactory.AddAssetAndQuotes(assetPair.First, assetPair.Second);
                }
            }
            return(quotedAssetSetFactory.CreateTenorSet());
        }
コード例 #5
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, Helpers.BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray()));
            }
            return(quotedAssetSetFactory.Create());
        }