Commit Graph
8 Commits
Author SHA1 Message Date
hjhan fb5bbfaa99 test(swap-eod): 场景4 跨日毒链携带守卫改为生产自身 DailyAccrual 不变量(真捕获 mode9 误反推)
- 原引擎级差分版(734683ea)为假绿:固定 obsDate=2026-05-12 在 td.StartDate 重置日判定下恒为重置日,
  basis=notional+priorAccrued 不取 priorNotional(被误反推的 TdInterestPrincipal),故未捕获 bug。
- 现改为直接复用生产单一真相源 SwapEodPositionService:1388 的 TdInterestIncome=DailyAccrual(TdInterestPrincipal,…)
  纯函数:正确本金与“生产实际”本金各算一次 D+1 应计,二者唯一差异即 TdInterestPrincipal;误反推(膨胀~2.3x)
  使 D+1 应计同步膨胀,差远超容差→红。该不变量与重置日/平仓比例无关,稳健。
- 守卫置于单日 TdInterestPrincipal 不变量之前,使其成为首要捕获点(实跑验证:注入 mode9 误反推后
  首失败点即“场景4[跨日] 毒链携带 D+1 应计偏差 -5501.96”,correct=-4126.47 / poisoned=-9628.43)。
- 移除不再使用的 CalcNextDayInterest 引擎级辅助方法。
2026-08-17 18:53:30 +08:00
hjhan 734683eaca test(swap-eod): 场景4 跨日毒链携带断言——引擎级差分(正确本金 vs 生产实际本金各喂一次 GetInterests)
- 前一版在 rollforward eod 层断言 TdInterestPrincipal 被证伪(该 harness 中 DealInterests 收到 eodPosition=null,rollforward eod 恒 0;复利写带符号重放值)——正常日该字段非计息基数载体,断言选错层
- 现改为引擎级差分:partialEod.Clone() 修正 TdInterestPrincipal=expectedTdPrincipal 作对照组,与生产实际 partialEod 各喂 GetInterests(05-12,settment:true),比对次日本金 InterestPrincipal——经 SwapDealService:1045 priorNotional 通道验证携带,容差 max(0.01, 5%)
- 变异验证(已还原):临时令 :1422 守卫放行 mode9 复现 GLMS-20260421-0004 → 三守卫齐红:本文件不变量断言(Expected 212135529.97 / Actual 494982903.27 精确命中历史签名值)、DI_GLMS_20260421_0004、DI_EXCEL_SCENARIO4;还原后 24/24 + 全量 576/566/10/0 复绿
- 生产代码零变更
2026-08-17 18:36:54 +08:00
hjhan c42335363b test(swap-eod): SwapInterestScenario3And4FloatingTest 的 TdInterestPrincipal 改独立不变量(封死假绿)
场景4 原 TdInterestPrincipal 断言 = 生产公式镜像(reverseMode2 ? base*(1-cp)/cp : base),
与生产 if(calcLast && mode2) TdInterestPrincipal *= (1-cp)/cp 逐字同构,永远跟自己一致,
故 mode9 被错误反推(GLMS-20260421-0004 膨胀 ~2.3x)时测试仍绿——假绿。

改为:mode9 用独立 else if 锁死 expected=LastBaseInterestPrincipal(反推前 base),
彻底脱离 reverseMode2 布尔拼写,封死重基线陷阱。已实跑证明:注入 mode9 反推 bug 后
唯一变红 T+1浮动减点算头算尾(实测 TdInterestPrincipal=494982903.27),回滚生产恢复 24/24。
零生产改动。
2026-08-17 18:18:02 +08:00
hjhan ef37c8e71d refactor(swap): 合并多空名义本金参数为单一 posiTotalNotional 并加固测试
- DealInterests 的 posiLongNotionalValue + posiShortNotionalValue 合并为 posiTotalNotional(调用点以 posiLongNotional+posiShortNotional 求和传入),净减一个参数

- SwapDealService / SwapEodPositionService / InterestCalcRequest 同步收敛多空死管道参数

- 19 个测试调用点适配新签名

- SwapEodPositionServiceIntegrationTest 参数计数断言由裸数字改为参数名集合断言(CollectionAssert.AreEquivalent,对增删/重排/改名敏感)
2026-08-14 17:30:46 +08:00
hjhan 4a3fee9292 refactor(swap)+test: 删 GetInterests/CalcSwapInterests 死参数 needPrice/grossPrice;补工厂→接缝映射钉子
死参数收口(另一半):
- SwapDealService.GetInterests 删 needPrice/grossPrice(体内零消费,2026-08 验证);
  InitSwapDealInterest.needPrice 同为死参数一并删
