using YLErp.Abstract; using YLErp.Models; using YLErp.QdpModule; namespace YLErp.BLL.Calculation { /// /// VolSurfaceInitParams构建 /// public struct VolSurfaceInitParamsBuilder { VolSurfaceInitParams initParams; public VolSurfaceInitParamsBuilder(string userId) { initParams = new VolSurfaceInitParams { userId = userId ?? string.Empty }; } /// /// 设置valueDate /// public VolSurfaceInitParamsBuilder SetValueDate(DateTime date) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } initParams.valueDate = date.ToString("yyyy-MM-dd"); return this; } /// /// 设置valueDate /// public VolSurfaceInitParamsBuilder SetValueDate(string valueDate) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } initParams.valueDate = valueDate; return this; } /// /// 设置QuotationDate,UnderlyingId,UnderlyingCode,UnderlyingName /// public VolSurfaceInitParamsBuilder SetUnderlying(underlying_manager udm) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } if (udm != null) { initParams.UnderlyingId = udm.id; initParams.UnderlyingCode = udm.UnderlyingCode; initParams.UnderlyingName = udm.UnderlyingName; if (udm.QuotationDate.HasValue && string.IsNullOrWhiteSpace(initParams.valueDate)) { initParams.valueDate = udm.QuotationDate.Value.ToString("yyyy-MM-dd"); } } return this; } /// /// 设置UnderlyingId,UnderlyingCode,UnderlyingName /// public VolSurfaceInitParamsBuilder SetUnderlying(int UnderlyingId, string UnderlyingCode, string UnderlyingName) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } initParams.UnderlyingId = UnderlyingId; initParams.UnderlyingCode = UnderlyingCode; initParams.UnderlyingName = UnderlyingName; return this; } /// /// 设置 vols,volSurfaceMode,interpolation /// public VolSurfaceInitParamsBuilder SetVolatility(IVolatility vol, List vols = null) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } if (vol != null) { initParams.vols = vols ?? vol.VolTable; initParams.volSurfaceMode = vol.VolSurfaceMode; initParams.interpolation = vol.InterpolationMethod; } else { initParams.vols = vols; } return this; } /// /// 构建实例 /// public VolSurfaceInitParams Build() { if (initParams == null) { initParams = new VolSurfaceInitParams(); } return initParams; } /// /// 设置 addVolRate,isAddVolPercent /// public VolSurfaceInitParams Build(double addVolRate, bool isAddVolPercent = true) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } initParams.addVolRate = addVolRate; initParams.isAddVolPercent = isAddVolPercent; return initParams; } /// /// 设置 volSurfaceNameKey,addVolRate,isAddVolPercent /// public VolSurfaceInitParams Build(string volSurfaceNameKey, double addVolRate = 0, bool isAddVolPercent = true) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } if (!string.IsNullOrEmpty(volSurfaceNameKey)) { initParams.volSurfaceNameKey = QdpVolHelper.GetVolSurfaceName(volSurfaceNameKey); } initParams.addVolRate = addVolRate; initParams.isAddVolPercent = isAddVolPercent; return initParams; } /// /// 设置 volSurfaceNameKey,volSurfaceMode,vols /// public VolSurfaceInitParams Build(string volSurfaceMode, List vols, string volSurfaceNameKey = null) { if (initParams == null) { initParams = new VolSurfaceInitParams(); } initParams.vols = vols; initParams.volSurfaceMode = volSurfaceMode; if (!string.IsNullOrEmpty(volSurfaceNameKey)) { initParams.volSurfaceNameKey = QdpVolHelper.GetVolSurfaceName(volSurfaceNameKey); } return initParams; } } }