diff --git a/UnitTestProject/Modules/SwapModule/ReturnLegs/ReturnLegSummaryTest.cs b/UnitTestProject/Modules/SwapModule/ReturnLegs/ReturnLegSummaryTest.cs new file mode 100644 index 00000000..61f9a69c --- /dev/null +++ b/UnitTestProject/Modules/SwapModule/ReturnLegs/ReturnLegSummaryTest.cs @@ -0,0 +1,46 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using YLErp.Modules.SwapModule.ReturnLegs; + +namespace UnitTestProject.Modules.SwapModule.ReturnLegs +{ + /// + /// ReturnLegSummary 值对象测试。 + /// 验证标的端归档产出的汇总值正确构造、字段语义清晰。 + /// + [TestClass] + public class ReturnLegSummaryTest + { + [TestMethod] + public void 构造_四个字段正确赋值() + { + var s = new ReturnLegSummary( + longNotional: 100_000_000m, + shortNotional: 0m, + closeNotional: 50_000_000m, + grossPrice: 1.02m); + + Assert.AreEqual(100_000_000m, s.LongNotional); + Assert.AreEqual(0m, s.ShortNotional); + Assert.AreEqual(50_000_000m, s.CloseNotional); + Assert.AreEqual(1.02m, s.GrossPrice); + } + + [TestMethod] + public void 构造_空头场景() + { + var s = new ReturnLegSummary(0m, 80_000_000m, 30_000_000m, 0.98m); + + Assert.AreEqual(0m, s.LongNotional, "无多头"); + Assert.AreEqual(80_000_000m, s.ShortNotional, "空头名义本金"); + } + + [TestMethod] + public void 构造_全平场景() + { + var s = new ReturnLegSummary(0m, 0m, 100_000_000m, 1.00m); + + Assert.AreEqual(100_000_000m, s.CloseNotional, "全平:平仓名义本金=全额"); + Assert.AreEqual(0m, s.LongNotional, "全平后无多头剩余"); + } + } +} diff --git a/YLErpDAL/Modules/SwapModule/ReturnLegs/ReturnLegSummary.cs b/YLErpDAL/Modules/SwapModule/ReturnLegs/ReturnLegSummary.cs new file mode 100644 index 00000000..442d64aa --- /dev/null +++ b/YLErpDAL/Modules/SwapModule/ReturnLegs/ReturnLegSummary.cs @@ -0,0 +1,31 @@ +namespace YLErp.Modules.SwapModule.ReturnLegs; + +/// +/// 标的端(Total Return Leg)归档产出的汇总值。 +/// +/// 这些值由标的盯市+分红计算得出,传给融资端(FundingLeg)作为计息基数参考。 +/// 对应原 SwapPositionCompose 里 DealFloatPositions 的产出: +/// posiLongNotional / posiShortNotional / closePosiNotional / grossPrice +/// +/// 命名说明:这里叫 ReturnLeg(业界标准 Total Return Leg),不叫 FloatLeg—— +/// "float" 在金融里首要含义是"浮动利率"(如 FR007),用于标的端会产生歧义。 +/// 标的端 = 标的资产的总回报(价格涨跌 + 票息/分红),与浮动利率无关。 +/// +public readonly struct ReturnLegSummary +{ + /// 多头剩余名义本金(= 数量 × 全价)。融资端用它算多头腿计息基数。 + public decimal LongNotional { get; } + + /// 空头剩余名义本金。 + public decimal ShortNotional { get; } + + /// 本次平仓名义本金(平仓数量 × 合约乘数 × 含费全价)。 + public decimal CloseNotional { get; } + + /// 标的含费全价(PosiGrossPrice / EntryDirtyPrice)。融资端 mode 9 衡泰路径折算用。 + public decimal GrossPrice { get; } + + public ReturnLegSummary(decimal longNotional, decimal shortNotional, decimal closeNotional, decimal grossPrice) + => (LongNotional, ShortNotional, CloseNotional, GrossPrice) + = (longNotional, shortNotional, closeNotional, grossPrice); +}