using BaseOUDAL; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text.RegularExpressions; using YLErp.Commons; using YLErp.Models.Tag; namespace YLErp.Model { /// /// 财务汇总 /// public abstract class FinancialSummaryModelBase { /// /// 交易份额 /// 未完结:本期末持仓数量 /// 已完结:本次交易数量 /// public double? Notional { get; set; } /// /// 成交日 /// public DateTime? TradeDate { get; set; } /// /// 清算日期 /// public DateTime? ClearDate { get; set; } /// /// 买卖方向-交易所 /// public string TradeDirection { get; set; } /// /// 标的代码 /// public string UnderlyingCode { get; set; } /// /// 名义本金(期初价格) /// public double? StockEqvNotional { get; set; } /// /// 名义本金(执行价格) /// public double? StockEqvNotional2 { get; set; } /// /// 名义本金(期初价格:合成标的时取最大价格) /// public double? StockEqvNotional3 { get; set; } /// /// 交易总额 /// public double? TradePrice { get; set; } /// /// 清算金额 /// public double? ClearPrice { get; set; } /// /// 手续费 /// public double? ServiceFee { get; set; } /// /// 存续名义本金 /// public double? SurvivingNominalPrincipal { get; internal set; } } /// /// 财务汇总-场外期权 /// 含远期和掉期 /// public class FinancialSummaryOptionModel : FinancialSummaryModelBase { /// /// 上期期末日期 /// public DateTime PreLastDate { get; set; } /// /// 客户Id /// public int ClientId { get; set; } /// /// 对应的交易编号 /// public int TradeId { get; set; } public double? NewTotalPnl { get; set; } /// /// 主交易编号 /// public int ParentTradeId { get; set; } /// /// 对应的开仓时资金记录编号 /// public int TradeOpenCashId { get; set; } /// /// 对应的资金记录编号 /// public int TradeCloseCashId { get; set; } /// /// 合约乘数 /// public double ContractSize { get; set; } /// /// 成交手数 /// public double OriginalLots { get; set; } /// /// 交易手数 /// public double Lots { get; set; } /// /// 持仓手数 /// public double PositionLots { get; set; } /// /// 成交份额 /// public double OriginalNotional { get; set; } /// /// 成交数量 /// public double OriginalAmount { get; set; } /// /// 持仓数量 /// public double PositionAmount { get; set; } /// /// 看涨看跌 /// public string OptionType { get; set; } /// /// 客户名称-全称 /// public string ClientFullName { get; set; } /// /// 交易编号 /// public string TradeNumber { get; set; } /// /// 确认书编号 /// public string ContractCode { get; set; } /// /// 结算确认书编号 /// public string SettlementCode { get; set; } /// /// 状态 /// True:完结 /// False:未完结 /// public bool Status { get; set; } public string StatusStr { get; set; } /// /// 客户名称-简称 /// public string ClientShortName { get; set; } /// /// 到期日 /// public DateTime? ExerciseDate { get; set; } /// /// 行权方式 /// public string ExerciseMode { get; set; } /// /// 收益总额 /// /// 已完结:交易总额 + 清算金额 /// 未完结:Null /// /// public double? ConfirmPnl { get { return Status ? TradePrice.FormatValue(2) + ClearPrice.FormatValue(2) : null; } } public double? ConfirmTotlePnl { get; set; } /// /// 上期期末市值 /// public double? LastPv { get; set; } private double? _lastTotalPnl = null; /// /// 上期期末累计浮动盈亏 /// 上期期末市值=0:0 /// 上期期末市值!=0: /// 卖出:交易价格-上期期末市值 /// 非卖出:交易价格+上期期末市值 /// /// 3.10版本财务汇总页面场外期权和远期交易中该字段算法改为Eod_Trade_Position表里的AccruedTotalPnl字段 /// /// public double? LastTotalPnl { get { if ((_lastTotalPnl == null && !PS.Config.Is广发商贸) || (PS.Config.Is广发商贸 && TradeDate <= PreLastDate)) { _lastTotalPnl = TradePrice.FormatValue(2) + LastPv.FormatValue(2); } return _lastTotalPnl; } set => _lastTotalPnl = value; } /// /// 本期期末市值 /// public double? Pv { get; set; } public int CountRatio { get; set; } public double? _totalPnl = null; /// /// 本期期末累计浮动盈亏 /// 本期期末市值=0:0 /// 本期期末市值!=0: /// 卖出:交易价格-本期期末市值 /// 非卖出:交易价格+本期期末市值 /// /// 3.10版本财务汇总页面场外期权和远期交易中该字段算法改为Eod_Trade_Position表里的AccruedTotalPnl字段 /// /// public double? TotalPnl { get { if (_totalPnl == null) { _totalPnl = TradePrice.FormatValue(2) + Pv.FormatValue(2); } return Status ? 0 : _totalPnl; } set => _ = value; } /// /// 本期浮动盈亏 /// /// 未完结:本期期末累计浮动盈亏 - 上期期末累计浮动盈亏 /// 已完结-光子:本期期末累计浮动盈亏 - 上期期末累计浮动盈亏 /// 已完结:交易总额 + 清算金额 - 上期期末累计浮动盈亏 /// /// public double? Pnl { get { if (!Status || PS.Config.Is光大光子)//光子已完结和未完结计算逻辑一致; { return TotalPnl.FormatValue(2) - LastTotalPnl.FormatValue(2); } else { return ConfirmPnl.FormatValue(2) - LastTotalPnl.FormatValue(2); } } set => _ = value; } public double? GF_Pnl { get; set; } /// /// 期货盈亏 /// public double? FuturePnl { get; set; } /// /// 费后总盈亏 /// /// 已完结:收益总额 + 期货盈亏 - 手续费 /// 未完结:本期期末累计浮动盈亏 + 期货盈亏 - 手续费 /// /// public double? TotalPnlAfterExpense { get { return Status ? ConfirmPnl.FormatValue(2) + FuturePnl.FormatValue(2) - ServiceFee.FormatValue(2) : TotalPnl.FormatValue(2) + FuturePnl.FormatValue(2) - ServiceFee.FormatValue(2); } set => _ = value; } /// /// 可用资金(财务) /// public double AvailableCash { get; set; } /// /// 期末结存(财务) /// public double EndBalance { get; set; } /// /// 交易确认书状态 /// public string TradeConfirmFileStatus { get; set; } /// /// 清算确认书状态 /// public string ClearConfirmFileStatus { get; set; } /// /// 财务入账 /// public double? FinancialEntry { get; set; } /// /// 交易确认日期-财务 /// public DateTime? TradeConfirmDate { get; set; } /// /// 了结确认日期 /// public DateTime? ClearConfirmDate { get; set; } /// /// 结构类型 /// public string StructureType { get; set; } /// /// 交易数量 /// public double TradeAmount { get; set; } public string UnderlyingInstrumentType{ get; set; } public string TradeType { get; set; } public string VarietyCode { get; set; } /// /// 客户标签 /// [NotMapped] public List Tags { get; set; } /// /// 客户标签 /// [NotMapped] public string OutputTags { get; set; } /// /// 簿记账户 /// [NotMapped] public string AssetBookName { get; set; } /// /// 簿记账户id /// [NotMapped] public int AssetId { get; set; } public double DailyPnL { get; internal set; } public string ExchangeCode { get; internal set; } } /// /// 财务汇总-场内期权 /// public class FinancialSummaryExchangeModel : FinancialSummaryModelBase { /// /// 交易所代码 /// public string ExchangeOptionCode { get; set; } /// /// 期权类型 /// public string OptionType { get; set; } /// /// 行权价 /// public double? Strike { get; set; } /// /// 权利金单价 /// public double? TradeSinglePrice { get { double? result = null; if (TradePrice != null && TradeUnit != null) { result = Math.Abs((TradePrice.FormatValue(2) / TradeUnit.FormatValue(2) / Notional.FormatValue(2)) ?? 0); } return result; } } /// /// 吨/手 /// public double? TradeUnit { get; set; } /// /// 名义本金 /// public new double? StockEqvNotional { get { return Strike.FormatValue(2) * Notional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 上期末日期 /// public DateTime PreLastDate { get; set; } /// /// 上期期末报价 /// public double? PrePotionLastPrice { get; set; } /// /// 上期浮动盈亏 /// public double? PrePotionLastPnl { get { if (TradeDate > PreLastDate || !PrePotionLastPrice.HasValue) { return null; } return (PrePotionLastPrice.FormatValue(2) - TradeSinglePrice.FormatValue(4)) * Notional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 本期末日期 /// public DateTime PreDate { get; set; } /// /// 本期期末报价 /// public double? PrePotionEndPrice { get; set; } /// /// 本期浮动盈亏 /// public double? PrePotionEndPnl { get { if (TradeDate > PreDate || !PrePotionEndPrice.HasValue) { return null; } double? price = TradeDate <= PreLastDate ? PrePotionLastPrice : TradeSinglePrice; return (PrePotionEndPrice.FormatValue(2) - price.FormatValue(4)) * Notional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 平仓买卖方向 /// public string UnwindTradeDirection { get; set; } /// /// 平仓权利金单价 /// public double? UnwindTradeSinglePrice { get { return ClearPrice.FormatValue(2) / UnwindNotional.FormatValue(2) / TradeUnit.FormatValue(2); } } /// /// 平仓成交量 /// public double? UnwindNotional { get; set; } /// /// 平仓手续费 /// public double? UnwindServiceFee { get; set; } /// /// 平仓对应初始权利金 /// public double? UnwindOriginalTradePrice { get { return UnwindNotional.FormatValue(2) * TradeSinglePrice.FormatValue(4) * TradeUnit.FormatValue(2); } } /// /// 平仓本期浮动盈亏 /// public double? UnwindEndPnl { get { double? price = TradeDate <= PreDate ? PrePotionEndPrice : TradeSinglePrice; return (UnwindTradeSinglePrice.FormatValue(2) - price.FormatValue(4)) * UnwindNotional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 平仓盈亏 /// public double? UnwindPnl { get { return ClearPrice.FormatValue(2) - UnwindOriginalTradePrice.FormatValue(2); } } /// /// 期末持仓期末结算价 /// public double? PositionEndSettlementPrice { get; set; } /// /// 持仓数(手) /// public double? PositionNotional { get; set; } /// /// 持仓期末市值 /// public double? PositionEndPv { get { return PositionEndSettlementPrice.FormatValue(2) * PositionNotional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 持仓对应初始权利金 /// public double? PositionOriginalTradePrice { get { return PositionNotional.FormatValue(2) * TradeUnit.FormatValue(2) * TradeSinglePrice.FormatValue(4); } } /// /// 持仓公允价值变动 /// public double? PositionPvOffset { get { double? price = TradeDate <= PreDate ? PrePotionEndPrice : TradeSinglePrice; return (PositionEndSettlementPrice.FormatValue(2) - price.FormatValue(4)) * PositionNotional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 持仓名义本金 /// public double? PositionStockEqvNotional { get { return Strike.FormatValue(2) * PositionNotional.FormatValue(2) * TradeUnit.FormatValue(2); } } /// /// 簿记账户 /// public string AssetBookName { get; set; } } public class FinancialSummaryModelReq : BaseSearchReq { /// /// 本期范围-开始 /// public DateTime CurrentPeriodDateStart { get; set; } /// /// 本期范围-结束 /// public DateTime CurrentPeriodDateEnd { get; set; } public string SummaryType { get; set; } public string ClientIds { get; set; } /// /// 客户Id /// public List ClientIdList { get { if (ClientIds == null || !Regex.IsMatch(ClientIds, @"^(\d+,?)+$")) { return new List(); } List list = Array.ConvertAll(ClientIds.Split(','), O => int.Parse(O)).ToList(); return list; } } /// /// 交易日期 /// public string TradeNumber { get; set; } /// /// 确认书编号 /// public string ContractCode { get; set; } /// /// 交易日期-开始 /// public DateTime TradeDateStart { get; set; } /// /// 交易日期-结束 /// public DateTime TradeDateEnd { get; set; } /// /// 到期日-开始 /// public DateTime ExerciseDateStart { get; set; } /// /// 到期日-结束 /// public DateTime ExerciseDateEnd { get; set; } /// /// 清算日期-开始 /// public DateTime ClearDateStart { get; set; } /// /// 清算日期-结束 /// public DateTime ClearDateEnd { get; set; } /// /// 交易确认日期-开始 /// public DateTime TradeConfirmDateStart { get; set; } /// /// 交易确认日期-结束 /// public DateTime TradeConfirmDateEnd { get; set; } /// /// 了结确认日期-开始 /// public DateTime ClearConfirmDateStart { get; set; } /// /// 了结确认日期-结束 /// public DateTime ClearConfirmDateEnd { get; set; } /// /// 期权类型 /// public List TradeTypeList { get; set; } /// /// 上期日期1 /// public DateTime PreLastPartDate { get; set; } /// /// 上期日期2 /// public DateTime LastPartDate { get; set; } /// /// 交易状态 /// public string TradeStatus { get; set; } /// /// 开仓数据 /// 查询开仓数据时,一个交易编号只显示一条数据; /// public bool IsOpen { get; set; } public List UserAssets { get; set; } /// /// 簿记账户组筛选 /// public List AssetIdGroupList { get; set; } /// /// 簿记账户信息 /// public List BookIds { get; set; } public List UserClients { get; set; } public List CurUserTradeIds { get; set; } /// /// 标签值 /// public List TagIds { get; set; } /// /// 客户标签值 /// public List ClientTagIds { get; set; } /// /// 品种代码 /// public string VarietyCode { get; set; } /// /// 品种名称 /// public string VarietyName { get; set; } } }