feat(margin): MarginAccount 加计息入口 AccrueInterest
保证金账户现在具备独立计息能力: AccrueInterest(rate, start, end, boundary, annualDays) 委托 SwapInterest.AccrueSimple(余额×利率×天数/年化)。 保证金利息是券商对客户保证金存款付息, 方向与融资腿相反。 Margin 模块现在完全独立于 CalcNotionalByMode—— 有自己的余额管理 + 计息入口, 不依赖融资腿框架。 测试: 3个计息用例(7天/零余额/释放后减半)。 CalcNotionalByMode 的 mode 5/6 case 仍在(下游路径共用), 待 EOD 归档改走 Margin 路径后再删。 验证: 编译0错误, 全量511测试7失败(基线一致)。
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using YLErp.Derivatives.Interest;
|
||||
using YLErp.Modules.SwapModule.Margin;
|
||||
|
||||
namespace UnitTestProject.Modules.SwapModule.Margin
|
||||
@@ -66,5 +67,55 @@ namespace UnitTestProject.Modules.SwapModule.Margin
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MarginAccount 计息
|
||||
|
||||
[TestMethod]
|
||||
public void 计息_单利7天_余额200万年化3pct()
|
||||
{
|
||||
var account = new MarginAccount(new MarginBalance(2_000_000m));
|
||||
// 200万 × 3% / 365 × 7天 = 1150.68...
|
||||
var r = account.AccrueInterest(
|
||||
rate: 0.03m,
|
||||
startDate: new System.DateTime(2026, 5, 4),
|
||||
endDate: new System.DateTime(2026, 5, 11),
|
||||
boundary: AccrualBoundary.StartOnly,
|
||||
annualDays: 365);
|
||||
|
||||
Assert.IsTrue(r.Accrued > 0, "7天利息应大于0");
|
||||
System.Console.WriteLine($"保证金7天利息={r.Accrued}");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void 计息_零余额_利息为零()
|
||||
{
|
||||
var account = new MarginAccount(new MarginBalance(0m));
|
||||
var r = account.AccrueInterest(0.03m,
|
||||
new System.DateTime(2026, 5, 4), new System.DateTime(2026, 5, 11),
|
||||
AccrualBoundary.StartOnly, 365);
|
||||
|
||||
Assert.AreEqual(0m, r.Accrued);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void 计息_释放后余额减少_利息相应减少()
|
||||
{
|
||||
var full = new MarginAccount(new MarginBalance(2_000_000m));
|
||||
var half = new MarginAccount(new MarginBalance(2_000_000m));
|
||||
half.Withdraw(1_000_000m);
|
||||
|
||||
var rFull = full.AccrueInterest(0.03m,
|
||||
new System.DateTime(2026, 5, 4), new System.DateTime(2026, 5, 11),
|
||||
AccrualBoundary.StartOnly, 365);
|
||||
var rHalf = half.AccrueInterest(0.03m,
|
||||
new System.DateTime(2026, 5, 4), new System.DateTime(2026, 5, 11),
|
||||
AccrualBoundary.StartOnly, 365);
|
||||
|
||||
Assert.IsTrue(rHalf.Accrued < rFull.Accrued, "释放后利息应更少");
|
||||
Assert.IsTrue(System.Math.Abs(rFull.Accrued - rHalf.Accrued * 2m) < 0.01m,
|
||||
"余额减半, 利息也应减半");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user