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:
+29
-34
@@ -1,24 +1,23 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using YLErp.DBModels.Enums;
|
||||
using YLErp.Modules.SwapModule.InterestLegs;
|
||||
using YLErp.Modules.SwapModule.FundingLegs;
|
||||
|
||||
namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
namespace UnitTestProject.Modules.SwapModule.FundingLegs
|
||||
{
|
||||
/// <summary>
|
||||
/// 利息腿策略单测。验证每个策略的 CalcNotional 与现有 CalcNotionalByMode switch 完全一致。
|
||||
/// 融资腿策略单测。验证每个策略的 CalcNotional 与现有 CalcNotionalByMode switch 完全一致。
|
||||
/// 这组测试是后续"迁移调用点"的安全网——迁移前后行为必须不变。
|
||||
/// 注:原预付金(PrepayLeg)用例已迁出,见 MarginLegTest(保证金独立限界上下文)。
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class InterestLegStrategyTest
|
||||
public class FundingLegStrategyTest
|
||||
{
|
||||
private const decimal Fix = 2_000_000m; // 合约固定本金
|
||||
private const decimal Notional = 100_000_000m; // 剩余名义本金 1 亿
|
||||
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):恒=Fix,不随比例变
|
||||
#region 固定值(mode 1)
|
||||
|
||||
[TestMethod]
|
||||
public void 固定值_部分平仓_计息基数恒等于Fix()
|
||||
@@ -28,7 +27,7 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
|
||||
Assert.AreEqual(Fix, r.ClosePrincipal, "平仓本金恒=Fix");
|
||||
Assert.AreEqual(Fix, r.PosiPrincipal, "持仓本金恒=Fix");
|
||||
Assert.AreEqual(1m, r.ClosePercent, "有效比例恒=1(固定值不随比例缩放)");
|
||||
Assert.AreEqual(1m, r.ClosePercent);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -36,13 +35,12 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
{
|
||||
var leg = new FixedNotionalLeg();
|
||||
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
|
||||
|
||||
Assert.AreEqual(Fix, r.ClosePrincipal, "全平本金仍=Fix");
|
||||
Assert.AreEqual(Fix, r.ClosePrincipal);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 合约名义本金规模(mode 2):按比例线性缩放
|
||||
#region 合约名义本金规模(mode 2)
|
||||
|
||||
[TestMethod]
|
||||
public void 合约名义本金_部分平仓_本金按比例缩放()
|
||||
@@ -50,9 +48,9 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
var leg = new ContractNotionalLeg();
|
||||
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
|
||||
|
||||
Assert.AreEqual(50_000_000m, r.ClosePrincipal, "平仓本金=Notional×50%");
|
||||
Assert.AreEqual(Notional, r.PosiPrincipal, "持仓本金=Notional全额");
|
||||
Assert.AreEqual(0.5m, r.ClosePercent, "有效比例=入参");
|
||||
Assert.AreEqual(50_000_000m, r.ClosePrincipal);
|
||||
Assert.AreEqual(Notional, r.PosiPrincipal);
|
||||
Assert.AreEqual(0.5m, r.ClosePercent);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -60,8 +58,7 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
{
|
||||
var leg = new ContractNotionalLeg();
|
||||
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
|
||||
|
||||
Assert.AreEqual(Notional, r.ClosePrincipal, "全平本金=Notional");
|
||||
Assert.AreEqual(Notional, r.ClosePrincipal);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -70,13 +67,13 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
var leg = new ContractNotionalLeg();
|
||||
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0m);
|
||||
|
||||
Assert.AreEqual(0m, r.ClosePrincipal, "零平仓本金=0");
|
||||
Assert.AreEqual(Notional, r.PosiPrincipal, "持仓本金仍=Notional");
|
||||
Assert.AreEqual(0m, r.ClosePrincipal);
|
||||
Assert.AreEqual(Notional, r.PosiPrincipal);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 标的期初全价(mode 9):主路径公式与mode2相同
|
||||
#region 标的期初全价(mode 9)
|
||||
|
||||
[TestMethod]
|
||||
public void 标的期初全价_部分平仓_主路径公式同mode2()
|
||||
@@ -84,7 +81,7 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
var leg = new UnderlyingFullPriceLeg();
|
||||
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
|
||||
|
||||
Assert.AreEqual(50_000_000m, r.ClosePrincipal, "平仓本金=Notional×50%(与mode2主路径一致)");
|
||||
Assert.AreEqual(50_000_000m, r.ClosePrincipal);
|
||||
Assert.AreEqual(Notional, r.PosiPrincipal);
|
||||
Assert.AreEqual(0.5m, r.ClosePercent);
|
||||
}
|
||||
@@ -94,13 +91,12 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
{
|
||||
var leg = new UnderlyingFullPriceLeg();
|
||||
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
|
||||
|
||||
Assert.AreEqual(Notional, r.ClosePrincipal);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 守卫:策略对应各自mode
|
||||
#region 守卫
|
||||
|
||||
[TestMethod]
|
||||
public void 各策略对应正确枚举值()
|
||||
@@ -112,35 +108,34 @@ namespace UnitTestProject.Modules.SwapModule.InterestLegs
|
||||
|
||||
#endregion
|
||||
|
||||
#region 工厂:按mode分发
|
||||
#region 工厂
|
||||
|
||||
[TestMethod]
|
||||
public void 工厂_返回各活跃mode的策略()
|
||||
{
|
||||
Assert.IsInstanceOfType(InterestLegStrategyFactory.Get(InterestModeEnum.固定值), typeof(FixedNotionalLeg));
|
||||
Assert.IsInstanceOfType(InterestLegStrategyFactory.Get(InterestModeEnum.合约名义本金规模), typeof(ContractNotionalLeg));
|
||||
Assert.IsInstanceOfType(InterestLegStrategyFactory.Get(InterestModeEnum.标的期初全价), typeof(UnderlyingFullPriceLeg));
|
||||
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>(() =>
|
||||
InterestLegStrategyFactory.Get(InterestModeEnum.持仓名义本金));
|
||||
FundingLegStrategyFactory.Get(InterestModeEnum.持仓名义本金));
|
||||
Assert.ThrowsException<ArgumentException>(() =>
|
||||
InterestLegStrategyFactory.Get(InterestModeEnum.持仓市值));
|
||||
// 预付金 5/6 已不再是利息腿,工厂不再注册,按未注册处理
|
||||
FundingLegStrategyFactory.Get(InterestModeEnum.持仓市值));
|
||||
Assert.ThrowsException<ArgumentException>(() =>
|
||||
InterestLegStrategyFactory.Get(InterestModeEnum.初始预付金));
|
||||
FundingLegStrategyFactory.Get(InterestModeEnum.初始预付金));
|
||||
Assert.ThrowsException<ArgumentException>(() =>
|
||||
InterestLegStrategyFactory.Get(InterestModeEnum.追加预付金));
|
||||
FundingLegStrategyFactory.Get(InterestModeEnum.追加预付金));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void 工厂_int重载和枚举重载等价()
|
||||
{
|
||||
var byEnum = InterestLegStrategyFactory.Get(InterestModeEnum.固定值);
|
||||
var byInt = InterestLegStrategyFactory.Get((int)InterestModeEnum.固定值);
|
||||
var byEnum = FundingLegStrategyFactory.Get(InterestModeEnum.固定值);
|
||||
var byInt = FundingLegStrategyFactory.Get((int)InterestModeEnum.固定值);
|
||||
Assert.AreEqual(byEnum.Mode, byInt.Mode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user