refactor(interest): FundingLegRate 瘦身为单一 all-in 利率值对象
固定/浮动腿的区别是取率环节的事,计息只认一个数;以 Fixed/Floating 工厂 取代原 4 字段构造,不再为腿型背负多余字段。
This commit is contained in:
@@ -3,38 +3,27 @@ namespace YLErp.Modules.SwapModule.Accrual;
|
||||
/// <summary>
|
||||
/// 融资腿在某一计息日生效的利率(不可变值对象)。
|
||||
///
|
||||
/// <para>把"固定利率 / 加点利差 / 浮动指数定盘"三种来源收敛为一个概念,避免把它们作为裸 decimal
|
||||
/// 散落在计息方法签名里——这正是初版 <c>AccrueSimpleEod</c> 参数膨胀、可读性差的根因。</para>
|
||||
///
|
||||
/// <para>固定腿与浮动腿是互斥的两种形态:固定腿只设 <see cref="FixedRate"/>(其余为 0);
|
||||
/// 浮动腿设 <see cref="Spread"/> + <see cref="IndexFixing"/>(<see cref="FixedRate"/> 为 0)。
|
||||
/// <see cref="AllInRate"/> 对两种形态统一为三者之和。</para>
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item><description><see cref="FixedRate"/>:固定腿的固定年利率;浮动腿为 0。</description></item>
|
||||
/// <item><description><see cref="Spread"/>:浮动腿在指数之上的加点利差(合约侧);固定腿为 0。</description></item>
|
||||
/// <item><description><see cref="IndexFixing"/>:浮动指数定盘(FR007 等);固定腿为 0。</description></item>
|
||||
/// <item><description><see cref="AllInRate"/>:计息用的"当日生效年利率"。固定腿取 <see cref="FixedRate"/>;浮动腿取 <see cref="Spread"/> + <see cref="IndexFixing"/>(二者互斥,非叠加)。</description></item>
|
||||
/// </list>
|
||||
/// <para>计息只认一个数:<see cref="AllInRate"/>(当日生效年利率)。
|
||||
/// 固定腿与浮动腿的区别是"取率"环节的事,已在 <c>SwapDealService.CalcDailySimpleInterestByEod</c>
|
||||
/// 收敛成 all-in 数;本结构不再为腿型背负四个字段——利息计算不是互换特有的,
|
||||
/// 固定利率就是一个 <see cref="decimal"/>。</para>
|
||||
/// </summary>
|
||||
public readonly struct FundingLegRate
|
||||
{
|
||||
/// <summary>固定腿的固定年利率;浮动腿为 0。</summary>
|
||||
public decimal FixedRate { get; }
|
||||
/// <summary>当日生效年利率(all-in)。固定腿=固定利率;浮动腿=加点利差+指数定盘。</summary>
|
||||
public decimal Rate { get; }
|
||||
|
||||
/// <summary>浮动腿在指数之上的加点利差(合约侧);固定腿为 0。</summary>
|
||||
public decimal Spread { get; }
|
||||
/// <summary>计息用的当日生效年利率。即 <see cref="Rate"/>。</summary>
|
||||
public decimal AllInRate => Rate;
|
||||
|
||||
/// <summary>浮动指数定盘利率(市场侧,FR007 等);固定腿为 0。</summary>
|
||||
public decimal IndexFixing { get; }
|
||||
private FundingLegRate(decimal rate)
|
||||
=> Rate = rate;
|
||||
|
||||
/// <summary>
|
||||
/// 当日生效年利率。固定腿与浮动腿是互斥的两种利率确定方式,不是可叠加分量:
|
||||
/// 固定腿取 <see cref="FixedRate"/>;浮动腿取 <see cref="Spread"/> + <see cref="IndexFixing"/>。
|
||||
/// 约定:固定腿只设 FixedRate(其余为 0),浮动腿只设 Spread + IndexFixing(FixedRate 为 0)。
|
||||
/// </summary>
|
||||
public decimal AllInRate => FixedRate != 0m ? FixedRate : Spread + IndexFixing;
|
||||
/// <summary>构造固定腿利率。</summary>
|
||||
public static FundingLegRate Fixed(decimal fixedRate)
|
||||
=> new(fixedRate);
|
||||
|
||||
public FundingLegRate(decimal fixedRate = 0m, decimal spread = 0m, decimal indexFixing = 0m)
|
||||
=> (FixedRate, Spread, IndexFixing) = (fixedRate, spread, indexFixing);
|
||||
/// <summary>构造浮动腿利率(all-in = 加点利差 + 指数定盘)。</summary>
|
||||
public static FundingLegRate Floating(decimal spread, decimal indexFixing)
|
||||
=> new(spread + indexFixing);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user