fix(swap): 修复部分平仓计息计算中的尾差处理问题
- 修正了部分平仓后待实现利息收入的预期值从 0.006383561644 到 -0.010438356164 - 修正了预期待实现利息值从 0.820569301369 到 0.410474008219 - 在 SwapDealService 中添加了已完成平仓事件的查询逻辑,排除已平仓头寸的本金计算 - 重构了 SwapEodPositionService 中的待结算利息计算逻辑,区分自动互换和平仓场景 - 在测试类中添加了已完成流程事件的查找方法和相关测试数据 - 更新了测试用例以验证平仓事件对利息计算的影响
This commit is contained in:
@@ -700,6 +700,9 @@ namespace YLErp.Modules.SwapModule
|
||||
|| x.InterestMode == (int)InterestModeEnum.追加预付金)
|
||||
.GroupBy(x => x.PositionId)
|
||||
.ToDictionary(x => x.Key, x => x.Sum(v => v.InterestPrincipal));
|
||||
var priorClosePositionIds = new HashSet<long>((completedFlowEvents ?? Enumerable.Empty<swap_flow_event>())
|
||||
.Where(x => x.EventType == (int)SwapEventTypeEnum.平仓 && x.EventDate <= settleDate)
|
||||
.Select(x => x.PositionId));
|
||||
|
||||
return origPositions.Where(x => x.PosiDirection == 0).Select(p =>
|
||||
{
|
||||
@@ -709,6 +712,10 @@ namespace YLErp.Modules.SwapModule
|
||||
var realLeg = realPositions.FirstOrDefault(r => r.PositionId == p.id);
|
||||
if (realLeg != null)
|
||||
{
|
||||
if (!priorClosePositionIds.Contains(p.id))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
var futurePrincipal = hasNotionalFlows
|
||||
? p.InterestPrincipalFix * futureCloseNotional / originalNotional
|
||||
: futureClosePrincipal.TryGetValue(p.id, out var flowPrincipal) ? flowPrincipal : 0m;
|
||||
|
||||
@@ -1412,12 +1412,9 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
else
|
||||
{
|
||||
var useAccrualBalance = !autoSwap
|
||||
&& (position.InterestMode == (int)InterestModeEnum.初始预付金
|
||||
|| position.InterestMode == (int)InterestModeEnum.追加预付金);
|
||||
var pendingInterestBeforeSettlement = useAccrualBalance
|
||||
? lastInterestIncomeSum + newEodPayPosition.TdInterestIncome
|
||||
: interestAmountBeforeSettlement;
|
||||
var pendingInterestBeforeSettlement = autoSwap
|
||||
? interestAmountBeforeSettlement
|
||||
: lastInterestIncomeSum + newEodPayPosition.TdInterestIncome;
|
||||
newEodPayPosition.InterestIncomeSum = RoundEodInterest(
|
||||
pendingInterestBeforeSettlement - newEodPayPosition.TdCloseInterest);
|
||||
newEodPayPosition.InterestFeeSum = eodPayPosition.InterestFeeSum + newEodPayPosition.TdInterestFee - newEodPayPosition.TdCloseInterestFee;
|
||||
|
||||
Reference in New Issue
Block a user