Files
zszq-trs/UnitTestProject/Modules/SwapModule/SwapSpanPriceSourceTest.cs
hjhan 84b5a362e8 修复 SP_002 冒烟测试两处取数偏差
- 样本 join underlying_manager:取数链路 InnerGetEodPrice 从标的表出发 join 价格表,
  未登记为标的的代码取数必返回 null,冒烟样本须限定在已登记标的上
- 查询日期经 GetNonHolidayDefore 回退到最近交易日:dev 库 eod_stock_price 混有
  非交易日/未来日期脏行(如 2026-08-30 周日),取数链路按交易日历向后滚到下一交易日
  后无数据导致假失败
2026-08-27 18:46:10 +08:00

64 lines
3.4 KiB
C#
Raw Permalink 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 YLErp.DBModels;
using YLErp.Modules.DataProviderModule;
using YLErp.QdpModule;
namespace YLErp.Modules.SwapModule
{
/// <summary>
/// R2 阶段三 §3.1 收盘价取数链路冒烟测试(只读 dev 库,不构造数据):
/// 债券净价源(china_bond_valuationGetBondPrice 口径 SettlePrice=净价、ClosePrice=全价,≤计算日 取最近——盘中/非交易日回退到最近已有估值);
/// 指数/ETF收盘价源(eod_stock_price)。
/// 两个源在"价格同步作业跑完前"决定引擎行为:取不到 → 追加按0、维持=初始(见 SwapSpanMarginEngineTest.SE_004)。
/// </summary>
[TestClass]
public class SwapSpanPriceSourceTest
{
[TestMethod]
public void SP_001_债券估值净价源_可取且净价为正()
{
using var db = DbContextFactory.GetYLDbContext();
var latest = db.china_bond_valuation
.Where(x => x.net_price > 0 && x.dirty_price_close > 0)
.OrderByDescending(x => x.valuation_date)
.Select(x => new { x.valuation_date, x.bond_id })
.FirstOrDefault();
if (latest == null)
{
Assert.Inconclusive("dev 库无中债估值数据,跳过");
}
//当日可取
Assert.IsTrue(EodPriceQueryService.TryGetBondEodPrice(latest.valuation_date, latest.bond_id, out var price));
Assert.IsTrue(price.SettlePrice > 0, "净价(SettlePrice)应为正");
Assert.IsTrue(price.ClosePrice > 0, "全价(ClosePrice)应为正");
//≤计算日 取最近:往未来多取几天仍回退到最近一条估值(盘中跑引擎即此语义)
Assert.IsTrue(EodPriceQueryService.TryGetBondEodPrice(latest.valuation_date.AddDays(5), latest.bond_id, out var fallback));
Assert.AreEqual(price.SettlePrice, fallback.SettlePrice, 1e-9);
}
[TestMethod]
public void SP_002_ETF收盘价源_可取()
{
using var db = DbContextFactory.GetYLDbContext();
//join underlying_manager:取数链路 InnerGetEodPrice 从标的表出发 join 价格表,
//价格表里未登记为标的的代码(同步进来的非管理标的)取数必返回 null,冒烟样本须限定在已登记标的上
var latest = (from ep in db.eod_stock_price
where ep.ClosePrice > 0
join um in db.underlying_manager on ep.UnderlyingCode equals um.UnderlyingCode
orderby ep.ValueDate descending
select new { ep.ValueDate, ep.UnderlyingCode }).FirstOrDefault();
if (latest == null)
{
Assert.Inconclusive("dev 库无股票/ETF日终价格数据,跳过");
}
//价格表可能混有非交易日/未来日期的脏行(如 2026-08-30 周日),而取数链路会按交易日历调整日期
//(非国君环境向后滚到下一交易日,脏行日期之后无数据 → 取不到);查询日期回退到最近交易日再验
var queryDate = QdpCalendarHelper.GetNonHolidayDefore(latest.ValueDate.Date);
Assert.IsTrue(EodPriceQueryService.TryGetEodPrice(queryDate, latest.UnderlyingCode, out var price));
Assert.IsTrue(price.GetPrice(SettlementTypeEnum.ClosePrice) > 0);
}
}
}