Files
zszq-trs/UnitTestProject/Modules/EodModule/BondPaymentServiceCalculationTest.cs
张名锐 6c582ac958 feat(swap): 添加公司行为现金分红按登记日权益数量计算功能
- 新增 CalcBondPayment 方法支持传入公司行为权益数量参数
- 在 SwapEodPositionService 中识别现金分红类型的公司行为持仓
- 修改 CopyEodPosition 和 UpdateEodPosition 方法传递公司行为前的数量信息
- 更新 SaveCurrentEodInitalPosi 方法支持公司行为数量计算
- 在 BondPaymentService 中实现公司行为现金分红按登记日权益数量计算逻辑
- 添加单元测试验证公司行为现金分红使用除权前数量的计算功能
2026-08-26 10:33:51 +08:00

89 lines
3.3 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;
namespace YLErp.Modules.EodModule
{
[TestClass]
public class BondPaymentServiceCalculationTest
{
private static BondPaymentService CreateService()
{
return new BondPaymentService(
new OptUserInfo(0, nameof(BondPaymentServiceCalculationTest), OptUserFrom.UnitTest));
}
[TestMethod]
public void CalcPayment_BondCoupon_KeepsPerHundredScale()
{
var payments = new List<BondPayment>
{
new BondPayment { payment_interest = 1m }
};
// 债券票息 1 表示每 100 元面值付 1 元:1 * 1000 / 100 = 10。
var actual = CreateService().CalcPayment(
payments,
qty: 1000m,
longRatio: 1m,
payDirection: 1m);
Assert.AreEqual(10m, actual);
}
[TestMethod]
public void CalcPayment_CorporateActionDividend_UsesPerTenScale()
{
var payments = new List<BondPayment>
{
new BondPayment { payment_interest = 10m, IsCorporateActionCashDividend = true }
};
// GiveCashAmount=10(每 10 份派 10)时,payment_interest 直接存 10
// 持仓 1000 份的现金分红 = 10 * 1000 / 10 = 1000,不能再套债券报价的 /100 换算。
var actual = CreateService().CalcPayment(
payments,
qty: 1000m,
longRatio: 1m,
payDirection: 1m);
Assert.AreEqual(1000m, actual);
}
[TestMethod]
public void CalcPayment_FundMixedBondPaymentAndCorporateAction_UsesEachRecordScale()
{
var payments = new List<BondPayment>
{
// bond_payment_info:每 100 份付 2200000 份应为 4000。
new BondPayment { payment_interest = 2m },
// ex_dividend_info:每 10 份派 10200000 份应为 200000。
new BondPayment { payment_interest = 10m, IsCorporateActionCashDividend = true }
};
var actual = CreateService().CalcPayment(
payments,
qty: 200000m,
longRatio: 1m,
payDirection: 1m);
Assert.AreEqual(204000m, actual);
}
[TestMethod]
public void CalcPayment_CorporateActionUsesPreCorporateActionQuantity()
{
var payments = new List<BondPayment>
{
new BondPayment { payment_interest = 2m },
new BondPayment { payment_interest = 10m, IsCorporateActionCashDividend = true }
};
var method = typeof(BondPaymentService).GetMethod(
nameof(BondPaymentService.CalcPayment),
new[] { typeof(List<BondPayment>), typeof(decimal), typeof(decimal), typeof(decimal), typeof(decimal?) });
Assert.IsNotNull(method, "公司行为现金分红需要支持单独传入除权前数量。");
var actual = (decimal)method.Invoke(CreateService(), new object[] { payments, 2000m, 1m, 1m, (decimal?)1000m });
Assert.AreEqual(1040m, actual, "原生付息按当前 2000 份计算为 40,公司行为分红按除权前 1000 份计算为 1000。");
}
}
}