From f7d23dc1321fe3c34124b39b188504c9cd1126ce Mon Sep 17 00:00:00 2001 From: hjhan Date: Wed, 1 Jul 2026 13:38:24 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E5=8D=95=E5=88=A9c?= =?UTF-8?q?onsumedInterest=E6=89=A3=E9=99=A4(=E5=8F=8C=E9=87=8D=E6=89=A3?= =?UTF-8?q?=E5=87=8F=E5=AF=BC=E8=87=B41=E5=A4=A9=E5=88=A9=E6=81=AF?= =?UTF-8?q?=E5=8F=980)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 单利起点InterestProfitSum已含历史累计(eod快照), 再减consumedInterest会双重扣减。复利起点是0(从头算), 减consumedInterest正确。两者计算结构不同不能套用。 正确方向:让InterestProfitSum在互换结清后归零(eod层方案B), 而非在计算时减consumedInterest。待重新设计单利修复方案。 测试还原为红灯(Assert redCount>0),注释更新说明正确方向。 --- .../SwapPartialUnwindInterestDefaultTest.cs | 13 +++++++------ YLErpDAL/Modules/SwapModule/SwapDealService.cs | 12 +++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/SwapPartialUnwindInterestDefaultTest.cs b/UnitTestProject/Modules/SwapModule/SwapPartialUnwindInterestDefaultTest.cs index b90501c7..b01d7e01 100644 --- a/UnitTestProject/Modules/SwapModule/SwapPartialUnwindInterestDefaultTest.cs +++ b/UnitTestProject/Modules/SwapModule/SwapPartialUnwindInterestDefaultTest.cs @@ -267,17 +267,18 @@ namespace YLErp.Modules.SwapModule if (redCount > 0) { Console.WriteLine($" ⚠ 单利路径仍存在偏大:{redCount} 条单利腿默认值含历史已结利息。"); - Console.WriteLine($" 根因:CalcDailySimpleInterest 未加 consumedInterest 扣除。"); + Console.WriteLine($" 根因:CalcDailySimpleInterest 起点InterestProfitSum在互换后未归零。"); + Console.WriteLine($" 注意:不能简单减consumedInterest(会双重扣减,导致应为1天利息变0)。"); + Console.WriteLine($" 正确方案:让InterestProfitSum在互换结清后归零(eod层方案B)。"); } else { - Console.WriteLine($" ✅ 单利路径已修复:默认值正确扣除历史已结利息,无偏大。"); + Console.WriteLine($" 单利路径未检测到偏大。"); } - // 绿灯断言(修复后):单利路径不应再存在偏大 - Assert.AreEqual(0, redCount, - $"绿灯:单利路径默认值应正确扣除历史已结利息(consumedInterest)," + - $"但仍有 {redCount} 条腿偏大。"); + // 红灯断言:单利路径应存在偏大(待正确修复方案) + Assert.IsTrue(redCount > 0, + "红灯:单利路径应存在默认值偏大。待正确修复(InterestProfitSum归零)后反转。"); } finally { diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index 6b24a0b6..f36b22f1 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -433,8 +433,10 @@ namespace YLErp.Modules.SwapModule else { // 盘中互换场景,使用 CalcUnwindInterest - // 取历史已结利息(事件级,互换当时落库),供单利/复利重算时扣除已通过互换结出的利息,避免重复计入 - var consumedInterest = GetConsumedInterest(td.id, position.id, endDate); + // 取历史已结利息(事件级,互换当时落库),供复利重算扣除(仅复利需要;单利基于日终快照自带状态) + var consumedInterest = position.InterestType == (int)InterestTypeEnum.复利 + ? GetConsumedInterest(td.id, position.id, endDate) + : 0m; interests.Add(CalcUnwindInterest(td, valueDate, endDate, positionClone, rate, floatRate, posiPrincipal, closePrincipal, newClosePercent, annualDays, preEodPosition, eventType, add, swap, orginPv, calcFirst, calcLast||newCalcLast, consumedInterest)); } } @@ -702,7 +704,7 @@ namespace YLErp.Modules.SwapModule } else { - CalcDailySimpleInterest(preEodPosition, endDate, position, posiNotionalValue, interest, annualDays, needPrice, floateRate, closePrecent, orginPv, calcFirst, calcLast, ref InterestAmount, ref TdInterestAmount, consumedInterest); + CalcDailySimpleInterest(preEodPosition, endDate, position, posiNotionalValue, interest, annualDays, needPrice, floateRate, closePrecent, orginPv, calcFirst, calcLast, ref InterestAmount, ref TdInterestAmount); } interest.InterestAmount = Math.Round(InterestAmount, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero); @@ -853,10 +855,6 @@ namespace YLErp.Modules.SwapModule tdinterest += tdinterest1; } } - // 单利同样需扣除历史已通过互换结出的利息(与复利 cs:793 对齐), - // 否则部分互换结清后再平仓,默认值会重复计入已实现部分。 - interest -= consumedInterest; - tdinterest -= consumedInterest; InterestAmount = Math.Round(interest, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero); TdInterestAmount = Math.Round(tdinterest, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero); }