using YLErp.Commons; using YLErp.DBModels.Helpers; using YLErp.Helpers; namespace YLErp.Model { public class EodPositionModelBase { private string _tradeJson; public int? ClientId { get; set; } public DateTime? ValueDate { get; set; } public string UnderlyingCode { get; set; } public string UnderlyingAssetName => trade?.UnderlyingAssetName; public int TradeId { get; set; } public string TradeType { get; set; } public string TradeNumber { get; set; } public string TradeContractCode { get; set; } public double? UnderlyingPrice { get; set; } public string BasisUnderlyingCode { get; set; } public string BasisUnderlyingName { get; set; } public double? BasisGap { get; set; } public double? Lots { get; set; } /// /// 交易预付金 /// public double? Margin { get; set; } /// /// 持仓实现金额(目前指持仓时的票息和互换金额) /// public double? PositionRelizedAmount { get; set; } /// /// 报价单位 /// public string QuoteUnitSingle { get; set; } /// /// 交易所代码 /// public string MarketCode { get; set; } //--------------------------------------------- internal string TradeJson { get => _tradeJson; set { _tradeJson = value; _trade = null; } } internal trade tradeOrigin { get; set; } trade _trade; public trade trade { get { if (_trade != null) { return _trade.IsDefault() ? null : _trade; } //优先从TradeJson取数据; if (!string.IsNullOrEmpty(TradeJson)) { try { return _trade = TradeHelper2.Deserialize(TradeJson); } catch (Exception e) { LogFactory.GetLogger().Error("EodTrade Trade", e); } } if (tradeOrigin != null) { return _trade = tradeOrigin; } _trade = trade.Default; return null; } } public string ExerciseMode => trade?.ExerciseMode; public string OptionType => trade?.OptionType; public bool? IsUsePremiumRate => trade?.IsUsePremiumRate; public double? PremiumRate => trade?.PremiumRate; public double? SpotPrice => trade?.SpotPrice; public double? Strike => trade?.Strike; public string StrikeToShow => trade?.StrikeToShow; public string IsMoneynessOption => trade?.IsMoneynessOption; /// /// 从客户角度看,方向转换 /// public string BuySell => trade != null ? trade.BuySell == "买入" ? "卖出" : "买入" : null; private Dictionary _dic; public Dictionary dic { get => _dic ?? (_dic = new Dictionary()); set => _dic = value; } //--------------------------------------------- public override string ToString() { return $"{TradeNumber}--{TradeType}--{TradeId}--{ClientId}"; } } public class eod_position : EodPositionModelBase { /// /// 加密TradeId /// public string EncryptTradeId => DataProtectHelper.Encrypt(TradeId); public DateTime? TradeDate { get; set; } public DateTime? ExerciseDate { get; set; } public string ClientName { get; set; } public double AnnualizeFactor { get; set; } public double ParticipationRate { get; set; } public double PrincipalRate { get; set; } public double NoRiskRate { get; set; } /// /// 双向预付金 /// public int? MarginOptionType { get; set; } public double? ExercisePrice => trade?.Strike; public double? Notional => trade != null ? trade.Notional : (double?)null; public double? TradeAmount => trade?.TradeAmount; public double? TradePrice { get { if (trade == null) { return null; } else if (trade.TradeType == "远期") { return trade.TradePrice * -1;//结算报告:资金明细。远期交易总额为客户付出的开仓费用。 } else { return trade.TradePrice * ("卖出".Equals(trade.BuySell) ? -1 : 1); } } } public double? CurrentPrice { get { if (trade == null) { return null; } //RoundedPv是客户方向,先反向取交易员方向,再算出单价再加负号变成客户方向 var tradeSinglePrice = -TradeHelper.GetTradeSinglePriceByTradePrice(-(YLErp.PS.Config.IsPVRounded ? RoundedPv : Pv), trade.Notional, PS.Config.ErpElement.IsPVIncludePrincipal ? trade.PrincipalSum() : 0, trade.BuySell, trade.TradeType, false); return tradeSinglePrice; } } public double? Pv { get; set; } public double? RoundedPv { get; set; } public double? Pnl { get; set; } public double? RoundedPnl { get; set; } public double? PvDouble { get; set; } public double? RoundedPvDouble { get; set; } public double? PnlDouble { get; set; } public double? RoundedPnlDouble { get; set; } //数据如果不对就解决不要依靠其他数据合成 public double? StockEqvNotional => trade == null ? null : trade.StockEqvNotional / trade.OriginalStockEqvNotional * trade.OriginalStockEqvNotionalV2; //数据如果不对就解决不要依靠其他数据合成 public double? OriginalStockEqvNotional => trade?.OriginalStockEqvNotionalV2; public double? InitialSpotPrice => trade?.SpotPrice ?? 0; public double? Strike => trade != null ? trade.IsMoneynessOptionData ? trade.Strike * trade.SpotPrice : trade.Strike : null; public double? TradeSinglePrice => trade?.TradeSinglePrice ?? 0; public string CallPut => trade?.OptionType; public string TradeMultipleType => trade?.TradeMultipleType; public double? TradeOriginalAmount => trade != null ? CountRatio > 0 ? trade.OriginalNotional / CountRatio : trade.OriginalNotional : null; public string SyntheticUnderlyingTipsInfo { get; set; } /// /// 持仓波动率 /// public double? Vol { get; set; } /// /// 开仓波动率 /// public double? TradeOpenVolatility => trade?.TradeOpenVolatility; public double? Delta { get; set; } public double? Gamma { get; set; } public double? Theta { get; set; } public double? Vega { get; set; } public double? Rho { get; set; } public double? GammaCash { get; set; } public string InstrumentType { get; set; } /// /// 合约乘数 /// public double ContractSize { get; set; } = 1; /// /// 乘积因子 /// public int CountRatio { get; set; } public string BBGTicker { get; set; } /// /// 客户端使用这个属性取TradeUnitValue /// public Variety2 Variety { get; set; } /// /// 是否为分组交易 /// public int IsGroup { get; set; } /// /// 客户预付金最大亏损 /// public double? MaxlossMargin { get; set; } /// /// 客户预付金最大亏损 /// public double? ChangeMargin { get; set; } /// /// 结算标识(0:正常结算,1:延期结算) /// public int SettlementFlag { get; set; } public string SettlementFlagStr { get { return SettlementFlag == 1 ? "是" : "否"; } } internal SettlementTypeEnum SettlementType { get; set; } /// /// 宏源 A/B团队 /// public string UserGroup { get; set; } public string UserGroupStr { get { if (!string.IsNullOrWhiteSpace(UserGroup) && PS.Config.Is宏源) { return UserGroup == "A" ? "A团队" : "B团队"; } else { return null; } } } } } /// /// 客户端取TradeUnitValue /// public class Variety2 { private double tradeUnitValue = 1; /// /// 合约乘数 /// public double TradeUnitValue { get => tradeUnitValue; set => tradeUnitValue = value < 1 ? 1 : value; } }