Files
zszq-trs/YLErpDAL/QdpModule/VolSurfaceVector.cs
T
2024-05-09 14:06:26 +08:00

56 lines
1.7 KiB
C#

using YLErp.Models;
namespace YLErp.QdpModule
{
/// <summary>
/// 波动率曲面向量
/// </summary>
public class VolSurfaceVector : VolSurfaceVectorBase
{
/// <summary>
/// a vector European call prices gotten from the market for the same underlying asset
/// </summary>
public double[,] vols { get; set; }
/// <summary>
///
/// </summary>
/// <param name="volTable"></param>
/// <param name="addVol">加点值或加点比例</param>
/// <param name="isAddVolPercent"></param>
public static VolSurfaceVector Create(IEnumerable<SingleVol> volTable, double addVol = 0, bool isAddVolPercent = true)
{
if (isAddVolPercent)
{
addVol += 1;
}
var dic = new Dictionary<string, SingleVol>(StringComparer.OrdinalIgnoreCase);
InnerParse(volTable, out var expires, out var strikes, dic);
var vols = new double[expires.Length, strikes.Length];
for (var i = 0; i < expires.Length; i++)
{
var expire = expires[i];
for (int j = 0; j < strikes.Length; j++)
{
var key = string.Concat(strikes[j].ToString("F"), "^", expire);
if (dic.TryGetValue(key, out var vol))
{
vols[i, j] = isAddVolPercent ? addVol * vol.Vol : addVol + vol.Vol;
}
}
}
return new VolSurfaceVector
{
strikes = strikes,
expires = expires,
vols = vols
};
}
}
}