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); }