From e9b54bdcf64f044cc6c82733959ba5ca1afda716 Mon Sep 17 00:00:00 2001 From: hjhan Date: Tue, 11 Aug 2026 13:00:52 +0800 Subject: [PATCH] =?UTF-8?q?cleanup:=20=E5=88=A0=E9=99=A4=E6=AD=BB=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9E=9A=E4=B8=BE=20mode=203/4/7/8=20=E5=8F=8A?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mode 3(持仓名义本金)/4(持仓市值): 零引用死代码 mode 7/8(多空存续名义本金): 界面已禁用, 无历史数据(用户确认) 删除: - InterestModeEnum: 移除 持仓名义本金/持仓市值/多头存续名义本金/空头存续名义本金 枚举值保持显式(1/2/5/6/9), DB契约不变 - CalcNotionalByMode: 移除 mode 7/8 的 case - ConsTrade.InterestModels/InterestNotionalModels: 移除 mode 7/8 - 删除3个 mode 7/8 相关测试方法(场景已不存在) CalcNotionalByMode 现在只剩 mode 5/6(保证金)的 case, 待 Margin 独立计息入口建成后整体删除。 验证: 编译0错误, 全量508测试7失败(基线一致)。 --- .../YLErp.Core/DBModels/Consts/ConsTrade.cs | 4 ++-- .../DBModels/Enums/InterestModeEnum.cs | 4 ---- .../FundingLegs/FundingLegStrategyTest.cs | 5 ++--- .../SwapUnwindFloatingLegDiagnosticTdd.cs | 14 ------------- .../SwapUnwindPrepayPrincipalBugTdd.cs | 21 ------------------- .../Modules/SwapModule/SwapDealService.cs | 8 ------- 6 files changed, 4 insertions(+), 52 deletions(-) diff --git a/Framework/YLErp.Core/DBModels/Consts/ConsTrade.cs b/Framework/YLErp.Core/DBModels/Consts/ConsTrade.cs index cd243a6a..08664c06 100644 --- a/Framework/YLErp.Core/DBModels/Consts/ConsTrade.cs +++ b/Framework/YLErp.Core/DBModels/Consts/ConsTrade.cs @@ -131,11 +131,11 @@ namespace YLErp.DBModels /// /// 互换利率端计息方式 /// - public static readonly List InterestModels = new List() { (int)InterestModeEnum.固定值, (int)InterestModeEnum.合约名义本金规模, (int)InterestModeEnum.空头存续名义本金,(int)InterestModeEnum.多头存续名义本金, (int)InterestModeEnum.标的期初全价 }; + public static readonly List InterestModels = new List() { (int)InterestModeEnum.固定值, (int)InterestModeEnum.合约名义本金规模, (int)InterestModeEnum.标的期初全价 }; /// /// 互换利率端计息方式-名义本金相关 /// - public static readonly List InterestNotionalModels = new List() {(int)InterestModeEnum.合约名义本金规模, (int)InterestModeEnum.空头存续名义本金, (int)InterestModeEnum.多头存续名义本金, (int)InterestModeEnum.标的期初全价 }; + public static readonly List InterestNotionalModels = new List() {(int)InterestModeEnum.合约名义本金规模, (int)InterestModeEnum.标的期初全价 }; /// /// 互换利率计息方式 预付金 /// diff --git a/Framework/YLErp.Core/DBModels/Enums/InterestModeEnum.cs b/Framework/YLErp.Core/DBModels/Enums/InterestModeEnum.cs index fc389cca..6645c9db 100644 --- a/Framework/YLErp.Core/DBModels/Enums/InterestModeEnum.cs +++ b/Framework/YLErp.Core/DBModels/Enums/InterestModeEnum.cs @@ -14,12 +14,8 @@ namespace YLErp.DBModels Unknown = 0, 固定值 = 1, 合约名义本金规模 = 2, - 持仓名义本金 = 3, - 持仓市值 = 4, 初始预付金 = 5, 追加预付金 = 6, - 多头存续名义本金 = 7, - 空头存续名义本金 = 8, 标的期初全价 = 9 } /// diff --git a/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs b/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs index b3d71a43..c3afb09f 100644 --- a/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs +++ b/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs @@ -121,10 +121,9 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 工厂_未注册mode抛异常() { + // mode 3/4/7/8 已从枚举删除,用 Unknown(0)验证未注册抛异常 Assert.ThrowsException(() => - FundingLegStrategyFactory.Get(InterestModeEnum.持仓名义本金)); - Assert.ThrowsException(() => - FundingLegStrategyFactory.Get(InterestModeEnum.持仓市值)); + FundingLegStrategyFactory.Get(InterestModeEnum.Unknown)); Assert.ThrowsException(() => FundingLegStrategyFactory.Get(InterestModeEnum.初始预付金)); Assert.ThrowsException(() => diff --git a/UnitTestProject/Modules/SwapModule/SwapUnwindFloatingLegDiagnosticTdd.cs b/UnitTestProject/Modules/SwapModule/SwapUnwindFloatingLegDiagnosticTdd.cs index c8645fac..9340fe93 100644 --- a/UnitTestProject/Modules/SwapModule/SwapUnwindFloatingLegDiagnosticTdd.cs +++ b/UnitTestProject/Modules/SwapModule/SwapUnwindFloatingLegDiagnosticTdd.cs @@ -94,19 +94,5 @@ namespace YLErp.Modules.SwapModule Assert.AreEqual(RealFix * ClosePct, close, "mode5 应 = 实时腿剩余本金(real Fix) * closePct,与 posiLong(orig 100M) 无关"); Assert.AreNotEqual(OrigFix * ClosePct, close, "务必不是期初 99,000 * closePct(证明后端修复生效)"); } - - [TestMethod] - public void 诊断_若将来有_多头存续名义本金_腿_posiLong用orig才出错_本deal无此腿_故不影响() - { - // 构造一个「多头存续名义本金」腿,证明此时 posiLong 取值(orig vs real)会直接决定结果—— - // 说明本 deal 没有这种腿,所以 fpositions 用 orig 100M 不影响;但普通收益互换若有此腿则会踩坑。 - var longLeg = new swap_position { id = 35799, InterestMode = (int)InterestModeEnum.多头存续名义本金 }; - var byOrig = CallCalcNotionalByMode(longLeg, ClosePct, RealLong * ClosePct, OrigLong, 0m); // 当前代码:posiLong=orig 100M - var byReal = CallCalcNotionalByMode(longLeg, ClosePct, RealLong * ClosePct, RealLong, 0m); // 若修正为 real 75.6M - Console.WriteLine($"[多头存续名义本金] orig100M→close={byOrig.close} ; real75.6M→close={byReal.close}"); - Assert.AreEqual(OrigLong * ClosePct, byOrig.close, "现状:多头存续名义本金用 orig 100M → 多次部分平仓后会偏大"); - Assert.AreEqual(RealLong * ClosePct, byReal.close, "正确应:用 real 剩余本金 75.6M"); - Assert.AreNotEqual(byOrig.close, byReal.close, "★ 潜在同类 bug:普通收益互换(含多头/空头存续名义本金腿)在多次部分平仓后,posiLong/posiShort 用 orig 会算错——本 deal 无此腿故不触发,属本轮修复范围外"); - } } } diff --git a/UnitTestProject/Modules/SwapModule/SwapUnwindPrepayPrincipalBugTdd.cs b/UnitTestProject/Modules/SwapModule/SwapUnwindPrepayPrincipalBugTdd.cs index e94a452f..ee29d70d 100644 --- a/UnitTestProject/Modules/SwapModule/SwapUnwindPrepayPrincipalBugTdd.cs +++ b/UnitTestProject/Modules/SwapModule/SwapUnwindPrepayPrincipalBugTdd.cs @@ -505,27 +505,6 @@ namespace YLErp.Modules.SwapModule Assert.AreEqual(918_000m, fe1.InterestPrincipal, "追加预付金 10% 应=Fix×0.1"); } - // ---- 多头/空头存续名义本金(7/8):经同一 CalcDailySimpleInterest,需证明修复通用 ---- - [TestMethod] - public void 多头存续名义本金腿_盘中_部分平仓重置周期7天_应线性缩放() - { - const decimal baseP = 2_000_000m; - var fe = CalcByMode((int)InterestModeEnum.多头存续名义本金, baseP, 0.5m); - Assert.AreEqual(1_000_000m, fe.InterestPrincipal, "多头存续 50% 应=posiLong×0.5"); - var fe1 = CalcByMode((int)InterestModeEnum.多头存续名义本金, baseP, 0.1m); - Assert.AreEqual(200_000m, fe1.InterestPrincipal, "多头存续 10% 应=posiLong×0.1"); - } - - [TestMethod] - public void 空头存续名义本金腿_盘中_部分平仓重置周期7天_应线性缩放() - { - const decimal baseP = 2_000_000m; - var fe = CalcByMode((int)InterestModeEnum.空头存续名义本金, baseP, 0.5m); - Assert.AreEqual(1_000_000m, fe.InterestPrincipal, "空头存续 50% 应=posiShort×0.5"); - var fe1 = CalcByMode((int)InterestModeEnum.空头存续名义本金, baseP, 0.1m); - Assert.AreEqual(200_000m, fe1.InterestPrincipal, "空头存续 10% 应=posiShort×0.1"); - } - // ---- 合约名义本金规模(2):CalcNotionalByMode 默认分支(posiNotional×cp) ---- [TestMethod] public void 合约名义本金规模腿_盘中_部分平仓重置周期7天_应线性缩放() diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index efaa7d3e..6e4aa810 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -937,14 +937,6 @@ namespace YLErp.Modules.SwapModule switch (mode) { - case InterestModeEnum.多头存续名义本金: - closePrincipal = posiLong * closePercent; - posiPrincipal = posiLong; - break; - case InterestModeEnum.空头存续名义本金: - closePrincipal = posiShort * closePercent; - posiPrincipal = posiShort; - break; case InterestModeEnum.追加预付金: case InterestModeEnum.初始预付金: closePrincipal = position.InterestPrincipalFix * closePercent;