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}" +