refactor: InterestLeg 改名 FundingLeg(业界标准 Financing Leg)

命名: InterestLeg→FundingLeg, 消除'interest'与通用'利息'歧义。
Funding精确表达'融资成本'(客户付券商的杠杆成本 spread+FR007)。

改名清单:
- IInterestLegStrategy → IFundingLegStrategy
- InterestLegStrategyFactory → FundingLegStrategyFactory
- InterestLegStrategyTest → FundingLegStrategyTest
- 命名空间 InterestLegs → FundingLegs
- 目录 InterestLegs/ → FundingLegs/
- SwapDealService 引用同步更新

验证: 编译0错误, 全量503测试7失败(基线一致)。
This commit is contained in:
hjhan
2026-08-11 10:52:04 +08:00
parent a26f848287
commit 946cbbb66d
7 changed files with 78 additions and 78 deletions
@@ -0,0 +1,144 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YLErp.DBModels.Enums;
using YLErp.Modules.SwapModule.FundingLegs;
namespace UnitTestProject.Modules.SwapModule.FundingLegs
{
/// <summary>
/// 融资腿策略单测。验证每个策略的 CalcNotional 与现有 CalcNotionalByMode switch 完全一致。
/// 这组测试是后续"迁移调用点"的安全网——迁移前后行为必须不变。
/// </summary>
[TestClass]
public class FundingLegStrategyTest
{
private const decimal Fix = 2_000_000m;
private const decimal Notional = 100_000_000m;
private const decimal LongNotional = 60_000_000m;
private const decimal ShortNotional = 40_000_000m;
#region (mode 1)
[TestMethod]
public void _部分平仓_计息基数恒等于Fix()
{
var leg = new FixedNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
Assert.AreEqual(Fix, r.ClosePrincipal, "平仓本金恒=Fix");
Assert.AreEqual(Fix, r.PosiPrincipal, "持仓本金恒=Fix");
Assert.AreEqual(1m, r.ClosePercent);
}
[TestMethod]
public void _全平_计息基数仍等于Fix()
{
var leg = new FixedNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
Assert.AreEqual(Fix, r.ClosePrincipal);
}
#endregion
#region (mode 2)
[TestMethod]
public void _部分平仓_本金按比例缩放()
{
var leg = new ContractNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
Assert.AreEqual(50_000_000m, r.ClosePrincipal);
Assert.AreEqual(Notional, r.PosiPrincipal);
Assert.AreEqual(0.5m, r.ClosePercent);
}
[TestMethod]
public void _全平_本金等于全额()
{
var leg = new ContractNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
Assert.AreEqual(Notional, r.ClosePrincipal);
}
[TestMethod]
public void _零平仓_本金为零()
{
var leg = new ContractNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0m);
Assert.AreEqual(0m, r.ClosePrincipal);
Assert.AreEqual(Notional, r.PosiPrincipal);
}
#endregion
#region (mode 9)
[TestMethod]
public void _部分平仓_主路径公式同mode2()
{
var leg = new UnderlyingFullPriceLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
Assert.AreEqual(50_000_000m, r.ClosePrincipal);
Assert.AreEqual(Notional, r.PosiPrincipal);
Assert.AreEqual(0.5m, r.ClosePercent);
}
[TestMethod]
public void _全平_本金等于全额()
{
var leg = new UnderlyingFullPriceLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
Assert.AreEqual(Notional, r.ClosePrincipal);
}
#endregion
#region
[TestMethod]
public void ()
{
Assert.AreEqual(InterestModeEnum., new FixedNotionalLeg().Mode);
Assert.AreEqual(InterestModeEnum., new ContractNotionalLeg().Mode);
Assert.AreEqual(InterestModeEnum., new UnderlyingFullPriceLeg().Mode);
}
#endregion
#region
[TestMethod]
public void _返回各活跃mode的策略()
{
Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.), typeof(FixedNotionalLeg));
Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.), typeof(ContractNotionalLeg));
Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.), typeof(UnderlyingFullPriceLeg));
}
[TestMethod]
public void _未注册mode抛异常()
{
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.));
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.));
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.));
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.));
}
[TestMethod]
public void _int重载和枚举重载等价()
{
var byEnum = FundingLegStrategyFactory.Get(InterestModeEnum.);
var byInt = FundingLegStrategyFactory.Get((int)InterestModeEnum.);
Assert.AreEqual(byEnum.Mode, byInt.Mode);
}
#endregion
}
}