当前位置: 首页>>代码示例>>C#>>正文


C# Series.TryGet方法代码示例

本文整理汇总了C#中Series.TryGet方法的典型用法代码示例。如果您正苦于以下问题:C# Series.TryGet方法的具体用法?C# Series.TryGet怎么用?C# Series.TryGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Series的用法示例。


在下文中一共展示了Series.TryGet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalcRepoRatesFromOisSpread

        // Compute repo rates based on an input repo-ois spread
        public static double[,] CalcRepoRatesFromOisSpread(this ICarbonClient client, Series<DateTime, double> repoSpdSrs, BondAnalytics.Country country, List<DateTime> asOfDate, List<DateTime> forwardDates,
            List<DateTime> holidays, Dictionary<DateTime, Tuple<DateTime, double>[]> discCurves = null)
        {
            // Init
            var holSet = new HashSet<DateTime>(holidays);
            var ccy = getRepoCCYFromCountry(country);

            // Checks
            if (asOfDate.Count != forwardDates.Count)
            {
                throw new ArgumentException("#Error: as of dates and forward dates need to have the same length!");
            }

            
            // Get swap curves if not specified
            if (discCurves == null)
            {
                discCurves = new Dictionary<DateTime, Tuple<DateTime, double>[]>();
                var rawCurves = client.BulkGetHistoricEodDiscountCurves(asOfDate, ccy, true);

                foreach (var kvp in rawCurves)
                {
                    discCurves[kvp.Key] = kvp.Value.AsTuples();
                }
            }

            // Get Results
            double[,] results = new double[asOfDate.Count, 2];
            for (int i = 0; i < asOfDate.Count; ++i)
            {
                var dte = asOfDate[i];
                var fwddte = forwardDates[i];
                var spdAttempt = repoSpdSrs.TryGet(dte);
                double repoRate;
                double repoSpread;

                if (spdAttempt.HasValue && !holSet.Contains(dte))
                {

                    // Calc repo rate
                    repoSpread = spdAttempt.Value;
                    double oisSwap = double.NaN;

                    //  Have already caught the case of missing discount curve above.
                    if (discCurves.ContainsKey(dte))
                    {
                        var tups = discCurves[dte];
                        DateTime[] discDfDates = tups.Select(x => x.Item1).ToArray();
                        double[] discDfs = tups.Select(x => x.Item2).ToArray();

                        BondAnalytics.DayCountType oisDct = (country == BondAnalytics.Country.CA ||
                                                             country == BondAnalytics.Country.UK
                            ? BondAnalytics.DayCountType.Act365
                            : BondAnalytics.DayCountType.Act360);

                        oisSwap = dte < fwddte
                            ? BondAnalytics.CalcMMS(dte, fwddte, oisDct, 12, 12, discDfDates,
                                discDfs,
                                discDfDates, discDfs, holidays, null, null, null, null, null, DateTime.MinValue, 5)
                            : double.NaN;
                    }

                    repoRate = double.IsNaN(oisSwap) ? double.NaN : oisSwap + repoSpread;
                }
                else
                {
                    repoRate = double.NaN;
                    repoSpread = double.NaN;
                }

                results[i, 0] = repoSpread;
                results[i, 1] = repoRate;
            }
            return results;
        }
开发者ID:heimanhon,项目名称:researchwork,代码行数:76,代码来源:AnalyticsUtilities.cs


注:本文中的Series.TryGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。