59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Qdp.Pricing.Base.Implementations;
|
|
using YLErp.Models;
|
|
|
|
namespace YLErp.QdpModule
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class VolSurfaceVectorBase
|
|
{
|
|
/// <summary>
|
|
/// a vector of time to maturity
|
|
/// </summary>
|
|
public string[] expires { get; set; }
|
|
|
|
/// <summary>
|
|
/// a vector of strike prices
|
|
/// </summary>
|
|
public double[] strikes { get; set; }
|
|
|
|
/// <summary>
|
|
/// 解析expires和strikes
|
|
/// </summary>
|
|
/// <param name="volTable">波动率表</param>
|
|
/// <param name="volMap">用于存储strike和expire组成的key对应的波动率(key格式:{strike:F2}^{expire})</param>
|
|
protected static void InnerParse(IEnumerable<SingleVol> volTable, out string[] expires, out double[] strikes, Dictionary<string, SingleVol> volMap = null)
|
|
{
|
|
if (volTable == null || !volTable.Any())
|
|
{
|
|
strikes = new double[0];
|
|
expires = new string[0];
|
|
return;
|
|
}
|
|
|
|
var strikeSet = new HashSet<double>();
|
|
var expireSet = new HashSet<string>(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]));
|
|
}
|
|
}
|
|
}
|