583 lines
16 KiB
C#
583 lines
16 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using YLErp.Commons;
|
|
|
|
namespace YLErp.DBModels
|
|
{
|
|
[Table("underlying_manager")]
|
|
[Serializable]
|
|
public partial class underlying_manager : DBModelWithOperator, IUnderlyingBasic, IDataTraceV2, IClonable<underlying_manager>
|
|
{
|
|
public static string LogClass = "标的管理";
|
|
|
|
public const string Status_Working = "正常运行";
|
|
public const string Status_Suspension = "停牌";
|
|
public const string Status_Delisting = "退市";
|
|
|
|
/// <summary>
|
|
/// 是否主合约,需要在下拉框中显示
|
|
/// </summary>
|
|
[NotMapped]
|
|
public bool IsMainContract { get; set; }
|
|
|
|
[NotMapped]
|
|
public int? order { get; set; }
|
|
|
|
/// <summary>
|
|
/// 波动率变化(百分比数值)
|
|
/// </summary>
|
|
[DisplayName("Span波动率变动")]
|
|
public string VolatilityRate { get; set; }
|
|
|
|
/// <summary>
|
|
/// 涨跌停板幅度
|
|
/// </summary>
|
|
[DisplayName("Span涨跌幅度")]
|
|
public string UpDownLimit { get; set; }
|
|
|
|
/// <summary>
|
|
/// 1为启用,其它不用
|
|
/// </summary>
|
|
[DisplayName("启用状态")]
|
|
public string LaunchState { get; set; }
|
|
|
|
[DisplayName(" ")]
|
|
public string UnderlyingInstrumentType { get; set; }
|
|
|
|
[DisplayName("股票收益率")]
|
|
public double? DividendRate { get; set; }
|
|
|
|
[DisplayName("最后更新时间")]
|
|
public DateTime? LastUpdateTime { get; set; }
|
|
|
|
[DisplayName("市场码")]
|
|
public string MarketCode { get; set; }
|
|
|
|
[DisplayName("品种")]
|
|
public string CommodityCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// 预付金比例(百分比数值)
|
|
/// </summary>
|
|
[DisplayName("预付金比例")]
|
|
public double? MarginRate { get; set; }
|
|
|
|
[DisplayName("上一个交易日的收盘价")]
|
|
public double? PrevClosePrice { get; set; }
|
|
|
|
/// <summary>
|
|
/// 市场
|
|
/// </summary>
|
|
[DisplayName("市场")]
|
|
public string MarketName { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的资产码
|
|
/// </summary>
|
|
[DisplayName("标的资产码"), Required]
|
|
public string UnderlyingCode { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的品种类型
|
|
/// </summary>
|
|
[DisplayName("品种类型")]
|
|
public string UnderlyingType { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的资产到期日
|
|
/// </summary>
|
|
[DisplayName("到期日")]
|
|
public DateTime? MaturityDate { set; get; }
|
|
|
|
/// <summary>
|
|
/// 中金远期标的交割日
|
|
/// </summary>
|
|
[DisplayName("交割日")]
|
|
public DateTime? CloseDate { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的资产状态 Live ,Matured
|
|
/// </summary>
|
|
[DisplayName("资产状态")]
|
|
public string UnderlyingState { set; get; }
|
|
|
|
public string GetUnderlyingStateDesc()
|
|
{
|
|
switch (UnderlyingState?.ToLowerInvariant())
|
|
{
|
|
case "live": return "正常";
|
|
case "matured": return "已过期";
|
|
default: return UnderlyingState;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否为连续合约
|
|
/// </summary>
|
|
public bool IsVirtualContract()
|
|
{
|
|
return (UnderlyingCode + "").EndsWith("00");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 交易代码
|
|
/// </summary>
|
|
[DisplayName("交易代码")]
|
|
public string TradeCode { set; get; }
|
|
|
|
/// <summary>
|
|
/// 描述
|
|
/// </summary>
|
|
[DisplayName("描述")]
|
|
public string UnderlyingDesc { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的名
|
|
/// </summary>
|
|
[DisplayName("标的名称")]
|
|
public string UnderlyingName { set; get; }
|
|
|
|
|
|
/// <summary>
|
|
/// 标的英文名
|
|
/// </summary>
|
|
[NotMapped]
|
|
[DisplayName("标的英文名")]
|
|
public string UnderlyingEnName { set; get; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[DisplayName("资产品种类型")]
|
|
public int UnderlyingTypeId { set; get; }
|
|
|
|
/// <summary>
|
|
/// 标的资产状态 正常运行 停牌 退市
|
|
/// </summary>
|
|
[DisplayName("运行状态")]
|
|
public string UnderlyingStatus { set; get; }
|
|
|
|
/// <summary>
|
|
/// 板块性质1
|
|
/// </summary>
|
|
public int Block1 { get; set; }
|
|
|
|
/// <summary>
|
|
/// 板块性质2
|
|
/// </summary>
|
|
public int Block2 { get; set; }
|
|
|
|
/// <summary>
|
|
/// 板块性质3
|
|
/// </summary>
|
|
public int Block3 { get; set; }
|
|
|
|
/// <summary>
|
|
/// 板块性质4
|
|
/// </summary>
|
|
public int Block4 { get; set; }
|
|
|
|
/// <summary>
|
|
/// 板块性质5
|
|
/// </summary>
|
|
public int Block5 { get; set; }
|
|
|
|
//-------------
|
|
//2020/5/14 新增字段TradeUnit和QuoteUnit
|
|
//--------------
|
|
/// <summary>
|
|
/// 交易单位
|
|
/// </summary>
|
|
public string TradeUnit { get; set; }
|
|
|
|
/// <summary>
|
|
/// 交易单位
|
|
/// <para>kg:千克</para>
|
|
/// </summary>
|
|
public string TradeUnitString
|
|
{
|
|
get
|
|
{
|
|
switch (TradeUnit ?? "")
|
|
{
|
|
case "kg":
|
|
return "千克";
|
|
default:
|
|
return TradeUnit;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string QuoteUnit { get; set; }
|
|
|
|
/// <summary>
|
|
/// 报价单位
|
|
/// <para>500千克:半吨</para>
|
|
/// <para>kg:千克</para>
|
|
/// </summary>
|
|
public string QuoteUnitString
|
|
{
|
|
get
|
|
{
|
|
switch (QuoteUnit ?? "")
|
|
{
|
|
case "500千克":
|
|
return "半吨";
|
|
case "kg":
|
|
return "千克";
|
|
default:
|
|
return QuoteUnit;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 合约乘数(这个不要随意修改以保证TradeLotsCalc能够正确计算)
|
|
/// </summary>
|
|
[DisplayName("合约乘数")]
|
|
public double ContractSize { get; set; }
|
|
|
|
/// <summary>
|
|
/// 最小价格变动单位
|
|
/// </summary>
|
|
public double PriceTick { get; set; }
|
|
|
|
/// <summary>
|
|
/// 上市日期
|
|
/// </summary>
|
|
[DisplayName("上市日期")]
|
|
public DateTime? OpenDate { get; set; }
|
|
|
|
/// <summary>
|
|
/// 标的价格,即时价格 SpotPrice
|
|
/// </summary>
|
|
[DisplayName("标的价格")]
|
|
public double? Price { get; set; }
|
|
|
|
/// <summary>
|
|
/// 组合数据(JSON数据:[{code,weight}...])
|
|
/// </summary>
|
|
public string SubData { get; set; }
|
|
|
|
/// <summary>
|
|
/// 价格涨幅阈值
|
|
/// </summary>
|
|
public double PriceIncreaseRate { get; set; }
|
|
|
|
/// <summary>
|
|
/// 价格跌幅阈值
|
|
/// </summary>
|
|
public double PriceDecreaseRate { get; set; }
|
|
|
|
/// <summary>
|
|
/// DeltaS/S
|
|
/// <para>用于计算PFE(潜在风险暴露)是使用的值,是协会通用要求,目前仅长江用到,</para>
|
|
/// <para>该值不存在时:股指取Span预付金率;其他取</para>
|
|
/// </summary>
|
|
[DisplayName("DeltaS/S")]
|
|
public double? DeltaS_S{get;set;}
|
|
|
|
public string ExJson { get; set; }
|
|
|
|
/// <summary>
|
|
/// 基础点差
|
|
/// </summary>
|
|
[DisplayName("基础点差")]
|
|
public double Spread { get; set; }
|
|
|
|
/// <summary>
|
|
/// 撮合点差
|
|
/// </summary>
|
|
[DisplayName("撮合点差")]
|
|
public double SpreadM { get; set; }
|
|
|
|
/// <summary>
|
|
/// 最小数量
|
|
/// </summary>
|
|
[DisplayName("最小数量")]
|
|
public int VolumeMin { get; set; }
|
|
|
|
/// <summary>
|
|
/// 最大数量
|
|
/// </summary>
|
|
[DisplayName("最大数量")]
|
|
public int VolumeMax { get; set; }
|
|
|
|
/// <summary>
|
|
/// 步进数量
|
|
/// </summary>
|
|
[DisplayName("步进数量")]
|
|
public int VolumeStep { get; set; }
|
|
|
|
/// <summary>
|
|
/// 限制数量
|
|
/// </summary>
|
|
[DisplayName("限制数量")]
|
|
public int VolumeLimit { get; set; }
|
|
|
|
public string UnderlyingPinYin { get; set; }
|
|
|
|
/// <summary>
|
|
/// 聚源内部id
|
|
/// </summary>
|
|
public long? InnerCode { get; set; }
|
|
|
|
/// <summary>
|
|
/// 债券增值税
|
|
/// </summary>
|
|
[Column("value_added_tax")]
|
|
[DisplayName("增值税率")]
|
|
public decimal? ValueAddedTax { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{UnderlyingCode}--{UnderlyingName}--{id}--{UnderlyingInstrumentType}";
|
|
}
|
|
|
|
public string GetDataTraceKeyId()
|
|
{
|
|
return id.ToString();
|
|
}
|
|
|
|
public string GetDataTraceKeyInfo()
|
|
{
|
|
return "标的资产:" + UnderlyingCode;
|
|
}
|
|
}
|
|
|
|
public partial class underlying_manager : IComparable<underlying_manager>
|
|
{
|
|
public int CompareTo(underlying_manager other)
|
|
{
|
|
if (other.UnderlyingState == "Matured" && UnderlyingState != "Matured")
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
if (other.UnderlyingState == UnderlyingState)
|
|
{
|
|
return id - other.id;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
public const string 除权中 = "除权中";
|
|
|
|
/// <summary>
|
|
/// 新增标的时默认价格,行情服务应该修改这个价格,如果找不到就一直是这个数字
|
|
/// </summary>
|
|
public const double DefaultSpotPrice = 999999;
|
|
|
|
/// <summary>
|
|
/// 标的状态
|
|
/// </summary>
|
|
public static readonly List<string> UnderlyingStates = new List<string> { "Live", "Matured" };
|
|
|
|
public static readonly List<string> UnderlyingStatusList = new List<string> { "正常运行", "停牌", "退市" };
|
|
|
|
[DisplayName("资产类型")]
|
|
[NotMapped]
|
|
public string UnderlyingInstrumentTypeCn => ConsGlobal.InstrumentType.GetDesc(UnderlyingInstrumentType);
|
|
|
|
/// <summary>
|
|
/// 品种
|
|
/// </summary>
|
|
[NotMapped]
|
|
public Variety Variety { get; set; }
|
|
|
|
/// <summary>
|
|
/// 行权日
|
|
/// </summary>
|
|
[NotMapped]
|
|
public DateTime? ExerciseDate { get; set; }
|
|
|
|
/// <summary>
|
|
/// 报价日
|
|
/// </summary>
|
|
[NotMapped]
|
|
public DateTime? QuotationDate { get; set; }
|
|
|
|
private int countRatio = 1;
|
|
|
|
/// <summary>
|
|
/// 数量转为份额的乘积因子(notional=amount*ratio)
|
|
/// 此属性的值必然大于0
|
|
/// </summary>
|
|
[NotMapped]
|
|
public int CountRatio
|
|
{
|
|
get { return countRatio; }
|
|
set { countRatio = value < 1 ? 1 : value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拼音首字母
|
|
/// </summary>
|
|
[NotMapped]
|
|
public string PinYinFirst { get; set; }
|
|
|
|
public underlying_manager Clone()
|
|
{
|
|
return (underlying_manager)MemberwiseClone();
|
|
}
|
|
|
|
#region----UnderlyingInstrumentType类型判断----
|
|
|
|
/// <summary>
|
|
/// 标的是否是商品类型
|
|
/// </summary>
|
|
public bool IsCommodity()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsCommodityFutures(UnderlyingInstrumentType)
|
|
|| ConsGlobal.InstrumentType.IsCommoditySpot(UnderlyingInstrumentType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否是商品现货
|
|
/// </summary>
|
|
public bool IsCommoditySpot()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsCommoditySpot(UnderlyingInstrumentType);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 标的是否是商品期货
|
|
/// </summary>
|
|
public bool IsCommodityFutures()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsCommodityFutures(UnderlyingInstrumentType);
|
|
}
|
|
/// <summary>
|
|
/// 标的是否是股票类型
|
|
/// </summary>
|
|
public bool IsStock()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsStock(UnderlyingInstrumentType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否是股指类型
|
|
/// </summary>
|
|
public bool IsStockIndex()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsStockIndex(UnderlyingInstrumentType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的计算方式是否是股票(权益)类型
|
|
/// </summary>
|
|
public bool CalcTypeIsStock()
|
|
{
|
|
return ConsGlobal.InstrumentType.CalcTypeIsStock(UnderlyingInstrumentType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否是股票指数期货类型
|
|
/// </summary>
|
|
public bool IsStockIF()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsStockIF(UnderlyingInstrumentType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否期货类型
|
|
/// </summary>
|
|
public bool IsFutures()
|
|
{
|
|
return ConsGlobal.InstrumentType.CalcTypeIsFutures(UnderlyingInstrumentType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否债券类型
|
|
/// </summary>
|
|
public bool IsBond()
|
|
{
|
|
return ConsGlobal.InstrumentType.IsBond(UnderlyingInstrumentType);
|
|
}
|
|
|
|
public string GetMainType()
|
|
{
|
|
switch (UnderlyingInstrumentType)
|
|
{
|
|
case "Stock":
|
|
case "StockIndex":
|
|
case ConsGlobal.InstrumentType.FixingRepoRate:
|
|
return "Stock";
|
|
case "StockIF":
|
|
case "CommodityFutures":
|
|
return "CommodityFutures";
|
|
case "CommoditySpot":
|
|
return "CommoditySpot";
|
|
case "Shibor":
|
|
return "Stock";
|
|
default:
|
|
return UnderlyingInstrumentType;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否是组合标的
|
|
/// </summary>
|
|
public bool IsSynthetic()
|
|
{
|
|
return CommodityCode == "组合标的";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否是组合标的
|
|
/// </summary>
|
|
public bool IsBasket()
|
|
{
|
|
return CommodityCode == "篮子标的";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标的是否是合成标的(组合OR篮子)
|
|
/// </summary>
|
|
public bool IsCombined()
|
|
{
|
|
return CommodityCode == "组合标的" || CommodityCode == "篮子标的";
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 获取价格涨跌幅度
|
|
/// </summary>
|
|
public double GetPriceChangePercent()
|
|
{
|
|
return Price.HasValue && PrevClosePrice.HasValue && Math.Abs(PrevClosePrice.Value) > 0.00001
|
|
? OtcFormatHelper.FormatValue(Price.Value / PrevClosePrice.Value - 1, 4) : 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// BBG Ticker
|
|
/// </summary>
|
|
[DisplayName("BBG Ticker")]
|
|
public string BBGTicker { get; set; }
|
|
|
|
/// <summary>
|
|
/// 债券全名
|
|
/// </summary>
|
|
[NotMapped]
|
|
public string UnderlyingFullName { get; set; }
|
|
/// <summary>
|
|
/// 标的发行量(亿)
|
|
/// </summary>
|
|
[NotMapped]
|
|
public decimal? IssueSize { get; set; }
|
|
/// <summary>
|
|
/// 标的证券发行人
|
|
/// </summary>
|
|
[NotMapped]
|
|
public string UnderlyingIssuer { get; set; }
|
|
}
|
|
|
|
[NotMapped]
|
|
public class UnderlyingManagerDto : underlying_manager
|
|
{
|
|
public IEnumerable<HistoryData> HisDataList { get; set; }
|
|
}
|
|
}
|