Merge remote-tracking branch 'origin/glms/feature/1.4.2' into glms/feature/1.4.2
This commit is contained in:
@@ -276,6 +276,7 @@ namespace YLErp.Modules.SwapModule
|
||||
floatEvent.PayDirection = position.PosiDirection;
|
||||
floatEvent.PosiGrossPrice = position.PosiGrossPrice;
|
||||
floatEvent.PosiNetPrice = position.PosiNetPrice;
|
||||
// 注意:TradingAmountNetAvg 字段名为"成交净价(期末语义)",但收益结算/平仓初始化时装入的是期初净价(PosiNetNoFeePrice),前端展示期初净价时取此字段
|
||||
floatEvent.TradingAmountNetAvg = position.PosiNetNoFeePrice;
|
||||
floatEvent.TradingAmountNetFeeAvg = position.PosiNetFeePrice;
|
||||
floatEvent.PositionType = position.PositionType;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using BaseOUDAL;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.POIFS.Properties;
|
||||
using System.Linq.Expressions;
|
||||
using YLErp.DBModels;
|
||||
using YLErp.DBModels.Consts;
|
||||
using YLErp.DBModels.Enums;
|
||||
using YLErp.Helpers;
|
||||
@@ -448,12 +450,14 @@ namespace YLErp.Modules.SwapModule
|
||||
PayDate = dividendPayDate,
|
||||
PositionId = eodPosi.PositionId,
|
||||
UnderlyingCode = eodPosi.UnderlyingCode,
|
||||
UnderlyingInstrumentType = eodPosi.UnderlyingInstrumentType,
|
||||
PayDirection = eodPosi.PosiDirection,
|
||||
PositionType = eodPosi.PositionType,
|
||||
PositionQty = eodPosi.PosiQuantity,
|
||||
Quantity = 0,
|
||||
ContractSize = eodPosi.ContractSize,
|
||||
TradingAmountAvg = eodPosi.PosiNetPrice,
|
||||
TradingAmountNetAvg = eodPosi.PosiNetNoFeePrice,
|
||||
PosiGrossPrice = eodPosi.PosiGrossPrice,
|
||||
PosiNetPrice = eodPosi.PosiNetPrice,
|
||||
MarkClosePnl = eodPosi.PosiDividendSum,
|
||||
@@ -470,12 +474,13 @@ namespace YLErp.Modules.SwapModule
|
||||
eodPosi.TdCloseDividend += eodPosi.PosiDividendSum;
|
||||
eodPosi.TdPosiDividend = 0;
|
||||
eodPosi.RealizedDividend += eodPosi.PosiDividendSum;
|
||||
eodPosi.PosiDividendSum = 0;
|
||||
eodPosi.PosiProfitSum -= eodPosi.TdCloseDividend;
|
||||
//互换持仓价值要去掉已实现的
|
||||
eodPosi.SwapPositionValue -= eodPosi.PosiDividendSum;
|
||||
//已实现盈亏要加上已实现的
|
||||
eodPosi.RealizedPnl += eodPosi.PosiDividendSum;
|
||||
eodPosi.PosiDividendSum = 0;
|
||||
eodPosi.PosiProfitSum -= eodPosi.TdCloseDividend;
|
||||
|
||||
}
|
||||
|
||||
UnwindData unwindData = new UnwindData();
|
||||
@@ -1459,6 +1464,12 @@ namespace YLErp.Modules.SwapModule
|
||||
int shortRatio = eod.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int directionRatio = eod.PosiDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
var price = UnderlyingCodePrice(eod.UnderlyingCode, dealDate, out decimal vobp);
|
||||
var todayConsumedDividend = CalcConsumedDividend(curretEod, unwindEvents);
|
||||
var originNotional = (decimal)td.OriginalStockEqvNotional / swapPosition.PosiNetPrice;
|
||||
BondPaymentService bondPaymentService = new BondPaymentService(UserInfo);
|
||||
decimal totalPayment = bondPaymentService.CalcPayment(curretEod.UnderlyingCode, td.StartDate.Value, valueDate, (decimal)originNotional, shortRatio, directionRatio);
|
||||
decimal tax = um.ValueAddedTax ?? 0;
|
||||
decimal totalInterest = totalPayment / (1 + tax) * (1 - tax);
|
||||
SetPriceInfoByFlowEvent(eod, curretEod, unwindEvents, swapPosition);
|
||||
curretEod.dv01 = Dv01Helper.CalcDv01(eod.UnderlyingCode, curretEod.PosiQuantity, eod.PosiDirection, eod.PositionType, vobp);
|
||||
curretEod.UnderlyingPrice = price;
|
||||
@@ -1466,35 +1477,42 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.PosiMtmPnL = (curretEod.UnderlyingPrice - curretEod.PosiGrossPrice) * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio * directionRatio;
|
||||
curretEod.TdPosiDividend = 0;
|
||||
// 分红与互换无关,只要持仓>0且起始日早于当前日,正常计算当日分红
|
||||
// 修改,互换事件会影响待实现的分红的,现在要算上
|
||||
if (valueDate > td.StartDate.Value && (curretEod.PosiQuantity > 0))
|
||||
{
|
||||
decimal tax = um.ValueAddedTax ?? 0;
|
||||
BondPaymentService bondPaymentService = new BondPaymentService(UserInfo);
|
||||
decimal payment = bondPaymentService.CalcPayment(curretEod.UnderlyingCode, eod.ValueDate, valueDate, curretEod.PosiQuantity, shortRatio, directionRatio);
|
||||
curretEod.TdPosiDividend = Math.Round(payment / (1 + tax) * (1 - tax), 2);
|
||||
}
|
||||
curretEod.RealizedMtmPnL = eod.RealizedMtmPnL + curretEod.TdCloseMtmPnl;
|
||||
|
||||
// 当日浮动端平仓盈亏·分红(仅来自平仓事件 和 互换 中已实现的分红)
|
||||
curretEod.TdCloseDividend = unwindEvents.Sum(e => e.DividendIn);
|
||||
curretEod.RealizedFee = eod.RealizedFee + curretEod.TdCloseFee;
|
||||
curretEod.RealizedPnl = eod.RealizedPnl + curretEod.TdCloseMtmPnl;
|
||||
curretEod.PosiStatus = curretEod.PosiQuantity == 0 ? 1 : 0;
|
||||
var closeQty = unwindEvents.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.平仓).ToList().Sum(s => s.Quantity);
|
||||
// 当日浮动端平仓盈亏·分红(仅来自平仓事件中已实现的分红)
|
||||
curretEod.TdCloseDividend = unwindEvents.Sum(e => e.DividendIn);
|
||||
|
||||
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, (decimal)originNotional, shortRatio, directionRatio);
|
||||
//var totalInterest = totalPayment / (1 + tax) * (1 - tax);
|
||||
curretEod.PosiDividendSum = Math.Round(totalInterest,2) - curretEod.RealizedDividend;
|
||||
}
|
||||
else
|
||||
{
|
||||
curretEod.PosiDividendSum = 0;
|
||||
}
|
||||
if (curretEod.PosiDividendSum == 0)//这里处理一下已实现盈亏和互换价值,其他在处理分红的时候会处理
|
||||
{
|
||||
curretEod.RealizedPnl += curretEod.TdCloseDividend;
|
||||
curretEod.SwapPositionValue -= curretEod.TdCloseDividend;
|
||||
|
||||
}
|
||||
curretEod.PosiProfitSum = curretEod.PosiMtmPnL + curretEod.PosiDividendSum + curretEod.PosiFeePending;
|
||||
if (curretEod.PosiStatus == 1)
|
||||
{
|
||||
@@ -1513,6 +1531,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 +1678,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user