refactor(return-leg): 4处增值税inline公式替换为 DividendCalc

SwapEodPositionService 4处 payment/(1+tax)*(1-tax) inline 替换:
- 1804/1906/2094: Math.Round(...) → DividendCalc.AfterTax(payment, tax)
- 1893: 中间计算(不四舍五入) → DividendCalc.AfterTaxRaw(total, tax)

修复 MtmCalcTest: UnrealizedPnl 第6参数 ratio 从 1m 改为 1(int)。
(1+tax) inline 公式出现次数: 4 → 0。

验证: 编译0错误, 全量507测试7失败(基线一致)。
This commit is contained in:
hjhan
2026-08-11 11:12:15 +08:00
parent 939d6a4271
commit c52d439469
2 changed files with 7 additions and 13 deletions
@@ -9,14 +9,12 @@ namespace UnitTestProject.Modules.SwapModule.ReturnLegs
[TestMethod]
public void MarketValue_多头_为正()
{
// 标的价100 × 1000张 × 乘数1 × 多头(+1) = 100000
Assert.AreEqual(100_000m, MtmCalc.MarketValue(100m, 1000m, 1m, 1));
}
[TestMethod]
public void MarketValue_空头_为负()
{
// 空头 shortRatio=-1
Assert.AreEqual(-100_000m, MtmCalc.MarketValue(100m, 1000m, 1m, -1));
}
@@ -29,22 +27,19 @@ namespace UnitTestProject.Modules.SwapModule.ReturnLegs
[TestMethod]
public void UnrealizedPnl_多头浮盈()
{
// (105-100) × 1000 × 1 × 1 × 1 = 5000
Assert.AreEqual(5000m, MtmCalc.UnrealizedPnl(105m, 100m, 1000m, 1m, 1, 1m));
Assert.AreEqual(5000m, MtmCalc.UnrealizedPnl(105m, 100m, 1000m, 1m, 1, 1));
}
[TestMethod]
public void UnrealizedPnl_多头浮亏()
{
// (95-100) × 1000 × 1 × 1 × 1 = -5000
Assert.AreEqual(-5000m, MtmCalc.UnrealizedPnl(95m, 100m, 1000m, 1m, 1, 1m));
Assert.AreEqual(-5000m, MtmCalc.UnrealizedPnl(95m, 100m, 1000m, 1m, 1, 1));
}
[TestMethod]
public void UnrealizedPnl_空头反向()
{
// 空头: 价格跌=盈利 (95-100) × 1000 × 1 × (-1) × 1 = 5000
Assert.AreEqual(5000m, MtmCalc.UnrealizedPnl(95m, 100m, 1000m, 1m, -1, 1m));
Assert.AreEqual(5000m, MtmCalc.UnrealizedPnl(95m, 100m, 1000m, 1m, -1, 1));
}
}
}
@@ -1800,8 +1800,7 @@ namespace YLErp.Modules.SwapModule
if (valueDate > td.StartDate.Value && curretEod.PosiQuantity > 0)
{
decimal payment = CalcBondPayment(curretEod.UnderlyingCode, eod.ValueDate, valueDate, curretEod.PosiQuantity, shortRatio, directionRatio);
// 考虑增值税
curretEod.TdPosiDividend = Math.Round(payment / (1 + tax) * (1 - tax), 2);
curretEod.TdPosiDividend = DividendCalc.AfterTax(payment, tax);
}
curretEod.PosiDividendSum = eod.PosiQuantity > 0 ? Math.Round(eod.PosiDividendSum + curretEod.TdPosiDividend, 2) : 0;
curretEod.PosiQuantity = eod.PosiQuantity;
@@ -1891,7 +1890,7 @@ namespace YLErp.Modules.SwapModule
var originNotional = (decimal)td.OriginalStockEqvNotional / swapPosition.PosiNetPrice;
decimal totalPayment = CalcBondPayment(curretEod.UnderlyingCode, td.StartDate.Value, valueDate, (decimal)originNotional, shortRatio, directionRatio);
decimal tax = um.ValueAddedTax ?? 0;
decimal totalInterest = totalPayment / (1 + tax) * (1 - tax);
decimal totalInterest = DividendCalc.AfterTaxRaw(totalPayment, tax);
SetPriceInfoByFlowEvent(eod, curretEod, unwindEvents, swapPosition);
curretEod.dv01 = Dv01Helper.CalcDv01(eod.UnderlyingCode, curretEod.PosiQuantity, eod.PosiDirection, eod.PositionType, vobp);
curretEod.UnderlyingPrice = price;
@@ -1903,7 +1902,7 @@ namespace YLErp.Modules.SwapModule
if (valueDate > td.StartDate.Value && (curretEod.PosiQuantity > 0))
{
decimal payment = CalcBondPayment(curretEod.UnderlyingCode, eod.ValueDate, valueDate, curretEod.PosiQuantity, shortRatio, directionRatio);
curretEod.TdPosiDividend = Math.Round(payment / (1 + tax) * (1 - tax), 2);
curretEod.TdPosiDividend = DividendCalc.AfterTax(payment, tax);
}
curretEod.RealizedMtmPnL = eod.RealizedMtmPnL + curretEod.TdCloseMtmPnl;
// 当日浮动端平仓盈亏·分红(仅来自平仓事件 和 互换 中已实现的分红)
@@ -2092,7 +2091,7 @@ namespace YLErp.Modules.SwapModule
{
decimal tax = um.ValueAddedTax ?? 0;
decimal payment = CalcBondPayment(curretEod.UnderlyingCode, td.StartDate.Value, settleDate, curretEod.PosiQuantity, shortRatio, directionRatio);
payment = Math.Round(payment / (1 + tax) * (1 - tax), 2);
payment = DividendCalc.AfterTax(payment, tax);
//var consumedDividend = CalcConsumedDividend(curretEod, unwindEvents); 首日应该没有分红
curretEod.TdPosiDividend = payment;
curretEod.PosiDividendSum = payment;