using System.ComponentModel.DataAnnotations.Schema; namespace YLErp.DBModels { /// /// 客户结算统计 /// [Table("clientbalancedaily")] public class ClientBalanceDaily : DBModelWithOperator { [DisplayName("预付金")] public double? CashDeposit { get; set; } [DisplayName("授信额度")] public double? Credit { get; set; } /// /// 追保金额(所有欠缺金额) /// [DisplayName("追保金额")] public double? Margin { get; set; } [NotMapped] public double MarginAbs { get { return Math.Abs(Margin ?? 0); } } /// /// 客户信息 /// [DisplayName("客户信息")] public int ClientId { get; set; } /// /// 客户名称 /// [DisplayName("客户名称")] public string ClientName { get; set; } /// /// 客户编号 /// [DisplayName("客户编号")] public string ClientNumber { get; set; } /// /// 结算日期 /// [DisplayName("结算日期")] public DateTime? BalanceDate { get; set; } /// /// 上日资金余额 /// [DisplayName("上日资金余额")] public double? LastDayRemainFund { get; set; } /// /// 上日资金余额(包含抵押品价值) /// [NotMapped] public double? LastDayRemainFundWithProduct { get { return LastDayRemainFund + TodayRemianFundProduct - CashInCashOutProductChange; } } /// /// 当日资金余额(不包含抵押品价值) /// [DisplayName("当日资金余额")] public double? ToDayRemainFund { get; set; } /// /// 当日资金余额(包含抵押品价值) /// [NotMapped] public double? ToDayRemainFundWithProduct { get { return ToDayRemainFund + TodayRemianFundProduct; } } /// /// 当日入金 /// [DisplayName("当日入金")] public double? InFund { get; set; } /// /// 当日出金 /// 为绝对值,不包含出金方向 /// [DisplayName("当日出金")] public double? OutFund { get; set; } /// /// 其他收入 /// [DisplayName("其他收入")] public double? InFundOther { get; set; } /// /// 其他支出 /// [DisplayName("其他支出")] public double? OutFundOther { get; set; } /// /// 当日损益 /// private double? _DayGainLoss; /// /// 当日损益 /// [DisplayName("当日损益")] public double? DayGainLoss { set { _DayGainLoss = value; } get { return _DayGainLoss == null ? _DayGainLoss : Round(_DayGainLoss.Value, 2); } } /// /// 持仓盈亏 /// private double? _PositionPnl; /// /// 持仓盈亏 /// [DisplayName("持仓盈亏")] public double? PositionPnl { set { _PositionPnl = value; } get { return _PositionPnl == null ? _PositionPnl : Round(_PositionPnl.Value, 2); } } /// /// 四舍五入处理后的持仓盈亏 /// public double? RoundedPositionPnl { get; set; } /// /// 期权空头浮动盈利=∑max(期权空头持仓*(期权合约成本价-期权合约现价), 0) 从客户角度看的 /// public double? ClientSellPositionPnl { get; set; } /// /// 总盈亏 /// private double? _TotalPnl; /// /// 总盈亏 /// [DisplayName("总盈亏")] public double? TotalPnl { set { _TotalPnl = value; } get { return _TotalPnl == null ? _TotalPnl : Round(_TotalPnl.Value, 2); } } //每日盈亏 [DisplayName("每日盈亏")] public double? DailyPnl { get; set; } [NotMapped] public double? RoundedDailyPnl { get; set; } /// /// 状态 /// [DisplayName("状态")] public string State { get; set; } ///// ///// 确认人 ///// //[DisplayName("确认人")] //public int? ConfirmerId { get; set; } ///// ///// 确认人 ///// //[DisplayName("确认人")] //public string ConfirmerName { get; set; } ///// ///// 结算书 ///// //[DisplayName("结算书")] //public string ConfirmBookHtml { get; set; } [NotMapped] public double? Amount { get; set; } /// /// 期权费收支 /// [DisplayName("期权费收支")] public double? OptionPremium { get; set; } /// /// 期权费收支(互换) /// [DisplayName("收益互换期权费")] public double? OptionPremiumSwap { get; set; } /// /// 结算收支 /// [DisplayName("结算收支")] public double? SettlementBalance { get; set; } /// /// 当日平仓收益 /// [DisplayName("当日平仓收益")] public double? UnwindBalance { get; set; } /// /// 当日行权收益 /// [DisplayName("当日行权收益")] public double? ExerciseBalance { get; set; } /// /// 当日互换收益 /// [DisplayName("当日互换收益")] public double? SwapBalance { get; set; } /// /// 净资金流入 /// [DisplayName("净资金流入")] public double? NetFund { get; set; } /// /// 其他收支 /// [DisplayName("其他收支")] public double? OtherFund { get; set; } /// /// 票息 /// [DisplayName("票息")] public double? Coupon { get; set; } /// /// 预付金余额 /// [DisplayName("预付金余额")] public double? MarginBalance { get; set; } /// /// 冻结权利金 /// [DisplayName("冻结权利金")] public double? FrozenPremium { get; set; } /// /// 冻结出金 /// [DisplayName("冻结出金")] public double? FrozenOutFund { get; set; } /// /// 冻结抵押品赎回 /// [DisplayName("冻结抵押品赎回")] public double? FrozenRedeemFunds { get; set; } /// /// 冻结资金 /// [DisplayName("冻结资金")] public double? FrozenBalance { get; set; } /// /// 应付到期权利金 /// [DisplayName("应付到期权利金")] public double? CopeWithExpirePremium { get; set; } /// /// 应付存续权利金 /// [DisplayName("应付存续权利金")] public double? CopeWithLastPremium { get; set; } /// /// 了结交易权利金 /// [DisplayName("了结权利金")] public double? EndPremium { get; set; } /// /// 潜在行权盈余 /// [DisplayName("潜在行权盈余")] public double? Pv { get; set; } /// /// 四舍五入处理后的持仓市值 /// public double? RoundedPv { get; set; } /// /// 空头持仓市值 /// [DisplayName("空头持仓市值")] public double? SellPv { get; set; } /// /// 当日该客户所有持仓的卖出期权权利金 /// [DisplayName("权利金冻结")] public double? SellTradePrice { get; set; } /// /// 客户权益(现金+持仓市值+抵押品总价值) /// [NotMapped] public double? TotalAmount { get { return (ToDayRemainFund ?? 0) + (Pv ?? 0) + (TodayRemianFundProduct ?? 0) - (PrepaymentAmount ?? 0); } } /// /// 客户权益(现金+四舍五入处理后的持仓市值+抵押品总价值) /// [NotMapped] public double? RoundedTotalAmount { get { return (ToDayRemainFund ?? 0) + (RoundedPv ?? 0) + (TodayRemianFundProduct ?? 0) - (PrepaymentAmount ?? 0); } } /// /// 未了结名义成交金额 /// [DisplayName("未了结名义成交金额")] public double? TotalNominal { get; set; } /// /// 应付预付金 /// 负数代表客户应缴预付金,正数代表客户应收预付金 /// [DisplayName("应付预付金")] public double? PayableMargin { get; set; } /// /// 互换应付预付金(要么为负,要么为零) /// [DisplayName("互换应付预付金")] public double? SwapPayableMargin { get; set; } /// /// 互换预付金容忍 /// [DisplayName("互换预付金容忍")] public double? SwapUnPayableMargin { get; set; } /// /// Delta预付金 /// 负数代表客户应缴预付金,正数代表客户应收预付金 /// public double? DeltaMargin { get; set; } /// /// 应付预付金(结算报告客户角度,正数代表他要付钱,负数代表应收) /// public double MinusPayableMargin { get { return -PayableMargin ?? 0; } } /// /// 双向预付金(暂时只有国君用到该字段) /// public double? TwoSideMargin { get; set; } /// /// 本方角度预付金 /// public double? MySideMargin { get; set; } /// /// 客户角度预付金 /// public double? OtherSideMargin { get; set; } /// /// 是否是手动修改过的预付金占用 /// public bool? IsPayableMarginManual { get; set; } /// /// 冻结预付金(绝对值) /// [DisplayName("冻结预付金")] public double? FrozenMarginMoney { get; set; } /// /// 可提取预付金 /// [DisplayName("可提取预付金")] public double? AdvisableMargin { get; set; } /// /// 抵押品变化 /// [DisplayName("抵押品变化")] public double? CashInCashOutProductChange { get; set; } /// /// 当日抵押品资金余额 /// [DisplayName("当日抵押品资金余额")] public double? TodayRemianFundProduct { get; set; } //是否期权费授信 [DisplayName("是否期权费授信")] public bool? IsTradeCredit { get; set; } /// /// 潜在行权盈余 /// [DisplayName("潜在行权盈余")] public double? PotentialSurpluses { get; set; } /// /// 持仓期权费净额 /// [DisplayName("持仓期权费净额")] public double? PositionPremiumNetCash { get; set; } /// /// 期初持仓交易净额 /// [DisplayName("期初持仓交易净额")] public double? LastDayPositionPremiumNetCash { get; set; } /// /// 实现盈亏 /// [DisplayName("实现盈亏")] public double? WinLoss { get; set; } /// /// 额外追保 /// [DisplayName("额外追保")] public double? AdditionalMargin { get; set; } /// /// 可用名义本金规模 /// public double? AvailableStockEqvNotional { get; set; } /// /// 潜在风险暴露 /// public double? PFE { get; set; } /// /// 违约风险暴露 /// public double? EAD { get; set; } //--------------------------------------- // 总和 //--------------------------------------- /// /// 净资金流入总和 /// public double? NetFundSum { get; set; } /// /// 入金总和 /// public double? InFundSum { get; set; } /// /// 出金总和 /// public double? OutFundSum { get; set; } /// /// 其他收支总和 /// public double? OtherFundSum { get; set; } /// /// 期权费收支(权利金收支)总和 /// public double? OptionPremiumSum { get; set; } /// /// 期权费收支(权利金收支)总和 -- 互换 /// public double? OptionPremiumSwapSum { get; set; } /// /// 结算费支出(客户平仓行权收益)总和 /// public double? SettlementBalanceSum { get; set; } /// /// 结算费支出(客户平仓收益)总和 /// public double? UnwindBalanceSum { get; set; } /// /// 结算费支出(客户行权收益)总和 /// public double? ExerciseBalanceSum { get; set; } public double? SwapBalanceSum { get; set; } /// /// 抵押品变化总和 /// public double? CashInCashOutProductChangeSum { get; set; } /// /// 实现盈亏总和 /// public double? WinLossSum { get; set; } /// /// 了结权利金总和 /// public double? EndPremiumSum { get; set; } /// /// 票息总和 /// public double? CouponSum { get; set; } public string FundJson { get; set; } /// /// 客户持仓交易预付金总和,客户买入为正,客户卖出为负 /// public double? PrepaymentAmount { get; set; } /// /// 维保线 /// public double? MaintenanceLine { get; set; } /// /// 追保入金 /// public double? vm_in_fund { get; set; } /// /// 追保 入金累计 /// public double? vm_in_fund_sum { get; set; } /// /// 追保 出金 /// public double? vm_out_fund { get; set; } /// /// 追保 出金累计 /// public double? vm_out_fund_sum { get; set; } /// /// 交易费用 /// public double? trade_fee { get; set; } public double? trade_fee_sum { get; set; } /// /// 利息盈亏 /// public double? interest_pnl { get; set; } public double? interest_pnl_sum { get; set; } [NotMapped] public FundObject FundObject { get; set; } private static double Round(double value, int digit) { var num = Convert.ToDouble("1e-" + digit); return Math.Round(value / num, 0, MidpointRounding.AwayFromZero) * num; } } public class FundObject { public Dictionary InFund { get; set; } = new Dictionary(); public Dictionary VmInFund { get; set; } = new Dictionary(); /// /// 出金为绝对值,不包含出金方向处理 /// public Dictionary OutFund { get; set; } = new Dictionary(); public Dictionary VmOutFund { get; set; } = new Dictionary(); public Dictionary NetFund { get; set; } = new Dictionary(); public Dictionary InFundOther { get; set; } = new Dictionary(); public Dictionary OutFundOther { get; set; } = new Dictionary(); public Dictionary OtherFund { get; set; } = new Dictionary(); public Dictionary InFundSum { get; set; } = new Dictionary(); public Dictionary VmInFundSum { get; set; } = new Dictionary(); public Dictionary OutFundSum { get; set; } = new Dictionary(); public Dictionary VmOutFundSum { get; set; } = new Dictionary(); public Dictionary NetFundSum { get; set; } = new Dictionary(); public Dictionary OtherFundSum { get; set; } = new Dictionary(); public Dictionary TodayRemainFund { get; set; } = new Dictionary(); public Dictionary LastDayRemainFund { get; set; } = new Dictionary(); } [NotMapped] public class clientbalanceStatistics : ClientBalanceDaily { public double? CreditRatio { get; set; } public double? AvailableFund { get; set; } public static clientbalanceStatistics TransferFromClientbalancedaily(ClientBalanceDaily clientbalancedaily) { var clientbalanceStatistics = new clientbalanceStatistics { Amount = clientbalancedaily.Amount ?? 0, CashDeposit = clientbalancedaily.CashDeposit ?? 0, DayGainLoss = clientbalancedaily.DayGainLoss ?? 0, LastDayRemainFund = clientbalancedaily.LastDayRemainFund ?? 0, ToDayRemainFund = clientbalancedaily.ToDayRemainFund ?? 0, InFund = clientbalancedaily.InFund ?? 0, OutFund = clientbalancedaily.OutFund ?? 0, OptionPremium = clientbalancedaily.OptionPremium ?? 0, OptionPremiumSwap = clientbalancedaily.OptionPremiumSwap ?? 0, SettlementBalance = clientbalancedaily.SettlementBalance ?? 0, UnwindBalance = clientbalancedaily.UnwindBalance ?? 0, ExerciseBalance = clientbalancedaily.ExerciseBalance ?? 0, Coupon = clientbalancedaily.Coupon ?? 0, SwapBalance = clientbalancedaily.SwapBalance ?? 0, MarginBalance = clientbalancedaily.MarginBalance, Pv = clientbalancedaily.Pv, Credit = clientbalancedaily.Credit, CreditRatio = 0, Margin = clientbalancedaily.Margin, TodayRemianFundProduct = clientbalancedaily.TodayRemianFundProduct, CashInCashOutProductChange = clientbalancedaily.CashInCashOutProductChange }; return clientbalanceStatistics; } } }