fix(swap): EQD-6977 无preEod兜底①=0且账龄超重置周期补退化告警trace——interestWindowEmpty(当日已结息)早退不重放覆盖种子值时①静默0(重置日分支本有同类告警,段中分支漏)复利每周期并本理应①>0;trace含事件基数/平仓本金两侧对比值+账龄天数+重置周期+疑似成因指向(interestWindowEmpty种子未重放/日终归档缺失)足够事后定位根因;承接块抽为ResolveCompoundCarry私有纯方法(Merge瘦身,三分支数据契约注释随行,行为零变化);TDD先行3例trace钉子:退化必告警(先红)/兜底>0不告警/真首日不告警;罚息域27例+GetInterests入口语义9例全绿

This commit is contained in:
hjhan
2026-08-21 07:10:04 +08:00
parent 8b66875098
commit 6e76f1c10d
2 changed files with 96 additions and 35 deletions
@@ -50,7 +50,8 @@ namespace UnitTestProject.Modules.SwapModule.Penalty
private static void RunMerge(
swap_position p, swap_flow_event normalEvent, eod_swap_position? preEod,
Func<swap_position, decimal>? getSpread = null, Func<DateTime, string, decimal?>? tryGetFixing = null)
Func<swap_position, decimal>? getSpread = null, Func<DateTime, string, decimal?>? tryGetFixing = null,
AccrualTrace? trace = null)
{
getSpread ??= _ => Rate;
tryGetFixing ??= (d, code) => Rate;
@@ -61,7 +62,8 @@ namespace UnitTestProject.Modules.SwapModule.Penalty
posiNotionalValue: Notional, closePosiNotionalValue: Notional, closePercent: 1m,
getSpread: getSpread,
getPreEod: _ => preEod,
tryGetFixing: tryGetFixing);
tryGetFixing: tryGetFixing,
trace: trace);
}
/// <summary>复利重放 [StartDate, endDate],重置段=每 7 天;分段利率由 rates 决定(rates.Count=1 时为常率)。</summary>
@@ -152,6 +154,45 @@ namespace UnitTestProject.Modules.SwapModule.Penalty
Assert.IsTrue(e.InterestFee > 0m, "无 preEod(首日平仓等)仍可计算罚息");
}
[TestMethod]
public void preEod复利段中兜底为零且账龄超重置周期_留退化告警trace()
{
// 场景:无日终快照 + 复利 + 段中平仓,事件 InterestPrincipal 仍是种子值(=平仓本金)→兜底①=0。
// 账龄 25 天 ≥ 7 天重置周期:复利每周期并本理应①>0,①=0 属退化——
// 典型成因=interestWindowEmpty(当日已结息)早退未重放覆盖种子、或日终归档缺失。
var e = NormalEvent(settledAmount: 50_000m);
e.InterestPrincipal = Notional; // GetInterests 种子值:interestWindowEmpty 早退路径不会用重放基数覆盖它
var trace = new AccrualTrace();
RunMerge(Leg(InterestTypeEnum.), e, preEod: null, trace: trace);
StringAssert.Contains(trace.ToString(), "无preEod兜底①=0",
"①=0 且账龄超周期必须留告警,供事后核对日终归档/计息窗口根因");
}
[TestMethod]
public void preEod兜底为正_不留退化告警()
{
var e = NormalEvent(settledAmount: 50_000m);
e.InterestPrincipal = Notional + 100_000m; // 重放末次并本金后基数 → ①=100000 正常路径
var trace = new AccrualTrace();
RunMerge(Leg(InterestTypeEnum.), e, preEod: null, trace: trace);
Assert.IsFalse(trace.ToString().Contains("兜底①=0"), "①>0 是正常兜底路径,不得告警");
}
[TestMethod]
public void preEod真首日兜底为零_不留退化告警()
{
var p = Leg(InterestTypeEnum.);
p.PosiStartDate = UnwindDate; // 起息日当天平仓:账龄 0 < 重置周期,①=0 是设计内约定(类头注)
var e = NormalEvent(settledAmount: 50_000m);
e.InterestPrincipal = Notional;
var trace = new AccrualTrace();
RunMerge(p, e, preEod: null, trace: trace);
Assert.IsFalse(trace.ToString().Contains("兜底①=0"), "真首日 ①=0 合法,不得告警");
}
[TestMethod]
public void _跳过该腿不阻断()
{