Merge remote-tracking branch 'origin/hotfix/zs_v1.3_1016' into feature/zs_v1.3.3
This commit is contained in:
@@ -9,6 +9,7 @@ using OfficeOpenXml.Drawing.Controls;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using Qdp.Pricing.Base.Implementations;
|
||||
using Qdp.Pricing.Core.Modules;
|
||||
using Qdp.Pricing.Library.Base.Utilities;
|
||||
using System.Linq.Expressions;
|
||||
using YLErp.BLL;
|
||||
using YLErp.BLL.Eod;
|
||||
@@ -71,6 +72,7 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
else
|
||||
{
|
||||
unwindData.TradeStartDate = td.StartDate;
|
||||
unwindData.CloseType = commodity ? 1 : 2;
|
||||
unwindData.StartDate = td.TradeDate.Value;
|
||||
if (preDealDate.HasValue)
|
||||
@@ -400,7 +402,7 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
else if (position.InterestMode == (int)InterestModeEnum.标的期初全价)
|
||||
{
|
||||
_closePosiNotionalValue = _posiNotionalValue * closePrecent;
|
||||
_closePosiNotionalValue = _posiNotionalValue * closePrecent;
|
||||
_posiNotionalValue = _posiNotionalValue;
|
||||
}
|
||||
else if (position.InterestMode == (int)InterestModeEnum.追加预付金 || position.InterestMode == (int)InterestModeEnum.初始预付金)
|
||||
@@ -433,7 +435,7 @@ namespace YLErp.Modules.SwapModule
|
||||
position.FloatRate = Convert.ToDecimal(floatRate);
|
||||
positionClone.FloatRate = position.FloatRate;
|
||||
}
|
||||
else if(!swap)
|
||||
else if (!swap)
|
||||
{
|
||||
throw new Exception($"获取不到{position.FloatRateUnderlyingCode}在{rateDate:yyyy年MM月dd日}的价格");
|
||||
}
|
||||
@@ -769,7 +771,7 @@ namespace YLErp.Modules.SwapModule
|
||||
DealFloatPosition(unwindData);
|
||||
var flowList = new List<swap_flow_event>(unwindData.FlowEvents);
|
||||
var eventId = SaveSwapDeal(unwindData, (int)SwapEventTypeEnum.平仓, clientCashId, "系统操作_平仓");
|
||||
if (unwindData.CloseMethod == (int)CloseMethodEnum.全部平仓|| unwindData.ClosePercent==1)
|
||||
if (unwindData.CloseMethod == (int)CloseMethodEnum.全部平仓 || unwindData.ClosePercent == 1)
|
||||
{
|
||||
td.TradeStatus = "已平仓";
|
||||
td.trade_extend = DbContext.trade_extend.FirstOrDefault(x => x.TradeId == td.id);
|
||||
@@ -812,7 +814,7 @@ namespace YLErp.Modules.SwapModule
|
||||
/// <param name="td"></param>
|
||||
/// <param name="unwindPrice"></param>
|
||||
/// <param name="unwindPriceFee"></param>
|
||||
public void AuotoSwapUnwind(int tradeid, decimal unwindPrice, decimal unwindPriceFee, decimal unwindNetFee, decimal unwindNet, DateTime valueDate, decimal unwindQty,decimal closeFee)
|
||||
public void AuotoSwapUnwind(int tradeid, decimal unwindPrice, decimal unwindPriceFee, decimal unwindNetFee, decimal unwindNet, DateTime valueDate, decimal unwindQty, decimal closeFee)
|
||||
{
|
||||
unwindPriceFee = decimal.Parse(unwindPriceFee.ToString("F10"));
|
||||
var td = DbContext.trade.Find(tradeid);
|
||||
@@ -850,7 +852,7 @@ namespace YLErp.Modules.SwapModule
|
||||
unwindData.CloseMethod = unwindQty == unwindData.PositionQty ? (int)CloseMethodEnum.全部平仓 : (int)CloseMethodEnum.部分平仓;
|
||||
unwindData.ClosePercent = unwindData.PositionQty == 0 ? 0 : unwindPercent;
|
||||
unwindData.CloseNotionalValue = position == null ? 0 : unwindQty * position.PosiGrossPrice * position.ContractSize;
|
||||
unwindData.CloseNotionalValue = unwindPercent >= 1? unwindData.PosiNotionalValue: Math.Round(unwindData.CloseNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
unwindData.CloseNotionalValue = unwindPercent >= 1 ? unwindData.PosiNotionalValue : Math.Round(unwindData.CloseNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
unwindData.CloseQty = unwindQty;
|
||||
if (position != null)
|
||||
{
|
||||
@@ -881,12 +883,13 @@ namespace YLErp.Modules.SwapModule
|
||||
floatEvent.TradingFeePending = Math.Round(floatEvent.TradingFeePending, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
floatEvent.TradingFee = closeFee;
|
||||
floatEvent.MarkClosePnl = (unwindPrice - position.PosiGrossPrice) * unwindQty * floatRatio * longRatio;
|
||||
floatEvent.MarkClosePnl = Math.Round(floatEvent.MarkClosePnl + ((floatEvent.TradingFeePending+ closeFee) * floatRatio * -1), ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
floatEvent.MarkClosePnl = Math.Round(floatEvent.MarkClosePnl + ((floatEvent.TradingFeePending + closeFee) * floatRatio * -1) + floatEvent.DividendIn, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
floatEvent.TradingAmount = unwindPrice * floatEvent.Quantity * floatEvent.ContractSize;
|
||||
floatEvent.TradingAmount = Math.Round(floatEvent.TradingAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
floatEvent.OptLog = "流水自动";
|
||||
floatEvent.OptLog = "流水自动";
|
||||
floatEvent.ClientId = td.ClientId;
|
||||
floatEvent.SetOpt(UserInfo);
|
||||
EnrichDividendIn(floatEvent, unwindQty, td);
|
||||
}
|
||||
unwindData.FlowEvents.Add(floatEvent);
|
||||
var interestPositions = GetUnwindInterests(unwindData.ValueDate, unwindData.UnwindDate.Value, td.id, unwindPercent, (int)SwapEventTypeEnum.平仓);
|
||||
@@ -896,14 +899,46 @@ namespace YLErp.Modules.SwapModule
|
||||
});
|
||||
foreach (var item in interestPositions)
|
||||
{
|
||||
item.TdInterestAmount=Math.Round(item.TdInterestAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
item.InterestAmount=Math.Round(item.InterestAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
item.TdInterestAmount = Math.Round(item.TdInterestAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
item.InterestAmount = Math.Round(item.InterestAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
item.InterestClosePnL = Math.Round(item.InterestClosePnL, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
unwindData.FlowEvents.AddRange(interestPositions);
|
||||
CalcCloseAmount(unwindData);
|
||||
DealUnwind(unwindData, td);
|
||||
}
|
||||
|
||||
private void EnrichDividendIn(swap_flow_event flowEvent, decimal unwindQty, trade td)
|
||||
{
|
||||
if (flowEvent.UnwindDate == null)
|
||||
{
|
||||
throw new ArgumentNullException("平仓日期缺失");
|
||||
}
|
||||
var date = flowEvent.EventDate;
|
||||
BondPaymentService servie = new BondPaymentService(UserInfo);
|
||||
var payments = servie.GetBondPayments(flowEvent.UnderlyingCode, td.StartDate.Value, date);
|
||||
|
||||
int shortRatio = flowEvent.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int directionRatio = flowEvent.PayDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
// + 付息日>上日日终且小于等于平仓日期的分红数据
|
||||
var dividendIn = servie.CalcPayment(payments, unwindQty, shortRatio, directionRatio);
|
||||
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(flowEvent.UnderlyingCode);
|
||||
decimal tax = um.ValueAddedTax ?? 0;
|
||||
dividendIn = dividendIn / (1 + tax) * (1 - tax);
|
||||
|
||||
flowEvent.DividendIn = Math.Round(dividendIn, 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
public decimal GetUnderlyingTax(string code)
|
||||
{
|
||||
var data = DataCacheProvider.GetUnderlyingDataSource().GetData(code);
|
||||
if (data == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return data.ValueAddedTax ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 衡泰新增平仓事件
|
||||
/// </summary>
|
||||
@@ -1051,7 +1086,7 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
return interests;
|
||||
}
|
||||
private void DealUnwind(UnwindData unwindData, trade td, string actionMsg = "系统操作_自动平仓")
|
||||
private void DealUnwind(UnwindData unwindData, trade td, string actionMsg = "系统操作_自动平仓")
|
||||
{
|
||||
int clientCashId = AddClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_平仓费, unwindData.ValueDate);
|
||||
if (unwindData.SwapMarginAmount != 0)
|
||||
@@ -1082,7 +1117,7 @@ namespace YLErp.Modules.SwapModule
|
||||
td.TradeAmount -= Convert.ToDouble(unwindData.CloseQty);
|
||||
td.Notional = td.TradeAmount;
|
||||
td.OptDate = DateTime.Now;
|
||||
td.OptId= UserId;
|
||||
td.OptId = UserId;
|
||||
td.OptName = UserName;
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
@@ -1362,7 +1397,7 @@ namespace YLErp.Modules.SwapModule
|
||||
decimal shortRatio = item.PositionType == (int)PositionTypeFlag.Long ? -1m : 1m;
|
||||
item.TradingAmountFeeAvg = item.TradingAmountAvg + item.TradingFeePending / unwindData.CloseQty * shortRatio;
|
||||
item.TradingAmountNetFeeAvg = item.TradingAmountNetAvg + item.TradingFeePending / unwindData.CloseQty * shortRatio;
|
||||
item.TradingAmount= item.TradingAmountAvg * unwindData.CloseQty;
|
||||
item.TradingAmount = item.TradingAmountAvg * unwindData.CloseQty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1378,7 +1413,7 @@ namespace YLErp.Modules.SwapModule
|
||||
if (!string.IsNullOrEmpty(position.UnderlyingCode))
|
||||
{
|
||||
position.PosiQuantity -= unwindData.CloseQty;
|
||||
position.PosiNotionalValue = unwindData.PosiNotionalValue- unwindData.CloseNotionalValue;
|
||||
position.PosiNotionalValue = unwindData.PosiNotionalValue - unwindData.CloseNotionalValue;
|
||||
position.PosiTradingFee -= position.PosiTradingFee * unwindData.ClosePercent;
|
||||
position.PosiTradingFeePending -= position.PosiTradingFeePending * unwindData.ClosePercent;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
var flowEvents = new List<swap_flow_event>();
|
||||
Expression<Func<swap_flow_event, bool>> eventExpression = x => x.SwapTradeId == td.id && x.DataState == (int)SwapFlowDateStateEnum.完成;
|
||||
eventExpression = eventExpression.And(x => x.EventDate == settleDate );
|
||||
eventExpression = eventExpression.And(x => x.EventDate == settleDate);
|
||||
//if (settleDate == td.TradeDate)
|
||||
//{
|
||||
// eventExpression = eventExpression.And(x => x.EventDate == settleDate);
|
||||
@@ -443,7 +443,7 @@ namespace YLErp.Modules.SwapModule
|
||||
decimal allPosiNotionalValue = 0;
|
||||
decimal longNotionalValue = realPositions.Where(s => s.PositionType == (int)PositionTypeFlag.Long).Sum(s => s.PosiNotionalValue);//剩余多头名义本金规模
|
||||
decimal shortNotionalValue = realPositions.Where(s => s.PositionType == (int)PositionTypeFlag.Short).Sum(s => s.PosiNotionalValue);//剩余空头名义本金规模
|
||||
|
||||
|
||||
foreach (var eventGroup in eventQuery.GroupBy(g => g.PositionId))//持仓标的腿合成持仓
|
||||
{
|
||||
var eventList = eventGroup.ToList();
|
||||
@@ -562,7 +562,7 @@ namespace YLErp.Modules.SwapModule
|
||||
unwindData.CloseNotionalValue = tdCloseNotionalValue;
|
||||
swapEvent.EventData = JsonHelper.Serialize(unwindData);
|
||||
DbContext.SaveChanges();
|
||||
SaveEodSwap(td, tradeDate,preSettleDate);
|
||||
SaveEodSwap(td, tradeDate, preSettleDate);
|
||||
DbContext.SaveChanges();
|
||||
trans?.Commit();
|
||||
}
|
||||
@@ -717,7 +717,7 @@ namespace YLErp.Modules.SwapModule
|
||||
var interests = new SwapDealService(this).GetInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, posiNotionalValue, closePercent, (int)SwapEventTypeEnum.自动互换, false, true, grossPrice, orginPv, true);
|
||||
decimal InterestAmount = interests.Sum(x => x.InterestAmount);
|
||||
decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount);
|
||||
|
||||
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
newEodPayPosition.PositionId = position.id;
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
@@ -750,7 +750,7 @@ namespace YLErp.Modules.SwapModule
|
||||
newEodPayPosition.InterestFeeSum = eodPayPosition.InterestFeeSum + newEodPayPosition.TdInterestFee - newEodPayPosition.TdCloseInterestFee;
|
||||
newEodPayPosition.InterestProfitSum = newEodPayPosition.InterestIncomeSum + newEodPayPosition.InterestFeeSum;
|
||||
//持仓价值
|
||||
newEodPayPosition.SwapPositionValue = newEodPayPosition.InterestProfitSum + newEodPayPosition.PosiProfitSum;
|
||||
newEodPayPosition.SwapPositionValue = newEodPayPosition.InterestProfitSum + newEodPayPosition.PosiProfitSum;
|
||||
|
||||
//累计已实现
|
||||
newEodPayPosition.RealizedInterest = eodPayPosition.RealizedInterest + newEodPayPosition.TdCloseInterest * ratio;
|
||||
@@ -824,7 +824,7 @@ namespace YLErp.Modules.SwapModule
|
||||
preEodPositions.Add(eodPayPosition);
|
||||
var interests = new SwapDealService(this).GetInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, closeNational, 1, eventType, false, true, grossPrice, orginPv, true);
|
||||
decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount);
|
||||
|
||||
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
newEodPayPosition.PositionId = position.id;
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
@@ -970,7 +970,7 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
var interests = new SwapDealService(this).GetInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNational, posiShortNational, posiNotionalValue, closePercent, 0, false, needPrice, grossPrice, orginPv);
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
|
||||
|
||||
newEodPayPosition.PosiStatus = 0;
|
||||
newEodPayPosition.Invalid = false;
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
@@ -1137,11 +1137,21 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
return curretEod;
|
||||
}
|
||||
var dealDate = curretEod.ValueDate;
|
||||
var dealDate = curretEod.ValueDate;
|
||||
int shortRatio = eod.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
int directionRatio = eod.PosiDirection == (int)SwapDirectionEnum.收取 ? 1 : -1;
|
||||
curretEod.PosiStatus = curretEod.PosiQuantity == 0 ? 1 : 0;
|
||||
var price = UnderlyingCodePrice(eod.UnderlyingCode, dealDate, out decimal vobp);
|
||||
decimal tax = um.ValueAddedTax ?? 0;
|
||||
BondPaymentService bondPaymentService = new BondPaymentService(UserInfo);
|
||||
if (valueDate > td.StartDate.Value && curretEod.PosiQuantity > 0)
|
||||
{
|
||||
decimal payment = bondPaymentService.CalcPayment(curretEod.UnderlyingCode, eod.ValueDate, valueDate, curretEod.PosiQuantity, shortRatio, directionRatio);
|
||||
// 考虑增值税
|
||||
curretEod.TdPosiDividend = payment / (1 + tax) * (1 - tax);
|
||||
}
|
||||
curretEod.PosiDividendSum = eod.PosiQuantity > 0 ? (eod.PosiDividendSum + curretEod.TdPosiDividend) : 0;
|
||||
curretEod.PosiQuantity = eod.PosiQuantity;
|
||||
if (curretEod.PosiStatus == 1)
|
||||
{
|
||||
curretEod.PosiNotionalValue = 0;
|
||||
@@ -1149,12 +1159,13 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.UnderlyingPrice = price;
|
||||
curretEod.UnderlyingMarketValue = curretEod.UnderlyingPrice * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio;
|
||||
curretEod.PosiMtmPnL = (curretEod.UnderlyingPrice - curretEod.PosiGrossPrice) * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio * directionRatio;
|
||||
curretEod.TdPosiDividend = 0;
|
||||
curretEod.PosiDividendSum = eod.PosiDividendSum + curretEod.TdPosiDividend;
|
||||
curretEod.PosiProfitSum = curretEod.PosiMtmPnL + curretEod.PosiDividendSum+ curretEod.PosiFeePending;
|
||||
//curretEod.TdPosiDividend = 0;
|
||||
//curretEod.PosiDividendSum = eod.PosiDividendSum + curretEod.TdPosiDividend;
|
||||
curretEod.PosiProfitSum = curretEod.PosiMtmPnL + curretEod.PosiDividendSum + curretEod.PosiFeePending;
|
||||
curretEod.TdCloseFee = 0;
|
||||
curretEod.TdCloseQty = 0;
|
||||
curretEod.TdCloseMtmPnl = 0;
|
||||
// 需要计算平仓盈亏分红
|
||||
curretEod.TdCloseDividend = 0;
|
||||
curretEod.RealizedMtmPnL = eod.RealizedMtmPnL + curretEod.TdCloseMtmPnl;
|
||||
curretEod.RealizedDividend = eod.RealizedDividend + curretEod.TdCloseDividend;
|
||||
@@ -1197,6 +1208,7 @@ namespace YLErp.Modules.SwapModule
|
||||
if (curretEod == null)
|
||||
{
|
||||
curretEod = eod.Clone();
|
||||
curretEod.TdPosiDividend = 0;
|
||||
curretEod.id = 0;
|
||||
curretEod.ValueDate = valueDate;
|
||||
}
|
||||
@@ -1206,7 +1218,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
return curretEod;
|
||||
}
|
||||
var dealDate = curretEod.ValueDate;
|
||||
var dealDate = curretEod.ValueDate;
|
||||
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);
|
||||
@@ -1214,13 +1226,28 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.UnderlyingPrice = price;
|
||||
curretEod.UnderlyingMarketValue = curretEod.UnderlyingPrice * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio;
|
||||
curretEod.PosiMtmPnL = (curretEod.UnderlyingPrice - curretEod.PosiGrossPrice) * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio * directionRatio;
|
||||
curretEod.PosiDividendSum = eod.PosiDividendSum + curretEod.TdPosiDividend;
|
||||
curretEod.PosiProfitSum = curretEod.PosiMtmPnL + curretEod.PosiDividendSum + curretEod.PosiFeePending;
|
||||
curretEod.TdPosiDividend = 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 = payment / (1 + tax) * (1 - tax);
|
||||
}
|
||||
curretEod.RealizedMtmPnL = eod.RealizedMtmPnL + curretEod.TdCloseMtmPnl;
|
||||
curretEod.RealizedDividend = eod.RealizedDividend + curretEod.TdCloseDividend;
|
||||
|
||||
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;
|
||||
|
||||
// 浮动端待实现收益·分红 = 昨日 + 当日浮动端分红 - 当日浮动端平仓盈亏·分红
|
||||
curretEod.PosiDividendSum = eod.PosiDividendSum + curretEod.TdPosiDividend - curretEod.TdCloseDividend;
|
||||
curretEod.PosiProfitSum = curretEod.PosiMtmPnL + curretEod.PosiDividendSum + curretEod.PosiFeePending;
|
||||
if (curretEod.PosiStatus == 1)
|
||||
{
|
||||
curretEod.PosiNotionalValue = 0;
|
||||
@@ -1295,13 +1322,13 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.PosiNetFeePrice = Math.Round(curretEod.PosiNetFeePrice ?? 0, 10, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
curretEod.PosiNotionalValue = curretEod.PosiGrossPrice * curretEod.PosiQuantity * curretEod.ContractSize;
|
||||
curretEod.PosiNotionalValue= Math.Round(curretEod.PosiNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
curretEod.PosiNotionalValue = Math.Round(curretEod.PosiNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
curretEod.TdPosiDividend = unwindEvents.Sum(x => x.DividendIn) * directionRatio;
|
||||
curretEod.TdCloseFee = unwindFlowEvents.Sum(x => x.TradingFee+x.TradingFeePending);
|
||||
curretEod.TdCloseFee = unwindFlowEvents.Sum(x => x.TradingFee + x.TradingFeePending);
|
||||
curretEod.TdCloseQty = unwindQty;
|
||||
curretEod.TdCloseMtmPnl = unwindEvents.Sum(x => x.MarkClosePnl);
|
||||
}
|
||||
if (curretEod.PosiQuantity==0)
|
||||
if (curretEod.PosiQuantity == 0)
|
||||
{
|
||||
curretEod.PosiFeePending = 0;
|
||||
}
|
||||
@@ -1322,7 +1349,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
return curretEod;
|
||||
}
|
||||
var dealDate = settleDate;
|
||||
var dealDate = settleDate;
|
||||
curretEod.ValueDate = settleDate;
|
||||
curretEod.PosiStartDate = position.PosiStartDate;
|
||||
curretEod.PosiMatuirityDate = td.ExerciseDate.Value;
|
||||
@@ -1432,11 +1459,11 @@ namespace YLErp.Modules.SwapModule
|
||||
/// </summary>
|
||||
/// <param name="td">互换交易</param>
|
||||
/// <param name="settleDate">收盘日</param>
|
||||
private void SaveEodSwap(trade td, DateTime settleDate,DateTime preSettleDate)
|
||||
private void SaveEodSwap(trade td, DateTime settleDate, DateTime preSettleDate)
|
||||
{
|
||||
var eod_Swaps = DbContext.eod_swap.Where(x => x.SwapTradeId == td.id && x.ValueDate >= preSettleDate && x.ValueDate<= settleDate).ToList();
|
||||
var eod_Swap = eod_Swaps.FirstOrDefault(x => x.ValueDate == settleDate);
|
||||
var preEodSwap= eod_Swaps.FirstOrDefault(x => x.ValueDate == preSettleDate);
|
||||
var eod_Swaps = DbContext.eod_swap.Where(x => x.SwapTradeId == td.id && x.ValueDate >= preSettleDate && x.ValueDate <= settleDate).ToList();
|
||||
var eod_Swap = eod_Swaps.FirstOrDefault(x => x.ValueDate == settleDate);
|
||||
var preEodSwap = eod_Swaps.FirstOrDefault(x => x.ValueDate == preSettleDate);
|
||||
if (eod_Swap == null)
|
||||
{
|
||||
eod_Swap = new eod_swap();
|
||||
@@ -1894,14 +1921,14 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
eventDate = QdpCalendarHelper.GetNonHoliday(eventDate.AddDays(tradeExtend.ExtendObj.SettlementRules));
|
||||
}
|
||||
item.DayCount = (eventDate - item.position.PosiStartDate).Days+1;
|
||||
item.DayCount = (eventDate - item.position.PosiStartDate).Days + 1;
|
||||
//item.position.PosiProfitSum += item.position.VTradingFee-item.position.PosiFeePending;
|
||||
SetClientEodPosition(item.position);
|
||||
//item.position.PosiProfitSum += item.TradingFee;
|
||||
var posiProfitSum= item.position.PosiProfitSum;
|
||||
var posiProfitSum = item.position.PosiProfitSum;
|
||||
//item.position.PosiProfitSum 不需要加交易费用
|
||||
item.position.PosiProfitSum = item.position.PosiProfitSum - item.position.PosiFeePending-item.position.PosiDividendSum;
|
||||
item.NetSettmentAmount = item.position.PosiProfitSum+ item.position.PosiDividendSum+ item.position.PosiFeePending;
|
||||
item.position.PosiProfitSum = item.position.PosiProfitSum - item.position.PosiFeePending - item.position.PosiDividendSum;
|
||||
item.NetSettmentAmount = item.position.PosiProfitSum + item.position.PosiDividendSum + item.position.PosiFeePending;
|
||||
item.PeriodAmount = item.position.PosiDividendSum;
|
||||
var margins = positions.Where(x => x.SwapTradeId == item.position.SwapTradeId);
|
||||
var interests = eodPositions.Where(x => x.SwapTradeId == item.position.SwapTradeId && x.ValueDate == item.position.ValueDate);
|
||||
@@ -1909,14 +1936,14 @@ namespace YLErp.Modules.SwapModule
|
||||
var eodInterests = interests.Where(x => !marginTypes.Contains(x.InterestMode));
|
||||
var floatRateInterest = eodInterests.Where(x => !string.IsNullOrEmpty(x.FloatRateUnderlyingCode)).FirstOrDefault();
|
||||
item.position.FloatRateUnderlyingCode = floatRateInterest?.FloatRateUnderlyingCode;
|
||||
item.position.FloatRate= floatRateInterest?.FloatRate??0;
|
||||
item.position.FloatRate = floatRateInterest?.FloatRate ?? 0;
|
||||
item.OpenMarginAmount = margins.Sum(s => s.InterestPrincipalFix * (s.InterestDirection == (int)SwapDirectionEnum.收取 ? 1 : -1));
|
||||
item.OpenMarginRate = margins.Sum(s => s.InterestRateDefault * (s.InterestDirection == (int)SwapDirectionEnum.收取 ? 1 : -1));
|
||||
item.MarginInterestAmount = eodMargins.Sum(s => s.InterestIncomeSum * (s.InterestDirection == (int)SwapDirectionEnum.收取 ? 1 : -1));
|
||||
item.InterestAmount = eodInterests.Sum(s => s.InterestIncomeSum * (s.InterestDirection == (int)SwapDirectionEnum.收取 ? -1 : 1));
|
||||
item.InterestRate = eodInterests.Sum(s => s.InterestRateDefault);
|
||||
item.NetSettmentAmount += item.InterestAmount + item.MarginInterestAmount + eodMargins.Sum(s => s.InterestPrincipalFix * (s.InterestDirection == (int)SwapDirectionEnum.收取 ? 1 : -1));
|
||||
item.NetSettmentAmount = Math.Round(item.NetSettmentAmount, ConsGlobal.MoneyRound,MidpointRounding.AwayFromZero);
|
||||
item.NetSettmentAmount = Math.Round(item.NetSettmentAmount, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
if (item.position.PosiNotionalValue != 0 && item.position.PosiNetPrice != 0)
|
||||
{
|
||||
item.FloatRateAbs = item.position.PosiNotionalValue == 0 ? 0 : item.InterestAmount / item.position.PosiNotionalValue;
|
||||
@@ -1962,7 +1989,7 @@ namespace YLErp.Modules.SwapModule
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户互换持仓信息
|
||||
/// </summary>
|
||||
@@ -1987,7 +2014,7 @@ namespace YLErp.Modules.SwapModule
|
||||
foreach (var item in eodSwaps)
|
||||
{
|
||||
var tradeOrigin = trades.First(x => x.id == item.SwapTradeId);
|
||||
var realizedPnL = item.RealizedMtmPnL + item.RealizedInterest;
|
||||
var realizedPnL = item.RealizedMtmPnL + item.RealizedInterest;
|
||||
var tdExtend = tradeExtends.First(x => x.TradeId == item.SwapTradeId);
|
||||
eod_position model = new eod_position()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user