From fe4b431fafcb4c9ba77e274bac713142eda1e63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=B9=E6=B5=B7?= Date: Fri, 25 Apr 2025 15:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=9A=84=E4=BA=A4=E6=98=93&=E9=A3=8E?= =?UTF-8?q?=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs | 19 ++++--- .../ExchangeTradePositionService.cs | 51 +++++-------------- .../ExchangeTradeSaveServiceBase.cs | 2 +- .../Modules/RiskModule/QuotaMonitorService.cs | 46 ++++++++--------- .../Views/ExchangeTrade/PositionList.cshtml | 7 --- YLErpWeb/Views/ExchangeTrade/TradeEdit.cshtml | 19 ++----- YLErpWeb/Views/ExchangeTrade/TradeList.cshtml | 3 -- .../wwwroot/Scripts/app/risk/quotaMonitor.js | 10 ++++ 8 files changed, 60 insertions(+), 97 deletions(-) diff --git a/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs b/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs index 7e51f2ef..3700184d 100644 --- a/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs +++ b/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs @@ -594,16 +594,6 @@ namespace YLErp.BLL.Eod } } clientPosition.update_user = 0; - if (clientPosition.id == 0 && clientPosition.position_qty > 0) - { - clientPosition.update_time = DateTime.Now; - bondDb.client_position.Add(clientPosition); - } - else if (clientPosition.id > 0 && (clientPosition.position_qty > 0 || clientPosition.today_profit_loss != 0)) - { - clientPosition.update_time = DateTime.Now; - } - bondDb.SaveChanges(); SetClientPositionPrice(clientPosition); clientPosition.swap_market_value = clientPosition.full_price_now * clientPosition.position_qty * (clientPosition.side == 0 ? 1 : -1); clientPosition.position_profit_loss = (clientPosition.full_price_now - clientPosition.deal_full_price_avg) * clientPosition.position_qty * (clientPosition.side == 0 ? 1 : -1) - clientPosition.commission; @@ -613,6 +603,15 @@ namespace YLErp.BLL.Eod { BondCalcApi(clientPosition); } + if (clientPosition.id == 0 && clientPosition.position_qty > 0) + { + clientPosition.update_time = DateTime.Now; + bondDb.client_position.Add(clientPosition); + } + else if (clientPosition.id > 0 && (clientPosition.position_qty > 0 || clientPosition.today_profit_loss != 0)) + { + clientPosition.update_time = DateTime.Now; + } bondDb.SaveChanges(); } var sql = $"{nameof(ClientPosition.create_time)}<'{datenow.AddSeconds(-1):yyyy-MM-dd HH:mm:ss}' or {nameof(ClientPosition.position_qty)}=0"; diff --git a/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradePositionService.cs b/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradePositionService.cs index f51ebbc7..be450461 100644 --- a/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradePositionService.cs +++ b/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradePositionService.cs @@ -20,51 +20,28 @@ namespace YLErp.Modules.ExchangeTradeModule public void ResetExchangeTradePosition() { var valueDate = SystemValueDate; - var lastDate = EodOperationBase.GetLastSettlementDate(valueDate, false); - List tradetypes = new List { "股票", "商品期货", "商品现货", "场内期权", "利率债", "信用债", "其它债券" }; - var eodQuery = from et in DbContext.eod_trade_position.AsNoTracking() - where et.ValueDate == lastDate && tradetypes.Contains(et.TradeType) - select new TradePositionEx - { - UnderlyingId = et.UnderlyingId, - TradeType = et.TradeType, - BookId = et.BookId, - InstrumentCode = et.ExchangeOptionCode, - UnderlyingCode = et.UnderlyingCode, - Position = et.Amount, - PositionCost = et.Cost, - BuySell = et.PositionType - }; - var positionList = eodQuery.ToList(); - - //如果当天未收盘 - if (valueDate != lastDate) - { - var tdQuery = from trad in DbContext.ExchangeTrade.AsNoTracking() - where trad.TradeDate > lastDate && trad.TradeDate <= valueDate && trad.IsValid - select new TdTradePositionEx - { - TradeType = trad.TradeType, - BookId = trad.AssetBookId, - InstrumentCode = trad.OptionCode, - Position = trad.Notional, - BuySell = trad.TradeSide, - UnderlyingCode = trad.UnderlyingCode, - TradeSinglePrice = trad.TradeSinglePrice - }; - - var tdDatas = tdQuery.ToArray(); - positionList.AddRange(tdDatas); - } + var tdQuery = from trad in DbContext.ExchangeTrade.AsNoTracking() + where trad.IsValid + select new TdTradePositionEx + { + TradeType = trad.TradeType, + BookId = trad.AssetBookId, + InstrumentCode = trad.OptionCode, + Position = trad.Notional, + BuySell = trad.TradeSide, + UnderlyingCode = trad.UnderlyingCode, + TradeSinglePrice = trad.TradeSinglePrice + }; + var positionList = tdQuery.ToList(); var dic = new Dictionary(positionList.Count); foreach (var n in positionList) { var tradeType1 = TradeHelper.GetTradeType1(n.TradeType); var positionType = TradeHelper.GetPositionType(n.BuySell); - var key = $"{n.BookId}^{(int)tradeType1}^{(int)positionType}^{n.UnderlyingCode}^{n.InstrumentCode}"; + var key = $"{n.BookId}^{(int)tradeType1}^{n.UnderlyingCode}^{n.InstrumentCode}"; var position = n.IsEod ? n.Position : TradeHelper.GetPositionNotional(n.BuySell, n.Position); var positionCost = n.IsEod ? n.PositionCost : position * n.TradeSinglePrice; diff --git a/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradeSaveServiceBase.cs b/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradeSaveServiceBase.cs index 887c6564..7b9a38f7 100644 --- a/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradeSaveServiceBase.cs +++ b/YLErpDAL/Modules/ExchangeTradeModule/ExchangeTradeSaveServiceBase.cs @@ -136,7 +136,7 @@ namespace YLErp.Modules.ExchangeTradeModule para.positionType = TradeHelper.GetPositionType(para.tradeSide); var predicate = PredicateBuilder.Create(n => n.BookId == td.AssetBookId - && n.TradeType1 == para.tradeType1 && n.PositionType == para.positionType && n.UnderlyingCode == td.UnderlyingCode); + && n.TradeType1 == para.tradeType1 && n.UnderlyingCode == td.UnderlyingCode); if (td.TradeType == "场内期权") { diff --git a/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs b/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs index 0e905161..309fbb71 100644 --- a/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs +++ b/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs @@ -901,6 +901,7 @@ namespace YLErp.Modules.RiskModule { return; } + obj.DeltaExposure= dict[obj.BusinessType].Sum(O => O.risk.Delta.Normalize()); obj.DeltaCash = dict[obj.BusinessType].Sum(O => O.risk.DeltaCash.Normalize()); obj.Vega = dict[obj.BusinessType].Sum(O => O.risk.Vega.Normalize()); obj.VegaCash = dict[obj.BusinessType].Sum(O => O.risk.VegaCash.Normalize()); @@ -1015,41 +1016,30 @@ namespace YLErp.Modules.RiskModule setValue(swap, swapSetting); var positionList = new List>(); - var gloabPnl = GetTradePositionPnl(); + var underly = GetTradePositionPnl(); if (dict.ContainsKey("互换")) { var swapPositionList = dict["互换"].Select(O => new KeyValuePair(O.t, O.risk)); swap.TotalPnL = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize()); - if (PS.Config.Is国信金阳) - { - swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize() < 0 ? O.Value.PositionPnl.Normalize() : 0); - } - else - { - swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize()); - } + swap.PositionPnl = swapPositionList.Sum(O => O.Value.PositionPnl.Normalize()); positionList.AddRange(swapPositionList); } - swap.DeltaNetExposure = double.NaN; var checkPosiList = GetCheckPosiList(); var posiStockEqvNotional = checkPosiList.Sum(s => s.Pv); - var underly = new QuotaMonitor_Global() - { - ParentKey = "场外", - BusinessType = "标的交易", - PositionPnl = gloabPnl - }; + var delta = checkPosiList.Sum(s => s.Delta); var unTrade = new QuotaMonitor_Global() { ParentKey = "场外", BusinessType = "未簿记合约", - StockEqvNotional = Convert.ToDouble(posiStockEqvNotional) - swap.StockEqvNotional.Normalize() + StockEqvNotional = Convert.ToDouble(posiStockEqvNotional) - swap.StockEqvNotional.Normalize(), + DeltaExposure=(double)delta- (swap.DeltaExposure??0) }; var all = new QuotaMonitor_Global() { BusinessType = "全局", StockEqvNotional = Convert.ToDouble(posiStockEqvNotional), - PositionPnl = underly.PositionPnl + swap.PositionPnl + PositionPnl = underly.PositionPnl + swap.PositionPnl, + DeltaExposure=(double)delta+ underly.DeltaExposure }; var list = new List { @@ -4364,7 +4354,7 @@ namespace YLErp.Modules.RiskModule checkQuotaMoitorModel.Commision = item.commission ?? 0; checkQuotaMoitorModel.Direction = item.direction; checkQuotaMoitorModel.ClientId = Convert.ToInt32(item.client_id ?? 0); - checkQuotaMoitorModel.Delta = (checkQuotaMoitorModel.Side == 0 ? checkQuotaMoitorModel.Price : -checkQuotaMoitorModel.Price) * checkQuotaMoitorModel.Qty; + checkQuotaMoitorModel.Delta = (checkQuotaMoitorModel.Side == 0 ? 1 : -1) * checkQuotaMoitorModel.Qty; EodPrice bondPrice = null; if (eodPriceDic.ContainsKey(checkQuotaMoitorModel.UnderlyingCode)) { @@ -4990,9 +4980,16 @@ namespace YLErp.Modules.RiskModule /// 算标的交易盈亏 /// /// - private double GetTradePositionPnl() + private QuotaMonitor_Global GetTradePositionPnl() { - double currentValue = 0; + QuotaMonitor_Global quotaMonitor_Global = new QuotaMonitor_Global() + { + ParentKey= "场外", + BusinessType = "标的交易", + PositionPnl=0, + DeltaExposure=0, + StockEqvNotional=0 + }; List tradetypes = new List { "利率债", "信用债", "其它债券" }; var tposis = DbContext.TradePosition.Where(x => tradetypes.Contains(x.TradeType)).AsNoTracking().ToList(); var umCodes = tposis.Select(x => x.UnderlyingCode).Distinct().ToList(); @@ -5015,9 +5012,12 @@ namespace YLErp.Modules.RiskModule lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple); } } - currentValue += lastPrice * item.Position - item.PositionCost; + quotaMonitor_Global.PositionPnl += lastPrice * item.Position - item.PositionCost; + quotaMonitor_Global.StockEqvNotional += item.PositionCost; + quotaMonitor_Global.DeltaExposure += (item.PositionType == PositionTypeFlag.Long ? -1 : 1) * item.Position; } - return currentValue; + + return quotaMonitor_Global; } private List checkGlobal(List positionList, List posiList, string tag_prefix, QuotaSetting[] settings, bool warning) { diff --git a/YLErpWeb/Views/ExchangeTrade/PositionList.cshtml b/YLErpWeb/Views/ExchangeTrade/PositionList.cshtml index 0935dd32..edd1d560 100644 --- a/YLErpWeb/Views/ExchangeTrade/PositionList.cshtml +++ b/YLErpWeb/Views/ExchangeTrade/PositionList.cshtml @@ -46,13 +46,6 @@ 交易类型 - @if (Model.TradeType == "场内期权") - { - - } - else - { - - - - - - - } + + +