refactor(funding-leg): 修复2个类名+补DividendCalc注释
采纳命名审查建议(优先级最高的2项): 1. UnderlyingFullPriceLeg → UnderlyingEntryFullPriceLeg 补齐'期初(Entry)'——建仓时点全价, 非当前全价, 金融上是不同计息口径 2. FixedNotionalLeg → FixedAmountLeg 去掉误导性的Notional——'固定值'是合同写死的数额, 不一定是名义本金, 避免与ContractNotionalLeg的Notional概念撞车 3. DividendCalc 补充注释: 业务含义(债券票息+股票分红统一用Dividend)、 税务口径(还原不含税再扣税)、命名保持理由 验证: 编译0错误, 全量507测试7失败(基线一致)。
This commit is contained in:
@@ -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]
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
using YLErp.DBModels;
|
||||
using YLErp.Modules.SwapModule.FundingLegs;
|
||||
|
||||
namespace YLErp.Modules.SwapModule.FundingLegs;
|
||||
|
||||
/// <summary>
|
||||
/// 固定值融资腿(InterestMode=固定值)。
|
||||
/// 计息基数由合约约定(InterestPrincipalFix),无论平仓比例多少都恒等于该值。
|
||||
/// 业务规则:固定值就是合同写死的固定值,永远不变。
|
||||
/// 业务规则:固定值就是合同写死的固定数额(Amount),永远不变。
|
||||
/// 不叫 FixedNotionalLeg——"固定值"不一定是"名义本金(Notional)",避免与 ContractNotionalLeg 概念撞车。
|
||||
/// </summary>
|
||||
public sealed class FixedNotionalLeg : IFundingLegStrategy
|
||||
public sealed class FixedAmountLeg : IFundingLegStrategy
|
||||
{
|
||||
public InterestModeEnum Mode => InterestModeEnum.固定值;
|
||||
|
||||
@@ -17,9 +17,9 @@ public static class FundingLegStrategyFactory
|
||||
{
|
||||
private static readonly Dictionary<InterestModeEnum, IFundingLegStrategy> _strategies = new()
|
||||
{
|
||||
[InterestModeEnum.固定值] = new FixedNotionalLeg(),
|
||||
[InterestModeEnum.固定值] = new FixedAmountLeg(),
|
||||
[InterestModeEnum.合约名义本金规模] = new ContractNotionalLeg(),
|
||||
[InterestModeEnum.标的期初全价] = new UnderlyingFullPriceLeg(),
|
||||
[InterestModeEnum.标的期初全价] = new UnderlyingEntryFullPriceLeg(),
|
||||
};
|
||||
|
||||
/// <summary>按 mode 返回对应策略。未注册的 mode 抛 ArgumentException。</summary>
|
||||
|
||||
+3
-2
@@ -4,12 +4,13 @@ namespace YLErp.Modules.SwapModule.FundingLegs;
|
||||
|
||||
/// <summary>
|
||||
/// 标的期初全价融资腿(InterestMode=标的期初全价)。
|
||||
/// 站在"持仓全价"视角:计息基数 = 标的含费全价(PosiGrossPrice/EntryDirtyPrice) × 数量。
|
||||
/// 计息基数 = 标的期初含费全价(PosiGrossPrice/EntryDirtyPrice) × 数量。
|
||||
/// "期初(Entry)"是关键——建仓时点的全价,非当前估值全价。
|
||||
/// 主路径 CalcNotionalByMode 公式与合约名义本金规模(2)相同;
|
||||
/// 差异在衡泰路径会乘 grossPrice 折算(SwapDealService.GetUnwindInterestsByHT),
|
||||
/// 以及 EOD 复利部分平仓后直接返回剩余本金(禁止反推,SwapEodPositionService:1458-1465)。
|
||||
/// </summary>
|
||||
public sealed class UnderlyingFullPriceLeg : IFundingLegStrategy
|
||||
public sealed class UnderlyingEntryFullPriceLeg : IFundingLegStrategy
|
||||
{
|
||||
public InterestModeEnum Mode => InterestModeEnum.标的期初全价;
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
namespace YLErp.Modules.SwapModule.ReturnLegs;
|
||||
|
||||
/// <summary>
|
||||
/// 标的端分红(票息)计算。
|
||||
/// 标的端分红/票息的增值税计算。
|
||||
///
|
||||
/// 增值税后票息 = 税前票息 / (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 字段,收益不匹配。
|
||||
/// </summary>
|
||||
public static class DividendCalc
|
||||
{
|
||||
/// <summary>增值税后票息,四舍五入到 2 位。</summary>
|
||||
/// <summary>增值税后票息/分红,四舍五入到分(2位)。</summary>
|
||||
public static decimal AfterTax(decimal payment, decimal tax)
|
||||
=> Math.Round(payment / (1 + tax) * (1 - tax), 2);
|
||||
|
||||
/// <summary>增值税后票息(不四舍五入,供中间计算用)。</summary>
|
||||
/// <summary>增值税后票息/分红(不四舍五入,供中间计算用)。</summary>
|
||||
public static decimal AfterTaxRaw(decimal payment, decimal tax)
|
||||
=> payment / (1 + tax) * (1 - tax);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user