收盘 分红计算逻辑中算上手动的已实现的分红

This commit is contained in:
锦麟 王
2026-06-25 14:33:01 +08:00
parent 1aba5cca00
commit 6d17e95197
@@ -1,6 +1,7 @@
using BaseOUDAL;
using Newtonsoft.Json;
using System.Linq.Expressions;
using YLErp.DBModels;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.Helpers;
@@ -1484,12 +1485,16 @@ namespace YLErp.Modules.SwapModule
curretEod.RealizedDividend = curretEod.RealizedDividend + curretEod.TdCloseDividend;
// 分红与互换解耦:持仓>0时从起始日重算待实现分红,不再受互换事件影响
// 修改,互换事件会影响待实现的分红的,现在要算上
if (curretEod.PosiQuantity > 0)
{
decimal tax = um.ValueAddedTax ?? 0;
BondPaymentService bondPaymentService = new BondPaymentService(UserInfo);
decimal totalPayment = bondPaymentService.CalcPayment(curretEod.UnderlyingCode, td.StartDate.Value, valueDate, curretEod.PosiQuantity, shortRatio, directionRatio);
curretEod.PosiDividendSum = Math.Round(totalPayment / (1 + tax) * (1 - tax), 2);
//decimal tax = um.ValueAddedTax ?? 0;
//BondPaymentService bondPaymentService = new BondPaymentService(UserInfo);
//decimal totalPayment = bondPaymentService.CalcPayment(curretEod.UnderlyingCode, td.StartDate.Value, valueDate, td.., shortRatio, directionRatio);
//var totalInterest = totalPayment / (1 + tax) * (1 - tax);
var consumedDividend = CalcConsumedDividend(curretEod, unwindEvents);
curretEod.PosiDividendSum = eod.PosiDividendSum - consumedDividend - curretEod.TdCloseDividend;
}
else
{
@@ -1513,6 +1518,21 @@ namespace YLErp.Modules.SwapModule
}
return curretEod;
}
private decimal CalcConsumedDividend(eod_swap_position curretEod, List<swap_flow_event> events)
{
decimal consumedDividend = 0;
List<int> swapEventTypes = new List<int>() { (int)SwapEventTypeEnum., (int)SwapEventTypeEnum. };
//这里要剔除掉平仓产生的分红
consumedDividend = events
.Where(x => x.SwapTradeId == curretEod.SwapTradeId
&& swapEventTypes.Contains(x.EventType)
&& x.DataState == (int)SwapFlowDateStateEnum.)
.Sum(s => s.DividendIn);
return consumedDividend;
}
/// <summary>
/// 根据开平仓事件算价格及后付费用
/// </summary>
@@ -1645,6 +1665,7 @@ namespace YLErp.Modules.SwapModule
BondPaymentService bondPaymentService = new BondPaymentService(UserInfo);
decimal payment = bondPaymentService.CalcPayment(curretEod.UnderlyingCode, td.StartDate.Value, settleDate, curretEod.PosiQuantity, shortRatio, directionRatio);
payment = Math.Round(payment / (1 + tax) * (1 - tax), 2);
//var consumedDividend = CalcConsumedDividend(curretEod, unwindEvents); 首日应该没有分红
curretEod.TdPosiDividend = payment;
curretEod.PosiDividendSum = payment;
}