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