diff --git a/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs b/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs index cae1d332..b3d71a43 100644 --- a/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs +++ b/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs @@ -22,7 +22,7 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 固定值_部分平仓_计息基数恒等于Fix() { - var leg = new FixedNotionalLeg(); + var leg = new FixedAmountLeg(); var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m); Assert.AreEqual(Fix, r.ClosePrincipal, "平仓本金恒=Fix"); @@ -33,7 +33,7 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 固定值_全平_计息基数仍等于Fix() { - var leg = new FixedNotionalLeg(); + var leg = new FixedAmountLeg(); var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m); Assert.AreEqual(Fix, r.ClosePrincipal); } @@ -78,7 +78,7 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 标的期初全价_部分平仓_主路径公式同mode2() { - var leg = new UnderlyingFullPriceLeg(); + var leg = new UnderlyingEntryFullPriceLeg(); var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m); Assert.AreEqual(50_000_000m, r.ClosePrincipal); @@ -89,7 +89,7 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 标的期初全价_全平_本金等于全额() { - var leg = new UnderlyingFullPriceLeg(); + var leg = new UnderlyingEntryFullPriceLeg(); var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m); Assert.AreEqual(Notional, r.ClosePrincipal); } @@ -101,9 +101,9 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 各策略对应正确枚举值() { - Assert.AreEqual(InterestModeEnum.固定值, new FixedNotionalLeg().Mode); + Assert.AreEqual(InterestModeEnum.固定值, new FixedAmountLeg().Mode); Assert.AreEqual(InterestModeEnum.合约名义本金规模, new ContractNotionalLeg().Mode); - Assert.AreEqual(InterestModeEnum.标的期初全价, new UnderlyingFullPriceLeg().Mode); + Assert.AreEqual(InterestModeEnum.标的期初全价, new UnderlyingEntryFullPriceLeg().Mode); } #endregion @@ -113,9 +113,9 @@ namespace UnitTestProject.Modules.SwapModule.FundingLegs [TestMethod] public void 工厂_返回各活跃mode的策略() { - Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.固定值), typeof(FixedNotionalLeg)); + Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.固定值), typeof(FixedAmountLeg)); Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.合约名义本金规模), typeof(ContractNotionalLeg)); - Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.标的期初全价), typeof(UnderlyingFullPriceLeg)); + Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.标的期初全价), typeof(UnderlyingEntryFullPriceLeg)); } [TestMethod] diff --git a/YLErpDAL/Modules/SwapModule/FundingLegs/FixedNotionalLeg.cs b/YLErpDAL/Modules/SwapModule/FundingLegs/FixedAmountLeg.cs similarity index 64% rename from YLErpDAL/Modules/SwapModule/FundingLegs/FixedNotionalLeg.cs rename to YLErpDAL/Modules/SwapModule/FundingLegs/FixedAmountLeg.cs index fd85793c..6e477b07 100644 --- a/YLErpDAL/Modules/SwapModule/FundingLegs/FixedNotionalLeg.cs +++ b/YLErpDAL/Modules/SwapModule/FundingLegs/FixedAmountLeg.cs @@ -1,14 +1,14 @@ using YLErp.DBModels; -using YLErp.Modules.SwapModule.FundingLegs; namespace YLErp.Modules.SwapModule.FundingLegs; /// /// 固定值融资腿(InterestMode=固定值)。 /// 计息基数由合约约定(InterestPrincipalFix),无论平仓比例多少都恒等于该值。 -/// 业务规则:固定值就是合同写死的固定值,永远不变。 +/// 业务规则:固定值就是合同写死的固定数额(Amount),永远不变。 +/// 不叫 FixedNotionalLeg——"固定值"不一定是"名义本金(Notional)",避免与 ContractNotionalLeg 概念撞车。 /// -public sealed class FixedNotionalLeg : IFundingLegStrategy +public sealed class FixedAmountLeg : IFundingLegStrategy { public InterestModeEnum Mode => InterestModeEnum.固定值; diff --git a/YLErpDAL/Modules/SwapModule/FundingLegs/FundingLegStrategyFactory.cs b/YLErpDAL/Modules/SwapModule/FundingLegs/FundingLegStrategyFactory.cs index a909ec5e..ee4114ef 100644 --- a/YLErpDAL/Modules/SwapModule/FundingLegs/FundingLegStrategyFactory.cs +++ b/YLErpDAL/Modules/SwapModule/FundingLegs/FundingLegStrategyFactory.cs @@ -17,9 +17,9 @@ public static class FundingLegStrategyFactory { private static readonly Dictionary _strategies = new() { - [InterestModeEnum.固定值] = new FixedNotionalLeg(), + [InterestModeEnum.固定值] = new FixedAmountLeg(), [InterestModeEnum.合约名义本金规模] = new ContractNotionalLeg(), - [InterestModeEnum.标的期初全价] = new UnderlyingFullPriceLeg(), + [InterestModeEnum.标的期初全价] = new UnderlyingEntryFullPriceLeg(), }; /// 按 mode 返回对应策略。未注册的 mode 抛 ArgumentException。 diff --git a/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingFullPriceLeg.cs b/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs similarity index 75% rename from YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingFullPriceLeg.cs rename to YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs index 725717fd..f78d9b74 100644 --- a/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingFullPriceLeg.cs +++ b/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs @@ -4,12 +4,13 @@ namespace YLErp.Modules.SwapModule.FundingLegs; /// /// 标的期初全价融资腿(InterestMode=标的期初全价)。 -/// 站在"持仓全价"视角:计息基数 = 标的含费全价(PosiGrossPrice/EntryDirtyPrice) × 数量。 +/// 计息基数 = 标的期初含费全价(PosiGrossPrice/EntryDirtyPrice) × 数量。 +/// "期初(Entry)"是关键——建仓时点的全价,非当前估值全价。 /// 主路径 CalcNotionalByMode 公式与合约名义本金规模(2)相同; /// 差异在衡泰路径会乘 grossPrice 折算(SwapDealService.GetUnwindInterestsByHT), /// 以及 EOD 复利部分平仓后直接返回剩余本金(禁止反推,SwapEodPositionService:1458-1465)。 /// -public sealed class UnderlyingFullPriceLeg : IFundingLegStrategy +public sealed class UnderlyingEntryFullPriceLeg : IFundingLegStrategy { public InterestModeEnum Mode => InterestModeEnum.标的期初全价; diff --git a/YLErpDAL/Modules/SwapModule/ReturnLegs/DividendCalc.cs b/YLErpDAL/Modules/SwapModule/ReturnLegs/DividendCalc.cs index 1b9f898f..d2472360 100644 --- a/YLErpDAL/Modules/SwapModule/ReturnLegs/DividendCalc.cs +++ b/YLErpDAL/Modules/SwapModule/ReturnLegs/DividendCalc.cs @@ -1,18 +1,27 @@ namespace YLErp.Modules.SwapModule.ReturnLegs; /// -/// 标的端分红(票息)计算。 +/// 标的端分红/票息的增值税计算。 /// -/// 增值税后票息 = 税前票息 / (1+税率) × (1-税率) -/// 原代码在 SwapEodPositionService 4处重复此公式(1804/1894/1906/2095)。 +/// 业务含义:TRS 标的如果是债券,标的端会收到债券票息(coupon); +/// 如果是股票,会收到现金分红(cash dividend)。系统统一用 Dividend 字段链路表达。 +/// 本类只负责"增值税后金额"这一步纯数学,不涉及取价/归属/落库。 +/// +/// 税务口径:票息/分红属于金融服务应税收入,先除以(1+税率)还原不含税收入, +/// 再乘以(1-税率)扣减税负。公式:afterTax = payment / (1+tax) × (1-tax)。 +/// 原代码在 SwapEodPositionService 4处 + SwapDealService 1处 重复此公式。 +/// +/// 命名保持 DividendCalc 而非改为 CashFlow/Coupon—— +/// 因为系统里"分红"字段(DividendIn/PosiDividendSum)是统一链路,同时覆盖债券票息和股票分红, +/// 改名会制造新歧义且需同步改 DB 字段,收益不匹配。 /// public static class DividendCalc { - /// 增值税后票息,四舍五入到 2 位。 + /// 增值税后票息/分红,四舍五入到分(2位)。 public static decimal AfterTax(decimal payment, decimal tax) => Math.Round(payment / (1 + tax) * (1 - tax), 2); - /// 增值税后票息(不四舍五入,供中间计算用)。 + /// 增值税后票息/分红(不四舍五入,供中间计算用)。 public static decimal AfterTaxRaw(decimal payment, decimal tax) => payment / (1 + tax) * (1 - tax); }