From 6d6729cf9cbc78514fa024132ea4e07358e3b8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8D=E9=94=90?= <1565842059@qq.com> Date: Fri, 7 Aug 2026 15:05:04 +0800 Subject: [PATCH] =?UTF-8?q?test(swap):=20=E6=B7=BB=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=B9=B3=E4=BB=93=E5=88=A9=E6=81=AF=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加算尾部分平仓当日新计利息包含已平仓部分的测试 - 添加不算尾部分平仓当日新计利息只包含剩余持仓部分的测试 - 验证部分平仓待实现收益计算的正确性 --- .../SwapModule/DealInterestsScenarioTest.cs | 44 +++++++++++++++++++ .../SwapModule/SwapEodPositionService.cs | 7 ++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs b/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs index 25d3d10f..f1a2be29 100644 --- a/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs +++ b/UnitTestProject/Modules/SwapModule/DealInterestsScenarioTest.cs @@ -807,6 +807,50 @@ namespace YLErp.Modules.SwapModule "预付金部分平仓待实现收益应为历史待实现+平仓后当日新增-平仓实现"); } + [TestMethod] + public void DI_MANUAL_PARTIAL_CLOSE_CalcLastIncludesClosedPrincipalDailyInterest() + { + var service = new StubEodPositionService(); + var td = CreateTrade(); + td.trade_extend.ExtendJson = JsonConvert.SerializeObject(new TradeExtendJson + { + AnnualDays = AnnualDays, + InterestCalcMode = "11", + SettlementRules = 0 + }); + var position = CreateInterestPosition(); + var previousEod = CreatePreEod(StartDate.AddDays(2), 100m); + previousEod.TdInterestPrincipal = Principal; + var closeFlow = CreateSwapFlowEvent(StartDate.AddDays(3), 50m); + closeFlow.EventType = (int)SwapFlowEventTypeEnum.平仓; + + var result = service.ExecuteSaveAutoEodWithCloseInterestPosition( + previousEod, position, td, StartDate.AddDays(3), null, + 500m, 0m, new List { closeFlow }, 500m, false); + + AssertDecimal(Principal * FixedRate / AnnualDays, result.TdInterestIncome, + "算尾部分平仓的当日新计利息应包含已平仓部分"); + } + + [TestMethod] + public void DI_MANUAL_PARTIAL_CLOSE_NoCalcLastUsesRemainingPrincipalDailyInterest() + { + var service = new StubEodPositionService(); + var td = CreateTrade(); + var position = CreateInterestPosition(); + var previousEod = CreatePreEod(StartDate.AddDays(2), 100m); + previousEod.TdInterestPrincipal = Principal; + var closeFlow = CreateSwapFlowEvent(StartDate.AddDays(3), 50m); + closeFlow.EventType = (int)SwapFlowEventTypeEnum.平仓; + + var result = service.ExecuteSaveAutoEodWithCloseInterestPosition( + previousEod, position, td, StartDate.AddDays(3), null, + 500m, 0m, new List { closeFlow }, 500m, false); + + AssertDecimal(500m * FixedRate / AnnualDays, result.TdInterestIncome, + "不算尾部分平仓的当日新计利息只应包含剩余持仓部分"); + } + [TestMethod] public void DI_AUTO_SETTLEMENT_005_AutoSettlementKeepsRemainingPrincipal() { diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index 35214d22..41ef4f4c 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -1343,7 +1343,8 @@ namespace YLErp.Modules.SwapModule positions.Add(position); List preEodPositions = new List(); preEodPositions.Add(eodPayPosition); - var interests = CalcSwapInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, closeNational, 1, eventType, false, true, grossPrice, orginPv, true, settment: false, newCalcLast: true); + var calcLast = tradeExtend?.InterestCalcMode?.EndsWith("1") ?? true; + var interests = CalcSwapInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, closeNational, 1, eventType, false, true, grossPrice, orginPv, true, settment: false, newCalcLast: autoSwap || calcLast); decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount); decimal interestAmountBeforeSettlement = interests.Sum(x => x.InterestAmount); decimal manualSettledInterestAmount = flowEvents.Sum(x => x.InterestAmount); @@ -1399,7 +1400,9 @@ namespace YLErp.Modules.SwapModule { intersetAcmount /= tradeExtend.AnnualDays; } - newEodPayPosition.TdInterestIncome = intersetAcmount; + newEodPayPosition.TdInterestIncome = !autoSwap && calcLast + ? TdInterestAmount - lastInterestIncomeSum + : intersetAcmount; Log.Info($"InterestIncomeSum is {lastInterestIncomeSum},TdInterestIncome is {newEodPayPosition.TdInterestIncome}" + $",TdCloseInterest is {newEodPayPosition.TdCloseInterest}"); Log.Info($"InterestFeeSum is {eodPayPosition.InterestFeeSum},TdInterestFee is {newEodPayPosition.TdInterestFee}" +