From a575de7bbec84755f2e77a6a460a0cdf309c4a28 Mon Sep 17 00:00:00 2001 From: tengyufan <1532636164@qq.com> Date: Mon, 27 Jul 2026 09:45:41 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(swap):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=B4=B9=E7=8E=87=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=99=BE=E5=88=86=E6=AF=94/=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E6=95=B0=E9=87=8F=E6=A8=A1=E5=BC=8F=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=8F=8A=E8=87=AA=E5=8A=A8=E8=AE=A1=E7=AE=97"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c9071a4eff5c4a39b3a368889a97d29408318ecc. --- .../YLErp.Core/DBModels/SwapFlowEvent.cs | 10 --- Framework/YLErp.Core/DBModels/SwapPosition.cs | 5 -- .../Modules/SwapModule/SwapDealService.cs | 21 ------ .../Modules/SwapModule/SwapTradeService.cs | 1 - YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml | 11 --- YLErpWeb/Views/SwapTrade2/TradeView.cshtml | 15 +--- .../Scripts/app/swaptrade/swapTradeEdit.js | 65 +++++------------ .../Scripts/app/swaptrade/unwindSwapTrade.js | 72 +++++++++---------- 8 files changed, 54 insertions(+), 146 deletions(-) diff --git a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs index 675154f7..b9079e27 100644 --- a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs +++ b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs @@ -228,16 +228,6 @@ namespace YLErp.DBModels [NotMapped] public decimal BeforeCloseFee { get; set; } /// - /// 单位交易费用(仅前端展示,不存库) - /// - [NotMapped] - public decimal PosiTradingFeeUnit { get; set; } - /// - /// 单位交易费用模式 0=百分比 1=单位数量(仅前端展示,不存库) - /// - [NotMapped] - public int PosiFeeType { get; set; } - /// /// 持仓腿id /// [DisplayName("持仓腿id")] diff --git a/Framework/YLErp.Core/DBModels/SwapPosition.cs b/Framework/YLErp.Core/DBModels/SwapPosition.cs index 04a306f9..44fb89d9 100644 --- a/Framework/YLErp.Core/DBModels/SwapPosition.cs +++ b/Framework/YLErp.Core/DBModels/SwapPosition.cs @@ -113,11 +113,6 @@ namespace YLErp.DBModels [DataChange] public decimal PosiTradingFeeUnit { get; set; } /// - /// 单位交易费用模式 0=百分比 1=单位数量 - /// - [DataChange] - public int PosiFeeType { get; set; } - /// /// 起始日 /// [DisplayName("起始日")] diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index fdde80ea..05182f5f 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -291,11 +291,6 @@ namespace YLErp.Modules.SwapModule floatEvent.UnderlyingInstrumentType = position.UnderlyingInstrumentType; floatEvent.CloseFee = 0; floatEvent.BeforeCloseFee = oriPosition.PosiTradingFeePending; - //自动计算平仓交易费用 - floatEvent.TradingFee = CalcInitTradingFee(oriPosition, unwindData); - //向前端传递单位交易费用和模式标记(NotMapped,不存库) - floatEvent.PosiTradingFeeUnit = oriPosition.PosiTradingFeeUnit; - floatEvent.PosiFeeType = oriPosition.PosiFeeType; floatEvent.MarkClosePnl = 0; floatEvent.PayDirection = position.PosiDirection; floatEvent.PosiGrossPrice = position.PosiGrossPrice; @@ -319,22 +314,6 @@ namespace YLErp.Modules.SwapModule return unwindData; } /// - /// 计算初始平仓交易费用 - /// - private decimal CalcInitTradingFee(swap_position oriPosition, UnwindData unwindData) - { - if (oriPosition.PosiFeeType == 0) - { - //百分比模式:费率%/100 × 平仓名义本金 - return Math.Round(oriPosition.PosiTradingFeeUnit / 100m * (decimal)unwindData.CloseNotionalValue, 2, MidpointRounding.AwayFromZero); - } - else - { - //单位数量模式:单位费率 × 平仓数量 - return Math.Round(oriPosition.PosiTradingFeeUnit * (decimal)unwindData.CloseQty, 2, MidpointRounding.AwayFromZero); - } - } - /// /// 校验上日是否收盘 /// /// diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeService.cs index f32f97fe..ca343cbc 100644 --- a/YLErpDAL/Modules/SwapModule/SwapTradeService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapTradeService.cs @@ -1375,7 +1375,6 @@ namespace YLErp.Modules.SwapModule position.PosiTradingFee = swap.PosiTradingFee; position.PosiTradingFee=Math.Round(position.PosiTradingFee, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero); position.PosiTradingFeeUnit = swap.PosiTradingFeeUnit; - position.PosiFeeType = swap.PosiFeeType; position.PosiTradingFeePending = swap.PosiTradingFeePending; position.PosiTradingFeePending = Math.Round(position.PosiTradingFeePending, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero); position.UnderlyingCode = swap.UnderlyingCode; diff --git a/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml b/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml index 9c2a9196..6409fe53 100644 --- a/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml +++ b/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml @@ -450,7 +450,6 @@ 期初标的成交收益率% 期初标的价格 数量 - 基础费率 交易费用后付 @@ -488,16 +487,6 @@ {{item.underlying!=null?item.underlying.QuoteUnitString:''}} - - - -
我方{{item.PosiDirection==1?"支付":"收取"}}交易费用
diff --git a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml index ed573429..9172e401 100644 --- a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml +++ b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml @@ -349,7 +349,7 @@ @item.interest_rest_days @((item.interest_rule != null) ? (SwapInterestRule)item.interest_rule : "") - 互换利率 + @(string.IsNullOrEmpty(item.category_tag) ? "互换利率" : item.category_tag) @@ -384,7 +384,6 @@ @initYtmTitle } 数量 - 基础费率 交易费用后付 @foreach (var item in paySwapPositions) @@ -410,16 +409,6 @@ @item.PosiQuantity.OtcFormat(OtcFormatFlag.StockEqvNotional) - - @if (item.PosiFeeType == 0) - { - @(item.PosiTradingFeeUnit.ToString("0.0000") + "%") - } - else - { - @item.PosiTradingFeeUnit.OtcFormat(OtcFormatFlag.StockEqvNotional) - } - @item.PosiTradingFeePending.OtcFormat(OtcFormatFlag.StockEqvNotional) @@ -563,7 +552,7 @@ @(item.InterestType == 0 ? "单利" : "复利") @item.interest_rest_days @((item.interest_rule != null) ? (SwapInterestRule)item.interest_rule : "") - 互换利率 + @(string.IsNullOrEmpty(item.category_tag) ? "互换利率" : item.category_tag) } diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js index 70a91ff2..fa6b7011 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js @@ -12,8 +12,6 @@ const inputFormatTradeAmount = Object.freeze({ precision: otcformat.trading.noti const inputFormatSwapRate = Object.freeze({ precision: otcformat.trading.premiumRateP.precision, negative: true, append: '%' }); const inputFormatTradePrice = Object.freeze({ precision: otcformat.trading.tradePrice.precision, negative: true, append: '' }); const inputFormatTradeSinglePrice = Object.freeze({ precision: otcformat.trading.tradeSinglePrice.precision, negative: true, append: '', percent: false }); -const inputFormatPosiFeePercent = Object.freeze({ precision: 4, negative: true, append: '' });//单位交易费用-百分比模式(精度4) -const inputFormatPosiFeeUnit = Object.freeze({ precision: 2, negative: true, append: '' });//单位交易费用-单位数量模式(精度2) const inputFormatMarginRate = Object.freeze({ precision: otcformat.trading.marginRateP.precision, append: '%' }); const inputFormatSwapDeliveryPrice = Object.freeze({ precision: 9, negative: true, append: '', percent: false }); const inputFormatSwapBondDeliveryPrice = Object.freeze({ precision: 9, negative: true, append: '', percent: true }); @@ -155,7 +153,6 @@ const vue = new Vue({ currencys: page.currencys, getNotionalSingleFee: 0, isSingleFee: page.Trade.trade_extend.ExtendObj.OpenFeeType == 0, - posiFeeModePercent: true,//单位交易费用模式: true=百分比模式, false=单位数量模式 observation: {//互换观察日 ObservationInterval: "", IntervalList: [], @@ -510,50 +507,28 @@ const vue = new Vue({ } }, - //变更单位交易费用(正算:单位交易费用→交易费用后付) + //变更单位交易费用 changeTradingFeeUnit(item) { - if (this.posiFeeModePercent) { - //百分比模式: 交易费用后付 = round(费率%/100 × 名义本金, 2) - var stockEqvNotional = Number(this.trade.StockEqvNotional) || 0; - item.PosiTradingFeePending = stockEqvNotional == 0 ? 0 : otcformat.trading.tradeSinglePrice(Number(item.PosiTradingFeeUnit) / 100 * stockEqvNotional); - } else { - //单位数量模式: 交易费用后付 = round(单位费率 × 数量, 2) - var quantity = Number(item.PosiQuantity) || 0; - item.PosiTradingFeePending = otcformat.trading.tradeSinglePrice(Number(item.PosiTradingFeeUnit) * quantity); - } + //计算交易费用 + //if (this.trade.trade_extend.ExtendObj.OpenFeeType == 0) {//按手数收费 + // item.PosiTradingFee = item.ContractSize == 0 ? 0 : otcformat.trading.tradeSinglePrice(item.PosiQuantity * item.PosiTradingFeeUnit / item.ContractSize); + //} else { + // item.PosiTradingFee = otcformat.trading.tradeSinglePrice(item.PosiQuantity * item.PosiTradingFeeUnit); + //} + }, - //变更交易费用(反算:交易费用后付→单位交易费用) + //变更交易费用 changeTradingFee(item) { - if (item.PosiQuantity == 0) { - item.PosiTradingFeeUnit = 0; - return; - } - if (this.posiFeeModePercent) { - //百分比模式反算: 单位交易费用 = round(交易费用后付 / 名义本金 × 100, 4) - var stockEqvNotional = Number(this.trade.StockEqvNotional) || 0; - item.PosiTradingFeeUnit = stockEqvNotional == 0 ? 0 : _.round(Number(item.PosiTradingFeePending) / stockEqvNotional * 100, 4); - } else { - //单位数量模式反算: 单位交易费用 = round(交易费用后付 / 数量, 2) - item.PosiTradingFeeUnit = _.round(Number(item.PosiTradingFeePending) / Number(item.PosiQuantity), 2); - } - }, - //切换到单位数量模式 - showPayAbsPrice() { - this.posiFeeModePercent = false; - this.paySwapList.forEach(item => { - item.PosiFeeType = 1; - item.PosiTradingFeeUnit = 0; - item.PosiTradingFeePending = 0; - }); - }, - //切换到百分比模式 - showPayPercentPrice() { - this.posiFeeModePercent = true; - this.paySwapList.forEach(item => { - item.PosiFeeType = 0; - item.PosiTradingFeeUnit = 0; - item.PosiTradingFeePending = 0; - }); + //计算单位交易费用 + //if (item.PosiQuantity == 0) { + // item.PosiTradingFeeUnit = 0; + // return + //} + //if (this.trade.trade_extend.ExtendObj.OpenFeeType == 0) {//按手数收费 + // item.PosiTradingFeeUnit = item.ContractSize == 0 ? 0 : otcformat.trading.tradeSinglePrice(item.PosiTradingFee * item.ContractSize / item.PosiQuantity); + //} else { + // item.PosiTradingFeeUnit = otcformat.trading.tradeSinglePrice(item.PosiTradingFee / item.PosiQuantity); + //} }, savetrade() { if (!this.checkSubmitData()) { @@ -643,7 +618,6 @@ const vue = new Vue({ x.PosiGrossPrice = thisObj.roundStorageDeliveryPrice(x, x.PosiGrossPrice); x.PosiNetNoFeePrice = thisObj.roundStorageBondNetPriceAndYtm(x.PosiNetNoFeePrice); x.InitYtm = x.InitYtm == null ? null : thisObj.roundStorageBondNetPriceAndYtm(x.InitYtm); - x.PosiFeeType = x.PosiFeeType ?? (this.posiFeeModePercent ? 0 : 1); thisObj.trade.swap_positions.push(x); }); } else { @@ -1602,7 +1576,6 @@ const vue = new Vue({ PosiTradingFee: 0,//交易费用 PosiTradingFeePending: 0,//交易费用后付 PosiTradingFeeUnit: 0,//单位交易费用 - PosiFeeType: 0,//单位交易费用模式 0=百分比 1=单位数量 InterestDirection: 0,//利息收支方式 InterestRateDefault: 0,//计息利率 InterestMode: 0,//计息基本类型 diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js index 3204b525..3838b7ea 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js @@ -60,12 +60,9 @@ const vue = new Vue({ this.ratio = this.floatPosition.PayDirection == 1 ? -1 : 1; this.shortRatio = this.floatPosition.PositionType == 1 ? 1 : -1; this.TradeStartDate = model.TradeStartDate; - // 多次部分平仓后 ClosePercent 语义为"占剩余持仓比例"。 - // 仅当"全部平仓"(CloseMethod==1) 时修正旧口径(model.ClosePercent 可能=剩余/原始<1)为 1; - // "部分平仓"(CloseMethod==2) 时保留已提交比例(平仓待复核场景),避免覆盖用户已提交的 closePercent - if (this.deal.CloseMethod === 1) { - this.deal.ClosePercent = 1; - } + // 最多可平比例(占期初口径) = 剩余名义本金 / 期初名义本金;分母为 0 时兜底为 1 + this.oriClosePercent = (this.deal.NotionalValue && this.deal.PosiNotionalValue) + ? this.deal.PosiNotionalValue / this.deal.NotionalValue : 1; // 转换期末标的价格为百分比形式 if (this.floatPosition.TradingAmountAvg) { this.floatPosition.TradingAmountAvg = this.floatPosition.TradingAmountAvg * this.multiplier; @@ -139,46 +136,39 @@ const vue = new Vue({ this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.PosiNotionalValue)); this.deal.CloseQty = this.deal.PositionQty; } else { - this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent)); + // ClosePercent 是占期初口径(A),需除以 oriClosePercent 转占剩余(B) 再乘剩余数量 + this.deal.CloseQty = this.calcCloseQtyByPercent(this.deal.ClosePercent); } this.calcTradingFeePending(); - this.calcTradingFee(); this.getInterestList(); this.calcFloatClosePnl(); }, + // 按"占期初口径(A)"的 ClosePercent 反算平仓数量:CloseQty = PositionQty × (ClosePercent / oriClosePercent) + // 多次部分平仓后必须这样转换,否则全部↔部分切换时 ClosePercent 没变但 CloseQty 会变(不自洽) + // 使用 swapCalc.calcCloseQtyByOriginalPercent 的 roundHalfAwayFromZero 避免 JS 浮点精度偏差 + // (如 32500000*(0.5/0.65)=24999999.999999996 而非 25000000) + calcCloseQtyByPercent(closePercent) { + return SwapCalc.calcCloseQtyByOriginalPercent(closePercent, this.oriClosePercent, this.deal.PositionQty); + }, calcTradingFeePending() { this.floatPosition.TradingFeePending = this.floatPosition.BeforeCloseFee * parseFloat(this.deal.ClosePercent); }, - //自动计算平仓交易费用(根据单位交易费用 + 模式) - calcTradingFee() { - var unit = parseFloat(this.floatPosition.PosiTradingFeeUnit) || 0; - var type = parseInt(this.floatPosition.PosiFeeType) || 0; - if (type === 0) { - //百分比模式:费率%/100 × 平仓名义本金 - this.floatPosition.TradingFee = _.round(unit / 100 * parseFloat(this.deal.CloseNotionalValue), 2); - } else { - //单位数量模式:单位费率 × 平仓数量 - this.floatPosition.TradingFee = _.round(unit * parseFloat(this.deal.CloseQty), 2); - } - //用格式化函数确保显示一致 - this.floatPosition.TradingFee = otcformat.trading.StockEqvNotional(this.floatPosition.TradingFee); - this.calcFloatClosePnl(); - }, changeCloseQty() {//修改平仓数量 if (parseFloat(this.deal.CloseQty) > parseFloat(this.deal.PositionQty)) { main.message("平仓数量不能超过持仓数量"); return; } - this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseQty) / parseFloat(this.deal.PositionQty)); + // CloseQty/PositionQty 得占剩余(B),× oriClosePercent 转回占期初(A) + var ori = parseFloat(this.oriClosePercent) || 0; + this.deal.ClosePercent = otcformat.fixed6((parseFloat(this.deal.CloseQty) / parseFloat(this.deal.PositionQty)) * ori); if (parseFloat(this.deal.CloseQty) == parseFloat(this.deal.PositionQty)) { this.deal.CloseMethod = 1; } else { this.deal.CloseMethod = 2; } - // 多次部分平仓后 PosiNotionalValue 才是剩余本金,不能用原始 NotionalValue,否则平仓名义本金偏大 - this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.PosiNotionalValue)); + // 占期初口径:平仓名义本金 = 平仓比例 × 期初名义本金(NotionalValue) + this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.NotionalValue)); this.calcTradingFeePending(); - this.calcTradingFee(); this.getInterestList(); this.calcFloatClosePnl(); }, @@ -188,16 +178,15 @@ const vue = new Vue({ this.deal.ClosePercent = this.oriClosePercent; return; } - this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent)); - // 多次部分平仓后 PosiNotionalValue 才是剩余本金,不能用原始 NotionalValue,否则平仓名义本金偏大 - this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.PosiNotionalValue)); - if (parseFloat(this.deal.CloseNotionalValue) == parseFloat(this.deal.PosiNotionalValue)) { - this.floatPosition.CloseMethod = 1; + this.deal.CloseQty = this.calcCloseQtyByPercent(this.deal.ClosePercent); + // 占期初口径:平仓名义本金 = 平仓比例 × 期初名义本金(NotionalValue) + this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.NotionalValue)); + if (parseFloat(this.deal.ClosePercent) == parseFloat(this.oriClosePercent)) { + this.deal.CloseMethod = 1; } else { - this.floatPosition.CloseMethod = 2; + this.deal.CloseMethod = 2; } this.calcTradingFeePending(); - this.calcTradingFee(); this.getInterestList(); this.calcFloatClosePnl(); }, @@ -207,11 +196,15 @@ const vue = new Vue({ this.deal.CloseNotionalValue = this.deal.PosiNotionalValue; return; } - // 多次部分平仓后应以 PosiNotionalValue(剩余) 为分母,否则 ClosePercent 偏小,导致后端预付金返还本金计算错误 - this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseNotionalValue) / parseFloat(this.deal.PosiNotionalValue)); - this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent)); + // 占期初口径:平仓比例 = 平仓名义本金 / 期初名义本金(NotionalValue) + this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseNotionalValue) / parseFloat(this.deal.NotionalValue)); + this.deal.CloseQty = this.calcCloseQtyByPercent(this.deal.ClosePercent); + if (parseFloat(this.deal.ClosePercent) == parseFloat(this.oriClosePercent)) { + this.deal.CloseMethod = 1; + } else { + this.deal.CloseMethod = 2; + } this.calcTradingFeePending(); - this.calcTradingFee(); this.getInterestList(); this.calcFloatClosePnl(); }, @@ -296,7 +289,8 @@ const vue = new Vue({ }, getInterestList() {//根据平仓日期获取利息腿信息 var thisObj = this; - var postData = { valueDate: thisObj.deal.ValueDate, unwindDate: thisObj.deal.UnwindDate, tradeId: thisObj.deal.SwapTradeId, closePercent: thisObj.deal.ClosePercent, eventType: 2 } + // closePercent 按"占期初(original)"语义(A)传给后端,由 GetUnwindInterestList 转为"占剩余(B)"计算 + var postData = { valueDate: thisObj.deal.ValueDate, unwindDate: thisObj.deal.UnwindDate, tradeId: thisObj.deal.SwapTradeId, closePercent: thisObj.deal.ClosePercent, eventType: 2, notionalValue: thisObj.deal.NotionalValue, posiNotionalValue: thisObj.deal.PosiNotionalValue } main.post("/swaptrade2/GetUnwindInterestList", postData, { async: true }).done(function (resp) { thisObj.interestList = resp.obj.filter((item) => { return item.InterestMode == 1 || item.InterestMode == 2 || item.InterestMode == 7 || item.InterestMode == 8 || item.InterestMode == 9;