本文整理汇总了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;
}