feat(trade): 新增真实除权日字段并完善基金公司行为处理 init

- 添加 EffectiveDate 字段用于标识真实除权生效日
- 实现公司行为价格系数和数量系数统一计算方法
- 增加基金除权回退和平仓基线恢复功能
- 完善除权日验证逻辑,确保真实除权日不早于股权登记日
- 重构平仓流程,支持按有效EOD基线重新计算损益和现金
- 添加基金拆合股和现金分红的特殊处理逻辑
- 增加单元测试验证各种公司行为场景下的正确性
This commit is contained in:
张名锐
2026-08-18 11:20:56 +08:00
parent 04f4468be5
commit aa1a13d7a3
11 changed files with 1582 additions and 18 deletions
@@ -24,6 +24,13 @@ namespace YLErp.Modules.SwapModule
public int SaveAllChangesCount;
public int CloseReCheckCallCount;
/// <summary>Fund 盤中基线测试输入;生产服务通过数据库查询同名 seam。</summary>
public swap_position RealtimeFloatPosition { get; set; }
public eod_swap_position LatestFundEodPosition { get; set; }
public bool HasCompletedFlowAfterLatestFundEod { get; set; }
public List<swap_position> ActiveSwapPositions { get; set; } = new();
public List<ex_dividend_info> ExDividendInfos { get; } = new();
public TestableSwapDealService(trade td,
Dictionary<int, swap_event> swapEvents = null,
Dictionary<long, List<swap_flow_event>> flowEventsByEventId = null)
@@ -36,6 +43,33 @@ namespace YLErp.Modules.SwapModule
protected override trade FindTrade(int tradeId) => tradeId == _trade.id ? _trade : null;
protected override List<swap_position> FindActiveSwapPositions(int tradeId)
=> ActiveSwapPositions;
protected override swap_position FindRealtimeFloatPosition(UnwindData unwindData)
=> RealtimeFloatPosition;
protected override eod_swap_position FindLatestFundEodPosition(int tradeId, long positionId, DateTime valueDate)
=> LatestFundEodPosition;
protected override bool HasCompletedFlowAfterFundEod(int tradeId, long positionId, DateTime eodDate, DateTime valueDate)
=> HasCompletedFlowAfterLatestFundEod;
protected override ex_dividend_info FindFundCorporateAction(string underlyingCode, DateTime valueDate)
=> ExDividendInfos.FirstOrDefault(x => x.ValidStatus
&& x.UnderlyingCode == underlyingCode
&& x.EffectiveDate == valueDate.Date);
protected override decimal GetFundCorporateActionClosePrice(
ex_dividend_info dividendInfo,
decimal fallbackPrice)
=> fallbackPrice;
protected override decimal GetFundDividendTaxRate() => 0m;
public bool RestoreEffectiveFundPositionForTest(UnwindData unwindData, DateTime valueDate)
=> TryRestoreEffectiveFundPosition(unwindData, valueDate);
protected override int AddClientCash(trade td, double amount, string action, DateTime valueDate)
{
ClientCashCalls.Add((amount, action, valueDate));