fix(swap): 修复复利平仓时已结利息扣除计算问题
- 修改 CalcCompoundUnwind 方法添加 closePercent 参数用于部分平仓场景 - 更新复利平仓逻辑,将已结利息按平仓比例进行缩放扣除 - 添加部分平仓测试用例验证已结利息按比例扣除的正确性 - 修复了全部已结利息在部分平仓时被全额扣除的问题
This commit is contained in:
@@ -108,13 +108,13 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
|
||||
/// <summary>调用 GetInterests 获取复利利息(统一调用入口,settment:false走盘中平仓路径)</summary>
|
||||
private static swap_flow_event CalcCompoundUnwind(StubSwapDealService service, DateTime unwindDate)
|
||||
private static swap_flow_event CalcCompoundUnwind(StubSwapDealService service, DateTime unwindDate, decimal closePercent = 1m)
|
||||
{
|
||||
var td = CreateTrade();
|
||||
var position = CreateCompoundPosition();
|
||||
var interests = service.GetInterests(td, td.trade_extend, unwindDate, unwindDate,
|
||||
new List<eod_swap_position>(), new List<swap_position> { position },
|
||||
Principal, Principal, Principal, Principal, 1m,
|
||||
Principal, Principal, Principal, Principal, closePercent,
|
||||
(int)SwapEventTypeEnum.平仓, false, false, Principal, Principal,
|
||||
add: false, settment: false, newCalcLast: false);
|
||||
Assert.AreEqual(1, interests.Count);
|
||||
@@ -246,5 +246,19 @@ namespace YLErp.Modules.SwapModule
|
||||
$"全部已结再平仓利息应≈0(实际={result.InterestAmount:F6}),不应为负");
|
||||
Console.WriteLine($"全部已结平仓≈0({result.InterestAmount:F6})✅");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CI_005_partialClose_scalesConsumedInterest()
|
||||
{
|
||||
var unwindDate = StartDate.AddDays(10);
|
||||
const decimal closePercent = 0.4m;
|
||||
const decimal consumed = 100m;
|
||||
|
||||
var baseline = CalcCompoundUnwind(CreateService(0m), unwindDate, closePercent).InterestAmount;
|
||||
var result = CalcCompoundUnwind(CreateService(consumed), unwindDate, closePercent).InterestAmount;
|
||||
|
||||
AssertDecimal(baseline - consumed * closePercent, result,
|
||||
$"partial close should deduct consumed interest by closePercent ({closePercent})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user