保证金就是保证金——有余额、有利率、有利息, 不存在'计息基数/Notional'概念。 现有代码把保证金塞进 InterestPrincipalFix 当计息腿处理是错误建模。 修正: - 删除 MarginLeg.cs(CalcBalance/accrualFactor 是融资腿的概念, 不该用在保证金) - 新增 MarginAccount.cs: 管理余额变动(Deposit追加/Withdraw释放), 不含计息 - MarginBalance: 注释去掉'计息基数', 改为'保证金余额' - IMarginResolver.Resolve: 去掉 accrualFactor 参数(融资腿比例, 非保证金概念) - CashMargin/CreditMargin/GuaranteeMargin: 同步去掉 accrualFactor - 枚举注释: '计息余额' → '余额' 保证金利息由 SwapInterest 纯函数按 余额×利率×天数/年化 计算, MarginAccount 只提供余额, 不掺计息逻辑。 验证: sln编译0错误, 全量486测试7失败(基线一致,零回归)。
71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using YLErp.Modules.SwapModule.Margin;
|
|
|
|
namespace UnitTestProject.Modules.SwapModule.Margin
|
|
{
|
|
/// <summary>
|
|
/// 保证金账户(MarginAccount)单测。验证余额变动(追加/释放/返还)。
|
|
/// 保证金就是保证金——有余额、有利率、有利息,不存在"计息基数/Notional"概念。
|
|
/// </summary>
|
|
[TestClass]
|
|
public class MarginLegTest
|
|
{
|
|
private const decimal Opening = 2_000_000m;
|
|
|
|
#region MarginAccount 余额变动
|
|
|
|
[TestMethod]
|
|
public void 账户_初始余额等于期初保证金()
|
|
{
|
|
var account = new MarginAccount(new MarginBalance(Opening));
|
|
Assert.AreEqual(Opening, account.Balance.Balance);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void 账户_追加保证金_余额增加()
|
|
{
|
|
var account = new MarginAccount(new MarginBalance(Opening));
|
|
account.Deposit(500_000m);
|
|
Assert.AreEqual(2_500_000m, account.Balance.Balance);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void 账户_释放保证金_余额减少()
|
|
{
|
|
var account = new MarginAccount(new MarginBalance(Opening));
|
|
account.Withdraw(800_000m);
|
|
Assert.AreEqual(1_200_000m, account.Balance.Balance);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void 账户_释放超过余额_不低于零()
|
|
{
|
|
var account = new MarginAccount(new MarginBalance(Opening));
|
|
account.Withdraw(3_000_000m);
|
|
Assert.AreEqual(0m, account.Balance.Balance, "保证金余额不低于零");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 三种保证金形态解析器
|
|
|
|
[TestMethod]
|
|
public void 三种形态解析器_各自返回正确Form和余额()
|
|
{
|
|
IMarginResolver cash = new CashMargin();
|
|
IMarginResolver credit = new CreditMargin();
|
|
IMarginResolver guarantee = new GuaranteeMargin();
|
|
|
|
Assert.AreEqual(MarginForm.Cash, cash.Form);
|
|
Assert.AreEqual(MarginForm.Credit, credit.Form);
|
|
Assert.AreEqual(MarginForm.Guarantee, guarantee.Form);
|
|
|
|
Assert.AreEqual(Opening, cash.Resolve(Opening).Balance);
|
|
Assert.AreEqual(Opening, credit.Resolve(Opening).Balance);
|
|
Assert.AreEqual(Opening, guarantee.Resolve(Opening).Balance);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|