using Qdp.ComputeService.Data.CommonModels.MarketInfos; using Qdp.Foundation.Implementations; using Qdp.Pricing.Base.Utilities; using Qdp.Pricing.Ecosystem.Utilities; using Qdp.Pricing.Library.Common.MathMethods.VolTermStructure; using System.Diagnostics; using YLErp.Configuration; using YLErp.Models; using YLErp.QdpModule.Constants; namespace YLErp.QdpModule { /// /// VolSurface构建器 /// public class VolSurfaceBuilder { /// /// /// public string volSurfaceName { get; set; } /// /// 默认使用MoneynessVol /// public string volSurfaceType { get; set; } = "MoneynessVol"; /// /// 默认使用BiLinear /// public string interpolation { get; set; } = ConsVolMethod.BiLinear; /// /// 默认使用PS.Config.ErpElement.VolSurfaceKeyDateShift /// public VolSurfaceKeyDateShiftEnum volSurfaceKeyDateShift { get; set; } /// /// 默认使用PS.Config.ErpElement.VolSurfaceTermExcludeEndDate /// public bool excludeEndDate { get; set; } public VolSurfaceVector vector { get; set; } public VolSurfaceBuilder() { //默认值不要随意更改 volSurfaceKeyDateShift = PS.Config.ErpElement.VolSurfaceKeyDateShift; excludeEndDate = PS.Config.ErpElement.VolSurfaceTermExcludeEndDate; } /// /// /// public VolSurfaceBuilder SetVectors(IEnumerable volTable, double addVol = 0, bool isAddVolPercent = true) { vector = VolSurfaceVector.Create(volTable, addVol, isAddVolPercent); return this; } /// /// /// public VolSurfaceWrap Build(Date date) { if (date is null) { throw new ArgumentNullException(nameof(date)); } if (string.IsNullOrEmpty(volSurfaceName)) { throw new Exception("volSurfaceName不能为空"); } if (vector is null) { throw new ArgumentNullException(nameof(vector)); } Debug.Assert(vector.expires != null); Debug.Assert(vector.strikes != null); Debug.Assert(vector.vols != null); if (string.IsNullOrWhiteSpace(volSurfaceType)) { volSurfaceType = "MoneynessVol"; } else { volSurfaceType = string.Equals("MoneynessVol", volSurfaceType, StringComparison.OrdinalIgnoreCase) ? "MoneynessVol" : "StrikeVol"; } if (string.IsNullOrWhiteSpace(interpolation)) { interpolation = ConsVolMethod.BiLinear; } var dates = QdpHelper.ConvertTenorsToDates(date, vector.expires, volSurfaceKeyDateShift, excludeEndDate); var volSurface = new VolSurfMktData(volSurfaceName, dates.ToArray(), vector.strikes, vector.vols, interpolation, volSurfaceType); var surface = volSurface.ToImpliedVolSurface(date, dc: BLL.valuedateBLL.SystemDate.CurveDayCount?.TrimToNull() ?? "Bus244"); return new VolSurfaceWrap { VolSurface = surface, VolSurfaceName = volSurfaceName, ValueDate = date.DateTime.ToString("yyyy-MM-dd") }; } public VolSurfaceWrap Build(DateTime date) { return Build(new Date(date.Date)); } /// /// /// /// /// public VolSurfaceWrap Build(string date) { var wrap = Build(date.ToDate()); wrap.ValueDate = date; return wrap; } } /// /// VolSurface构建结果包装 /// public class VolSurfaceWrap { public string ValueDate { get; set; } public ImpliedVolSurface VolSurface { get; set; } public string VolSurfaceName { get; set; } } }