Files
zszq-trs/UnitTestProject/Modules/SwapModule/SwapUnwindFloatingLegDiagnosticTdd.cs
T
hjhan 70550af29a refactor(funding-leg): 清理CalcNotional死参数posiLong/posiShort+修正过时InterestMode注释
- 删除 IFundingLegStrategy.CalcNotional 的 posiLong/posiShort 死参数(多空存续腿界面已禁用,三个实现均不读取),同步三个实现签名、SwapDealService 唯一调用点、FundingLegStrategyTest 7 处调用
- 修正 SwapPosition/SwapFlowEvent/EodSwapPosition 的 InterestMode 字段注释(去掉已删的 3/4,补全 5/6/9)
- 重写 SwapUnwindFloatingLegDiagnosticTdd 过时类注释

零行为变化;编译 0 错误;FundingLegStrategyTest 11/11 通过。
2026-08-13 08:51:21 +08:00

71 lines
4.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Newtonsoft.Json;
using YLErp.DBModels;
using YLErp.DBModels.Enums;
namespace YLErp.Modules.SwapModule
{
/// <summary>
/// 诊断测试骨架:针对 GLMS 双轨持仓(orig/real)构造预付金腿(mode 5)与标的期初全价腿(mode 9)
/// 用于验证“浮动腿 fpositions 用 origPositions 对预付金/标的端计息基数的影响”。
/// 计息基数现由 FundingLegStrategyFactory + 各 IFundingLegStrategy 策略类计算
/// (原 private CalcNotionalByMode 已重构移除);多空存续腿的 posiLong/posiShort 因界面禁用
/// 已从策略接口删除,故预付金/标的端计息基数不依赖多空头寸。
/// 注:当前仅含数据构造,反射诊断方法尚未实现(无 [TestMethod])。
/// </summary>
[TestClass]
public class SwapUnwindFloatingLegDiagnosticTdd
{
private sealed class StubSwapDealService : SwapDealService
{
public StubSwapDealService(OptUserInfo optUser) : base(optUser) { }
protected override bool TryGetFloatRate(DateTime valueDate, string underlyingCode, out double rate)
{ rate = 0; return false; }
}
private const decimal OrigFix = 99_000m; // 期初预付金腿初始本金
private const decimal RealFix = 66_813.12m; // 实时预付金腿剩余本金(4 次平仓后)
private const decimal OrigLong = 100_000_000m; // 期初标的(多头)名义本金
private const decimal RealLong = 68_947_200m; // 实时标的(多头)剩余名义本金
private const decimal ClosePct = 0.1m; // 本次平仓比例 10%
private static readonly DateTime D0 = new(2026, 7, 1);
private static readonly DateTime D1 = new(2026, 7, 16);
private SwapDealService _svc;
[TestInitialize] public void Init() => _svc = new StubSwapDealService(new OptUserInfo(0, nameof(SwapUnwindFloatingLegDiagnosticTdd), OptUserFrom.UnitTest));
// ---- GLMS 双轨持仓构造 ----
private static swap_position OrigPrepay(decimal fix = OrigFix) => new swap_position
{ id = 35798, SwapTradeId = 1993, PosiDirection = 0, InterestMode = (int)InterestModeEnum.初始预付金,
InterestPrincipalFix = fix, IsInitial = true, Invalid = false, InterestType = (int)InterestTypeEnum.单利,
interest_rest_days = 1, InterestDirection = (int)SwapDirectionEnum.收取, InterestSwapInterval = "[]" };
private static swap_position RealPrepay(decimal fix = RealFix) => new swap_position
{ id = 35871, SwapTradeId = 1993, PositionId = 35798, PosiDirection = 0, InterestMode = (int)InterestModeEnum.初始预付金,
InterestPrincipalFix = fix, IsInitial = false, Invalid = false, InterestType = (int)InterestTypeEnum.单利,
interest_rest_days = 1, InterestDirection = (int)SwapDirectionEnum.收取, InterestSwapInterval = "[]" };
private static swap_position OrigBasePrice() => new swap_position
{ id = 35797, SwapTradeId = 1993, PosiDirection = 0, InterestMode = (int)InterestModeEnum.标的期初全价,
InterestPrincipalFix = 0, IsInitial = true, Invalid = false, InterestType = (int)InterestTypeEnum.单利,
interest_rest_days = 1, InterestSwapInterval = "[]" };
private static swap_position RealBasePrice() => new swap_position
{ id = 35870, SwapTradeId = 1993, PositionId = 35797, PosiDirection = 0, InterestMode = (int)InterestModeEnum.标的期初全价,
InterestPrincipalFix = 0, IsInitial = false, Invalid = false, InterestType = (int)InterestTypeEnum.单利,
interest_rest_days = 1, InterestSwapInterval = "[]" };
private static swap_position OrigLongLeg() => new swap_position
{ id = 35799, SwapTradeId = 1993, PosiDirection = 2, PositionType = (int)PositionTypeFlag.Long, InterestMode = 0,
PosiNotionalValue = OrigLong, IsInitial = true, Invalid = false };
private static swap_position RealLongLeg() => new swap_position
{ id = 35872, SwapTradeId = 1993, PositionId = 35799, PosiDirection = 2, PositionType = (int)PositionTypeFlag.Long, InterestMode = 0,
PosiNotionalValue = RealLong, IsInitial = false, Invalid = false };
private static trade MakeTrade()
{
var extend = new trade_extend { TradeId = 1993, ExtendJson = JsonConvert.SerializeObject(new TradeExtendJson
{ AnnualDays = 365, InterestCalcMode = "10", SettlementRules = 0 }) };
return new trade { id = 1993, TradeNumber = "GLMS-20260701-0008", ClientId = 999998, TradeType = "收益互换",
TradeDate = D0, StartDate = D0, ExerciseDate = D1, TradeStatus = "确认成交", ValidState = "Valid",
StockEqvNotional = (double)RealLong, Notional = (double)RealLong, trade_extend = extend };
}
}
}