using Qdp.Pricing.Base.Implementations; using YLErp.Models; namespace YLErp.QdpModule { /// /// /// public class VolSurfaceVectorBase { /// /// a vector of time to maturity /// public string[] expires { get; set; } /// /// a vector of strike prices /// public double[] strikes { get; set; } /// /// 解析expires和strikes /// /// 波动率表 /// 用于存储strike和expire组成的key对应的波动率(key格式:{strike:F2}^{expire}) protected static void InnerParse(IEnumerable volTable, out string[] expires, out double[] strikes, Dictionary volMap = null) { if (volTable == null || !volTable.Any()) { strikes = new double[0]; expires = new string[0]; return; } var strikeSet = new HashSet(); var expireSet = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (var item in volTable) { strikeSet.Add(item.Strike); expireSet.Add(item.Expire ?? string.Empty); if (volMap != null) { var key = string.Concat(item.Strike.ToString("F"), "^", item.Expire); volMap[key] = item; } } strikes = strikeSet.ToArray(); Array.Sort(strikes); expires = expireSet.ToArray(); var terms = expires.ToDictionary(x => x, x => new Term(x)); Array.Sort(expires, (x, y) => terms[x].CompareTo(terms[y])); } } }