234 lines
7.0 KiB
C#
234 lines
7.0 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace YLErp.DBModels
|
|
{
|
|
[Table("synthetic_underlying")]
|
|
public class SyntheticUnderlying : DBModelWithOperator, IClonable<SyntheticUnderlying>
|
|
{
|
|
/// <summary>
|
|
/// 名称
|
|
/// </summary>
|
|
[DisplayName("名称"), Required]
|
|
public string Name { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的信息1
|
|
/// </summary>
|
|
[DisplayName("标的信息1")]
|
|
public int? UnderlyingId1 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的信息2
|
|
/// </summary>
|
|
[DisplayName("标的信息2")]
|
|
public int? UnderlyingId2 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的信息3
|
|
/// </summary>
|
|
[DisplayName("标的信息3")]
|
|
public int? UnderlyingId3 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的信息4
|
|
/// </summary>
|
|
[DisplayName("标的信息4")]
|
|
public int? UnderlyingId4 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的代码1
|
|
/// </summary>
|
|
[DisplayName("标的代码1")]
|
|
public string UnderlyingCode1 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的代码3
|
|
/// </summary>
|
|
[DisplayName("标的代码3")]
|
|
public string UnderlyingCode2 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的代码1
|
|
/// </summary>
|
|
[DisplayName("标的代码1")]
|
|
public string UnderlyingCode3 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的代码4
|
|
/// </summary>
|
|
[DisplayName("标的代码4")]
|
|
public string UnderlyingCode4 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 系数1
|
|
/// </summary>
|
|
[DisplayName("系数1")]
|
|
public double? Coefficient1 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 系数2
|
|
/// </summary>
|
|
[DisplayName("系数2")]
|
|
public double? Coefficient2 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 系数3
|
|
/// </summary>
|
|
[DisplayName("系数3")]
|
|
public double? Coefficient3 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 系数4
|
|
/// </summary>
|
|
[DisplayName("系数4")]
|
|
public double? Coefficient4 { set; get; }
|
|
|
|
/// <summary>
|
|
/// 常数
|
|
/// </summary>
|
|
public double? Constant { get; set; }
|
|
|
|
/// <summary>
|
|
/// 合约乘数
|
|
/// </summary>
|
|
public double? ContractSize { get; set; }
|
|
|
|
public bool IsEquals(SyntheticUnderlying su2)
|
|
{
|
|
if (ReferenceEquals(this, su2))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (su2 is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
string InnerTrim(string str)
|
|
{
|
|
return str?.Trim() ?? string.Empty;
|
|
}
|
|
|
|
return InnerTrim(UnderlyingCode1) == InnerTrim(su2.UnderlyingCode1)
|
|
&& InnerTrim(UnderlyingCode2) == InnerTrim(su2.UnderlyingCode2)
|
|
&& InnerTrim(UnderlyingCode3) == InnerTrim(su2.UnderlyingCode3)
|
|
&& InnerTrim(UnderlyingCode4) == InnerTrim(su2.UnderlyingCode4)
|
|
&& Math.Abs((Coefficient1 ?? 0) - su2.Coefficient1 ?? 0) < 1e-7
|
|
&& Math.Abs((Coefficient2 ?? 0) - su2.Coefficient2 ?? 0) < 1e-7
|
|
&& Math.Abs((Coefficient3 ?? 0) - su2.Coefficient3 ?? 0) < 1e-7
|
|
&& Math.Abs((Coefficient4 ?? 0) - su2.Coefficient4 ?? 0) < 1e-7
|
|
&& Math.Abs((Constant ?? 0) - su2.Constant ?? 0) < 1e-7;
|
|
}
|
|
|
|
public string UnderlyingTipsInfo
|
|
{
|
|
get
|
|
{
|
|
var tipsInfo = "";
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode1))
|
|
{
|
|
tipsInfo += $"{Coefficient1}*{UnderlyingCode1}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode2))
|
|
{
|
|
tipsInfo += $"{(Coefficient2 >= 0 ? "+" : "-")}{Math.Abs(Coefficient2.Value)}*{UnderlyingCode2}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode3))
|
|
{
|
|
tipsInfo += $"{(Coefficient3 >= 0 ? "+" : "-")}{Math.Abs(Coefficient3.Value)}*{UnderlyingCode3}";
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode4))
|
|
{
|
|
tipsInfo += $"{(Coefficient4 >= 0 ? "+" : "-")}{Math.Abs(Coefficient4.Value)}*{UnderlyingCode4}";
|
|
}
|
|
|
|
if (Constant != null && Constant != 0)
|
|
{
|
|
tipsInfo += $"{(Constant >= 0 ? "+" : "-")}{Math.Abs(Constant.Value)}";
|
|
}
|
|
|
|
return tipsInfo;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取可用的标的代码
|
|
/// </summary>
|
|
public IEnumerable<string> GetUnderlyingCodes()
|
|
{
|
|
var arr = new string[] {
|
|
UnderlyingCode1.TrimToNull(),
|
|
UnderlyingCode2.TrimToNull(),
|
|
UnderlyingCode3.TrimToNull(),
|
|
UnderlyingCode4.TrimToNull(),
|
|
};
|
|
return arr.Where(n => !string.IsNullOrEmpty(n)).ToArray();
|
|
}
|
|
|
|
public SyntheticUnderlying Clone()
|
|
{
|
|
return (SyntheticUnderlying)MemberwiseClone();
|
|
}
|
|
|
|
public SyntheticPriceModel GetSyntheticPriceModel()
|
|
{
|
|
var sulist = new List<UnderlyingPriceModel>();
|
|
|
|
var model = new SyntheticPriceModel
|
|
{
|
|
SuList = sulist,
|
|
Constant = Constant ?? 0
|
|
};
|
|
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode1))
|
|
{
|
|
sulist.Add(new UnderlyingPriceModel { UnderlyingCode = UnderlyingCode1, Coefficient = Coefficient1 ?? 0 });
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode2))
|
|
{
|
|
sulist.Add(new UnderlyingPriceModel { UnderlyingCode = UnderlyingCode2, Coefficient = Coefficient2 ?? 0 });
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode3))
|
|
{
|
|
sulist.Add(new UnderlyingPriceModel { UnderlyingCode = UnderlyingCode3, Coefficient = Coefficient3 ?? 0 });
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(UnderlyingCode4))
|
|
{
|
|
sulist.Add(new UnderlyingPriceModel { UnderlyingCode = UnderlyingCode4, Coefficient = Coefficient4 ?? 0 });
|
|
}
|
|
|
|
return model;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的价格模型
|
|
/// </summary>
|
|
public class UnderlyingPriceModel
|
|
{
|
|
public string UnderlyingCode { get; set; }
|
|
|
|
public double Price { get; set; }
|
|
|
|
public double Coefficient { get; set; }
|
|
public double? ContractSize { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 合成价差期权价格结果Model
|
|
/// </summary>
|
|
public class SyntheticPriceModel
|
|
{
|
|
public double Constant { get; set; }
|
|
|
|
public double Price { get; set; }
|
|
|
|
public IEnumerable<UnderlyingPriceModel> SuList { get; set; }
|
|
}
|
|
}
|