using YLErp.Models;
namespace YLErp.QdpModule
{
///
/// 波动率曲面向量
///
public class VolSurfaceVector : VolSurfaceVectorBase
{
///
/// a vector European call prices gotten from the market for the same underlying asset
///
public double[,] vols { get; set; }
///
///
///
///
/// 加点值或加点比例
///
public static VolSurfaceVector Create(IEnumerable volTable, double addVol = 0, bool isAddVolPercent = true)
{
if (isAddVolPercent)
{
addVol += 1;
}
var dic = new Dictionary(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
};
}
}
}