fix(swap): 统一处理【名义本金】数值精度舍入问题

- 在多个位置添加 Math.Round 函数确保金额计算精度
- 新增 NormalizeNotionalValues 方法统一处理 UnwindData 中的名义本金舍入
- 修复交易平仓时 StockEqvNotional 扣减计算的精度问题
- 解决持仓数据 PosiNotionalValue 的精度舍入处理
- 修复前端页面显示格式化问题
- 添加单元测试验证名义本金舍入逻辑正确性
This commit is contained in:
张名锐
2026-07-22 13:05:49 +08:00
parent e7c6e432e1
commit 0755233ab6
7 changed files with 53 additions and 21 deletions
@@ -332,7 +332,7 @@ namespace YLErp.Modules.SwapModule
AssetBookName = asset.Name,
Notional = Convert.ToDouble(flowMerge.TradingQtyAbs),
TradeAmount = Convert.ToDouble(flowMerge.TradingQtyAbs),
StockEqvNotional = Convert.ToDouble(flowMerge.TradingAmount),
StockEqvNotional = Math.Round(Convert.ToDouble(flowMerge.TradingAmount), ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero),
IsAutoGenerate = true,
};
if (flowMerge.SettleDate.HasValue)
@@ -374,7 +374,7 @@ namespace YLErp.Modules.SwapModule
PosiNetFeePrice = flowMerge.TradingAmountNetFeeAvg ?? 0,
PosiNetNoFeePrice = flowMerge.TradingAmountNetAvg ?? 0,
PosiQuantity = flowMerge.TradingQtyAbs,
PosiNotionalValue = flowMerge.TradingAmount,
PosiNotionalValue = Math.Round(flowMerge.TradingAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero),
PosiTradingFeePending = flowMerge.TradingFeePending,
PosiTradingFee = 0,
PosiTradingFeeUnit = 0,
@@ -762,6 +762,7 @@ namespace YLErp.Modules.SwapModule
req.SpotPrice = Convert.ToDouble(swapPosition.PosiNetPrice);
}
req.Strike = null;
req.StockEqvNotional = Math.Round(req.StockEqvNotional, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
req.OriginalStockEqvNotional = req.StockEqvNotional;
req.StockEqvNotionalReal = req.StockEqvNotional;
@@ -1355,7 +1356,7 @@ namespace YLErp.Modules.SwapModule
position.PosiNetNoFeePrice = swap.PosiNetNoFeePrice;
position.PosiNetFeePrice = swap.PosiQuantity == 0 ? 0 : (swap.PosiNetNoFeePrice + (position.PosiTradingFeePending / swap.PosiQuantity) * ratio);
position.PosiNetFeePrice = Math.Round(position.PosiNetFeePrice??0, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero);
position.PosiNotionalValue = swap.PosiNotionalValue;
position.PosiNotionalValue = Math.Round(swap.PosiNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
position.PosiQuantity = swap.PosiQuantity;
position.InterestDirection = swap.InterestDirection;
position.InterestMode = swap.InterestMode;
@@ -1479,7 +1480,7 @@ namespace YLErp.Modules.SwapModule
td.ProcessStatus = null;
if (backToBegin)
{
td.StockEqvNotional = td.OriginalStockEqvNotional ?? 0;
td.StockEqvNotional = Math.Round(td.OriginalStockEqvNotional ?? 0, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
td.UnWindDate = null;
td.HasPartialUnWind = null;
SingleTradeBackToBegin(td, swapPositions);
@@ -1641,10 +1642,10 @@ namespace YLErp.Modules.SwapModule
posi.PosiGrossPrice = eodPosi.PosiGrossPrice;
posi.PosiNetFeePrice = eodPosi.PosiNetFeePrice;
posi.PosiNetNoFeePrice = eodPosi.PosiNetNoFeePrice;
posi.PosiNotionalValue = eodPosi.PosiNotionalValue;
posi.PosiNotionalValue = Math.Round(eodPosi.PosiNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
if (posi.PosiDirection > 0)
{
td.StockEqvNotional = Convert.ToDouble(posi.PosiNotionalValue);
td.StockEqvNotional = Math.Round(Convert.ToDouble(posi.PosiNotionalValue), ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
td.TradeAmount = Convert.ToDouble(posi.PosiQuantity);
}
}