test(swap): 添加消费利息场景测试用例并修复重置日利息计算逻辑
- 添加CI_010_EodResetWithoutCloseCarriesFullPendingInterest测试方法 - 验证无平仓重置日必须完整并入上一期累计待实现利息的场景 - 修复CalcDailyCompoundInterestByEod方法中剩余百分比计算逻辑 - 使用posiPrincipal替代preEodPosition.TdInterestPrincipal进行计算 - 确保重置日期计算中本金比例的准确性
This commit is contained in:
@@ -473,5 +473,47 @@ namespace YLErp.Modules.SwapModule
|
||||
AssertDecimal(pendingInterest, result.InterestAmount,
|
||||
"calcLast=false must not accrue unwind-date interest after the previous EOD");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CI_010_EodResetWithoutCloseCarriesFullPendingInterest()
|
||||
{
|
||||
const decimal principal = 303139117.80m;
|
||||
const decimal previousBase = 303230391.742592383565m;
|
||||
const decimal pendingInterest = 184331.611361300669m;
|
||||
var startDate = new DateTime(2026, 4, 21);
|
||||
var resetDate = new DateTime(2026, 4, 28);
|
||||
var position = new swap_position
|
||||
{
|
||||
PosiStartDate = startDate,
|
||||
InterestType = (int)InterestTypeEnum.复利,
|
||||
InterestRateDefault = 0.0025m,
|
||||
InterestSwapInterval = JsonConvert.SerializeObject(new List<IntervalModel>()),
|
||||
IsAnnualized = true,
|
||||
interest_rest_days = 7,
|
||||
FloatRateUnderlyingCode = "FR007"
|
||||
};
|
||||
var preEod = new eod_swap_position
|
||||
{
|
||||
id = 1,
|
||||
ValueDate = resetDate.AddDays(-1),
|
||||
TdInterestPrincipal = previousBase,
|
||||
InterestIncomeSum = pendingInterest,
|
||||
InterestProfitSum = pendingInterest,
|
||||
FloatRate = 0.013502m
|
||||
};
|
||||
var flowEvent = new swap_flow_event { InterestRate = 0.0025m };
|
||||
var service = new StubSwapDealService(
|
||||
new OptUserInfo(0, nameof(ConsumedInterestScenarioTest), OptUserFrom.UnitTest),
|
||||
d => 0.0139);
|
||||
decimal interestAmount = 0m;
|
||||
decimal tdInterestAmount = 0m;
|
||||
|
||||
service.CalcDailyCompoundInterestByEod(preEod, resetDate, startDate, position,
|
||||
principal, principal, flowEvent, AnnualDays, false, 0.013502m, 1m, principal,
|
||||
ref interestAmount, ref tdInterestAmount);
|
||||
|
||||
AssertDecimal(principal + pendingInterest, flowEvent.InterestPrincipal,
|
||||
"无平仓重置日必须完整并入上一期累计待实现利息");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,8 +1417,8 @@ namespace YLErp.Modules.SwapModule
|
||||
var days = (endDate - tradeDate).Days;
|
||||
if (days % interestPeriod == 0)
|
||||
{
|
||||
var remainingPercent = preEodPosition.TdInterestPrincipal > 0m
|
||||
? principal / preEodPosition.TdInterestPrincipal
|
||||
var remainingPercent = posiPrincipal > 0m
|
||||
? principal / posiPrincipal
|
||||
: 1m;
|
||||
remainingPercent = Math.Max(0m, Math.Min(1m, remainingPercent));
|
||||
tdDynomicPrincipal = tdDynomicPrincipal + interestProfitSum * remainingPercent;
|
||||
|
||||
Reference in New Issue
Block a user