fix(swap): 结算或全部平仓后,待实现置0
- 添加 NormalizeSettledInterestAmounts 方法处理手工平仓和互换的利息事件精度 - 添加 NormalizeManualSettlementAmounts 方法在手工结算前收敛流水金额 - 将利息计算精度从 ConsGlobal.PriceRound 统一调整为 InterestCalculationPrecision(12位) - 在日终持仓快照中添加精度标准化处理,利息腿保留12位精度 - 修复全量平仓时待实现利息和费用的清零逻辑 - 在收益结算事件后清空待实现利息余额避免重复计算 - 更新单元测试验证现金与两位利息事件的一致性
This commit is contained in:
@@ -258,5 +258,36 @@ namespace YLErp.Modules.SwapModule
|
||||
Assert.AreEqual(500000.00m, savedData.CloseNotionalValue, "平仓名义本金应按两位小数写入事件");
|
||||
Assert.AreEqual(500000.01, td.StockEqvNotional, 0.000001, "trade 剩余名义本金应在扣减后舍入两位小数");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UW_010_SwapUnwind_现金与两位利息事件保持一致()
|
||||
{
|
||||
var td = SwapDealTestFactory.CreateTrade();
|
||||
var service = new TestableSwapDealService(td);
|
||||
var unwindData = SwapDealTestFactory.CreateUnwindData(
|
||||
swapRealizedPnL: 10.0049m, closeMethod: (int)CloseMethodEnum.全部平仓,
|
||||
closePercent: 1m, closeQty: 10000m, closeNotionalValue: 1000000m, positionQty: 10000m);
|
||||
var floatEvent = new swap_flow_event
|
||||
{
|
||||
UnderlyingCode = "UT-FLOAT", PositionType = (int)PositionTypeFlag.Long,
|
||||
EventType = (int)SwapEventTypeEnum.平仓, PayDirection = 1, MarkClosePnl = 10m
|
||||
};
|
||||
var interestEvent = new swap_flow_event
|
||||
{
|
||||
PositionType = 0, InterestAmount = 0.0049m, TdInterestAmount = 0.0049m,
|
||||
InterestClosePnL = 0.0049m, InterestFee = 0.0049m
|
||||
};
|
||||
unwindData.FlowEvents.Add(floatEvent);
|
||||
unwindData.FlowEvents.Add(interestEvent);
|
||||
|
||||
service.SwapUnwind(unwindData);
|
||||
|
||||
Assert.AreEqual(0m, interestEvent.InterestAmount);
|
||||
Assert.AreEqual(0m, interestEvent.TdInterestAmount);
|
||||
Assert.AreEqual(0m, interestEvent.InterestClosePnL);
|
||||
Assert.AreEqual(0m, interestEvent.InterestFee);
|
||||
Assert.AreEqual(10m, unwindData.SwapRealizedPnL);
|
||||
Assert.AreEqual(-10d, service.ClientCashCalls[0].amount, 0.001d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user