fix: 计算平仓分红
This commit is contained in:
@@ -910,10 +910,21 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
private void EnrichDividendIn(swap_flow_event flowEvent, decimal unwindQty)
|
||||
{
|
||||
// 平仓数量/平仓前的数量*平仓对象的待实现分红收益,保留2位小数
|
||||
var yest = QdpCalendarHelper.GetNonHolidayDefore(flowEvent.EventDate.AddDays(-1));
|
||||
var eod = DbContext.eod_swap_position.Where(e => e.SwapTradeId == flowEvent.SwapTradeId && !e.Invalid && e.PosiQuantity > 0 && e.ValueDate == yest).FirstOrDefault();
|
||||
if (flowEvent.UnwindDate == null) {
|
||||
throw new ArgumentNullException("平仓日期缺失");
|
||||
}
|
||||
var date = flowEvent.UnwindDate.GetValueOrDefault();
|
||||
var preDate = date.AddDays(-1);
|
||||
// 平仓数量/平仓前的数量 * 上一自然日待实现分红收益,保留2位小数
|
||||
var eod = DbContext.eod_swap_position.Where(e => e.SwapTradeId == flowEvent.SwapTradeId && !e.Invalid && e.PosiQuantity > 0 && e.ValueDate == preDate).FirstOrDefault();
|
||||
var dividendIn = eod.PosiDividendSum * unwindQty / eod.PosiQuantity;
|
||||
// + 付息日>上日日终且小于等于平仓日期的分红数据
|
||||
BondPaymentService servie = new BondPaymentService(UserInfo);
|
||||
var payments = servie.GetBondPayments(flowEvent.UnderlyingCode, preDate, date);
|
||||
|
||||
int shortRatio = flowEvent.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int directionRatio = flowEvent.PayDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
dividendIn = dividendIn + servie.CalcPayment(payments, unwindQty, shortRatio, directionRatio);
|
||||
flowEvent.DividendIn = Math.Round(dividendIn, 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user