184 lines
5.3 KiB
C#
184 lines
5.3 KiB
C#
using YLErp.Abstract;
|
|
using YLErp.Models;
|
|
using YLErp.QdpModule;
|
|
|
|
namespace YLErp.BLL.Calculation
|
|
{
|
|
/// <summary>
|
|
/// VolSurfaceInitParams构建
|
|
/// </summary>
|
|
public struct VolSurfaceInitParamsBuilder
|
|
{
|
|
VolSurfaceInitParams initParams;
|
|
|
|
public VolSurfaceInitParamsBuilder(string userId)
|
|
{
|
|
initParams = new VolSurfaceInitParams
|
|
{
|
|
userId = userId ?? string.Empty
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置valueDate
|
|
/// </summary>
|
|
public VolSurfaceInitParamsBuilder SetValueDate(DateTime date)
|
|
{
|
|
if (initParams == null)
|
|
{
|
|
initParams = new VolSurfaceInitParams();
|
|
}
|
|
initParams.valueDate = date.ToString("yyyy-MM-dd");
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置valueDate
|
|
/// </summary>
|
|
public VolSurfaceInitParamsBuilder SetValueDate(string valueDate)
|
|
{
|
|
if (initParams == null)
|
|
{
|
|
initParams = new VolSurfaceInitParams();
|
|
}
|
|
|
|
initParams.valueDate = valueDate;
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置QuotationDate,UnderlyingId,UnderlyingCode,UnderlyingName
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置UnderlyingId,UnderlyingCode,UnderlyingName
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置 vols,volSurfaceMode,interpolation
|
|
/// </summary>
|
|
public VolSurfaceInitParamsBuilder SetVolatility(IVolatility vol, List<SingleVol> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 构建实例
|
|
/// </summary>
|
|
public VolSurfaceInitParams Build()
|
|
{
|
|
if (initParams == null)
|
|
{
|
|
initParams = new VolSurfaceInitParams();
|
|
}
|
|
return initParams;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置 addVolRate,isAddVolPercent
|
|
/// </summary>
|
|
public VolSurfaceInitParams Build(double addVolRate, bool isAddVolPercent = true)
|
|
{
|
|
if (initParams == null)
|
|
{
|
|
initParams = new VolSurfaceInitParams();
|
|
}
|
|
|
|
initParams.addVolRate = addVolRate;
|
|
initParams.isAddVolPercent = isAddVolPercent;
|
|
return initParams;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置 volSurfaceNameKey,addVolRate,isAddVolPercent
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置 volSurfaceNameKey,volSurfaceMode,vols
|
|
/// </summary>
|
|
public VolSurfaceInitParams Build(string volSurfaceMode, List<SingleVol> 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;
|
|
}
|
|
}
|
|
}
|