test(swap): 添加部分平仓利息计算测试用例

- 添加算尾部分平仓当日新计利息包含已平仓部分的测试
- 添加不算尾部分平仓当日新计利息只包含剩余持仓部分的测试
- 验证部分平仓待实现收益计算的正确性
This commit is contained in:
张名锐
2026-08-07 15:05:04 +08:00
parent 3a435ad89b
commit 6d6729cf9c
2 changed files with 49 additions and 2 deletions
@@ -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<swap_flow_event> { 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<swap_flow_event> { closeFlow }, 500m, false);
AssertDecimal(500m * FixedRate / AnnualDays, result.TdInterestIncome,
"不算尾部分平仓的当日新计利息只应包含剩余持仓部分");
}
[TestMethod]
public void DI_AUTO_SETTLEMENT_005_AutoSettlementKeepsRemainingPrincipal()
{
@@ -1343,7 +1343,8 @@ namespace YLErp.Modules.SwapModule
positions.Add(position);
List<eod_swap_position> preEodPositions = new List<eod_swap_position>();
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}" +