From 7528670e8b94a5c9d356c2674ce1152cbdba6691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8D=E9=94=90?= <1565842059@qq.com> Date: Sun, 9 Aug 2026 13:42:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(swap):=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=B9=B3=E4=BB=93=E5=90=8E=E7=AE=97=E5=B0=BE=E5=88=A9?= =?UTF-8?q?=E6=81=AF=E8=AE=A1=E7=AE=97=E9=97=AE=E9=A2=98(=E7=AE=97?= =?UTF-8?q?=E5=A4=B4=E7=AE=97=E5=B0=BET+0=E5=90=88=E7=BA=A6=E5=8D=95?= =?UTF-8?q?=E5=88=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将测试方法改为数据驱动测试以覆盖不同利息模式 - 在测试中添加对不同利息模式的验证逻辑 - 修复平仓后EOD本金只携带剩余持仓的计算逻辑 - 添加对算尾部分平仓后EOD本金的断言验证 - 优化单利算尾当日按平仓前全额计提的处理逻辑 --- .../Modules/SwapModule/DealInterestsScenarioTest.cs | 9 +++++++-- YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs b/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs index f75375be..907849eb 100644 --- a/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs +++ b/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs @@ -864,8 +864,10 @@ namespace YLErp.Modules.SwapModule "预付金部分平仓待实现收益应为历史待实现+平仓后当日新增-平仓实现"); } - [TestMethod] - public void DI_MANUAL_PARTIAL_CLOSE_CalcLastIncludesClosedPrincipalDailyInterest() + [DataTestMethod] + [DataRow((int)InterestModeEnum.合约名义本金规模)] + [DataRow((int)InterestModeEnum.标的期初全价)] + public void DI_MANUAL_PARTIAL_CLOSE_CalcLastIncludesClosedPrincipalDailyInterest(int interestMode) { var service = new StubEodPositionService(); var td = CreateTrade(); @@ -876,6 +878,7 @@ namespace YLErp.Modules.SwapModule SettlementRules = 0 }); var position = CreateInterestPosition(); + position.InterestMode = interestMode; var previousEod = CreatePreEod(StartDate.AddDays(2), 100m); previousEod.TdInterestPrincipal = Principal; var closeFlow = CreateSwapFlowEvent(StartDate.AddDays(3), 50m); @@ -887,6 +890,8 @@ namespace YLErp.Modules.SwapModule AssertDecimal(Principal * FixedRate / AnnualDays, result.TdInterestIncome, "算尾部分平仓的当日新计利息应包含已平仓部分(按全额本金计提)"); + AssertDecimal(500m, result.TdInterestPrincipal, + "算尾部分平仓后的 EOD 本金应只携带剩余持仓"); // 补充:算尾部分平仓的待实现利息总额应满足递推 // InterestIncomeSum = 前日待实现 + 当日新计(全额本金,含被平仓部分) - 当日实现 diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index 9eea085c..e7c07412 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -1453,6 +1453,16 @@ namespace YLErp.Modules.SwapModule newEodPayPosition.TdInterestIncome /= tradeExtend.AnnualDays; } } + if (!autoSwap + && closePercent > 0m && closePercent < 1m + && posiNotionalValue > 0m + && position.InterestType == (int)InterestTypeEnum.单利 + && (position.InterestMode == (int)InterestModeEnum.合约名义本金规模 + || position.InterestMode == (int)InterestModeEnum.标的期初全价)) + { + // 单利算尾当日仍按平仓前全额计提,跨日 EOD 本金只携带剩余持仓。 + newEodPayPosition.TdInterestPrincipal = posiNotionalValue; + } Log.Info($"InterestIncomeSum is {lastInterestIncomeSum},TdInterestIncome is {newEodPayPosition.TdInterestIncome}" + $",TdCloseInterest is {newEodPayPosition.TdCloseInterest}"); Log.Info($"InterestFeeSum is {eodPayPosition.InterestFeeSum},TdInterestFee is {newEodPayPosition.TdInterestFee}" +