- SwapEodPositionService.CalcSwapInterests 签名+转发同步;两个 EOD 生产调用点
  (SaveAutoEodInterestPosition/SaveEodInterestPositionCopy) 重排实参;
  CalcEodPostCloseSettleInterests/GetIntradayUnwindInterests 委托同步
- 14 个测试文件 ~44 处直调点机械更新(8 处 override 签名 + 36 处调用实参)
- 注意:EOD 编排链(DealInterests→Save*家族)的 grossPrice(期初不含费价)有真实用途,保留未动

新增钉子:CalcEodPostCloseSettleInterests 工厂→接缝参数映射测试——
CalcSwapInterestsCapture 捕获 stub 断言 EodPostCloseSettle 的完整转发契约
(posi=平仓后剩余/closePosi=平掉额/恒1/settment:false/orginPv 等 11 项)。
该段位置转发含三个相邻同型 decimal,编译器不查错位,此测试兜底。

验证:定向 241 测试通过(含 T0/T1 Excel 验证期望值、EntrySemantics 精确值钉子——
任何 decimal 错位即红);全量 903=145失败/746通过/12跳过,与基线逐位一致。
2026-08-14 16:57:56 +08:00
hjhan 22f22bc9c5 refactor(margin): ConsTrade.InterestMarginModels 4处引用收敛到 MarginModes
上次失败根因: EodClientBalanceCalc:134 是 EF Core LINQ 表达式,
HashSet.Contains 无法翻译成 SQL, 导致场景3/4 全红。

修正: MarginModes 新增 ForLinq(List<int>) 供 EF Core 翻译用。
- SwapEodPositionService 2处纯函数(非LINQ): 用 MarginModes.Contains
- EodClientBalanceCalc LINQ表达式: 用 MarginModes.ForLinq.Contains
- RealTimeClientBanlanceService(已ToList,内存集合): 用 MarginModes.Contains

ConsTrade.InterestMarginModels 产品代码引用: 4处 → 0(只剩定义+注释)。
保证金mode判断 {初始预付金,追加预付金} 现在统一由 MarginModes 提供。

验证: sln编译0错误, 全量485测试7失败(基线一致,零回归)。
2026-08-11 09:57:20 +08:00
hjhan 4916f7207d test(refactor): SwapInterestScenario3And4 诚实化——去掉 return 0m, 从交易开始日逐日真实收盘
- 删除 StubSwapDealService.GetConsumedInterest 的  硬编码(此前注释明写"与生产缺陷态一致",
  等于把唯一会出错的机制整个屏蔽, 断言缺陷态输出, 伪绿)。
- 改为复用生产同一口径: 对真实收盘经 PersistFlowEvent 累积的 swap_flow_event
  (EventType∈{互换,自动互换}, DataState=完成, EventDate<结算日) 求和 —— 数据来自真实代码执行, 非硬编码。
- TestableSwapEodPositionService 新增 FlowEvents 捕获 + override PersistFlowEvent, 供 GetConsumedInterest 真实计算(不连库)。
- 新增 E2EEodService: 从交易开始日(TradeDate)逐日驱动真实 SwapPositionCompose 构建 eod 链,
  再把真实 eod 快照喂给平仓; 平仓走生产同一入口 SaveAutoEodWithCloseInterestPosition。
- 全程无硬编码输入: FR007 曲线/名义本金/日期均来自 Excel 场景真源, 计算全走真实代码。
- 验证: 24/24 通过(SKIP_INITIALIZATION); PrepaidPrincipal 追踪测试 2/2 通过; 基类改动无回归。
- 注: ConsumedInterestScenarioTest.CI_008 既有失败(复利重置日本金继承, 与本回合无关, 未触碰该文件), 另议。
2026-08-09 11:22:42 +08:00
hjhan feffc196c6 fix(interest): 修复浮动利率部分/全平利息尾差(Bug A/B/C) 并补充回归测试
- Bug A(SwapDealService): 复利早退分支 TdInterestAmount 未乘 closePrecent
- Bug B(SwapDealService): CalcDailyCompoundInterest 用 interest 而非 EOD 四舍五入快照
- Bug C(SwapEodPositionService): 用 oriPosiNotionalValue(平仓前原始本金) 重算平仓利息
- 新增 SwapInterestScenario3And4FloatingTest: 24 个浮动利率用例, 走真实生产函数
  (GetInterests / SaveAutoEodWithCloseInterestPosition), 对照 Excel 手算 oracle(AO/BL/BN),
  断言容差 0.01, 非 re-baseline; 含 DebugCompare 调试输出便于与生产/Excel 逐项对比
- 附 缺陷分析-利息部分平仓尾差20260807.md 与 oracle 源 xlsx
2026-08-08 09:02:05 +08:00