dv01全局去除
This commit is contained in:
@@ -288,7 +288,7 @@ namespace YLErp.Modules.SwapModule
|
||||
continue;
|
||||
}
|
||||
var eodPosition = eodPositions.FirstOrDefault(x => x.PositionId == interest.id);//上一日日终利息信息 可能不存在
|
||||
var tdEodPosition = todyEodPositions.FirstOrDefault(x => x.PositionId == interest.id && x.IsSkipEod);//当前结算日日终利息信息
|
||||
var tdEodPosition = todyEodPositions.FirstOrDefault(x => x.PositionId == interest.id);//当前结算日日终利息信息
|
||||
var insterval = interest.SwapIntervalList.FirstOrDefault(x => x.Date == settleDate && x.Settlement == 1);//自动互换观察日信息
|
||||
List<swap_flow_event> dealInterests = new List<swap_flow_event>();
|
||||
dealInterests.AddRange(flowEvents);
|
||||
@@ -376,7 +376,7 @@ namespace YLErp.Modules.SwapModule
|
||||
foreach (var posi in posiList)
|
||||
{
|
||||
var eodPosition = eodPositions.Where(x => x.PositionId == posi.id).FirstOrDefault();//上一日日终持仓信息
|
||||
var tdEodPosition = todyEodPositions.FirstOrDefault(x => x.PositionId == posi.id && x.IsSkipEod);//当前结算日日终持仓信息
|
||||
var tdEodPosition = todyEodPositions.FirstOrDefault(x => x.PositionId == posi.id);//当前结算日日终持仓信息
|
||||
var unwindEvents = flowEvents.Where(x => x.PositionId == posi.id).ToList();//当前日平仓信息
|
||||
var realPosition = realPosiList.FirstOrDefault(s => s.PositionId == posi.id);
|
||||
eod_swap_position eodPosi = new eod_swap_position();
|
||||
@@ -389,7 +389,6 @@ namespace YLErp.Modules.SwapModule
|
||||
else
|
||||
{
|
||||
tdEodPosition.PosiFeePending = posi.PosiTradingFeePending;
|
||||
UpdateHTData(tdEodPosition);
|
||||
tdEodPosition.PosiNotionalValue = tdEodPosition.PosiQuantity * tdEodPosition.ContractSize;
|
||||
tdEodPosition.PosiNetFeePrice = posi.PosiNetFeePrice;
|
||||
tdEodPosition.PosiNetNoFeePrice = posi.PosiNetNoFeePrice;
|
||||
@@ -700,12 +699,6 @@ namespace YLErp.Modules.SwapModule
|
||||
newEodPayPosition.PosiStartDate = position.PosiStartDate;
|
||||
eodPayPosition.PosiMatuirityDate = td.ExerciseDate.Value;
|
||||
}
|
||||
if (newEodPayPosition.IsSkipEod)
|
||||
{
|
||||
newEodPayPosition.FloatRate = flowEvents.FirstOrDefault()?.FloatRate ?? 0;
|
||||
newEodPayPosition.FloatRateUnderlyingCode = position.FloatRateUnderlyingCode;
|
||||
return;
|
||||
}
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
newEodPayPosition.PositionId = position.id;
|
||||
newEodPayPosition.ClientId = td.ClientId;
|
||||
@@ -793,7 +786,6 @@ namespace YLErp.Modules.SwapModule
|
||||
if (newEodPayPosition == null)
|
||||
{
|
||||
newEodPayPosition = eodPayPosition.Clone();
|
||||
newEodPayPosition.IsSkipEod = false;
|
||||
newEodPayPosition.id = 0;
|
||||
}
|
||||
List<swap_position> positions = new List<swap_position>();
|
||||
@@ -803,12 +795,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, true);
|
||||
decimal InterestAmount = interests.Sum(x => x.InterestAmount);
|
||||
decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount);
|
||||
if (newEodPayPosition.IsSkipEod)
|
||||
{
|
||||
newEodPayPosition.FloatRate = interests.Count > 0 ? interests.First().FloatRate ?? 0 : 0;
|
||||
newEodPayPosition.FloatRateUnderlyingCode = position.FloatRateUnderlyingCode;
|
||||
return new List<swap_flow_event>();
|
||||
}
|
||||
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
newEodPayPosition.PositionId = position.id;
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
@@ -909,12 +896,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, true);
|
||||
decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount);
|
||||
if (newEodPayPosition.IsSkipEod)
|
||||
{
|
||||
newEodPayPosition.FloatRate = interests.Count > 0 ? interests.First().FloatRate ?? 0 : 0;
|
||||
newEodPayPosition.FloatRateUnderlyingCode = position.FloatRateUnderlyingCode;
|
||||
return new List<swap_flow_event>();
|
||||
}
|
||||
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
newEodPayPosition.PositionId = position.id;
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
@@ -1020,7 +1002,6 @@ namespace YLErp.Modules.SwapModule
|
||||
newEodPayPosition = eodPayPosition.Clone();
|
||||
newEodPayPosition.id = 0;
|
||||
newEodPayPosition.PositionId = position.id;
|
||||
newEodPayPosition.IsSkipEod = false;
|
||||
}
|
||||
|
||||
bool longShort = td.StructureType == ClientMarginTypeEnum.多空组合.ToString();
|
||||
@@ -1055,11 +1036,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);
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
if (newEodPayPosition.IsSkipEod)
|
||||
{
|
||||
newEodPayPosition.FloatRate = interests.Count > 0 ? interests.First().FloatRate ?? 0 : 0;
|
||||
return;
|
||||
}
|
||||
|
||||
newEodPayPosition.PosiStatus = 0;
|
||||
newEodPayPosition.Invalid = false;
|
||||
newEodPayPosition.ValueDate = valueDate;
|
||||
@@ -1184,7 +1161,6 @@ namespace YLErp.Modules.SwapModule
|
||||
newEodPayPosition.RealizedPnl = newEodPayPosition.TdCloseMtmPnl + newEodPayPosition.TdCloseDividend + newEodPayPosition.TdCloseFee;
|
||||
|
||||
newEodPayPosition.PosiStatus = payQty == 0 ? 1 : 0;
|
||||
newEodPayPosition.DV01 = newEodPayPosition.PosiQuantity * newEodPayPosition.ContractSize * vobp * shortRatio * ratio * 0.01m;
|
||||
UpdateDbOption(newEodPayPosition);
|
||||
newEodPayPosition.Invalid = false;
|
||||
var currencyRate = new EodCurrencyRateService(UserInfo).GetCurrencyRate(td.QuoteCurrency, td.SettlementCurrency, eventFlow.EventDate
|
||||
@@ -1221,7 +1197,6 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod = eod.Clone();
|
||||
curretEod.id = 0;
|
||||
curretEod.ValueDate = valueDate;
|
||||
curretEod.IsSkipEod = false;
|
||||
}
|
||||
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(eod.UnderlyingCode);
|
||||
if (um == null)
|
||||
@@ -1237,17 +1212,6 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
curretEod.PosiNotionalValue = 0;
|
||||
}
|
||||
if (curretEod.IsSkipEod)
|
||||
{
|
||||
curretEod.DV01 = curretEod.PosiQuantity * curretEod.ContractSize * vobp * shortRatio * directionRatio * 0.01m;
|
||||
curretEod.PosiNotionalValue = curretEod.PosiQuantity * curretEod.ContractSize;
|
||||
curretEod.PosiNetFeePrice = eod.PosiNetFeePrice;
|
||||
curretEod.PosiNetNoFeePrice = eod.PosiNetNoFeePrice;
|
||||
curretEod.PosiFeePending= eod.PosiFeePending;
|
||||
UpdateHTData(curretEod);
|
||||
UpdateDbOption(curretEod);
|
||||
return curretEod;
|
||||
}
|
||||
curretEod.UnderlyingPrice = price;
|
||||
curretEod.UnderlyingMarketValue = curretEod.UnderlyingPrice * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio;
|
||||
curretEod.PosiMtmPnL = (curretEod.UnderlyingPrice - curretEod.PosiGrossPrice) * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio * directionRatio;
|
||||
@@ -1267,7 +1231,6 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.TdCurrency = Convert.ToDecimal(currencyRate);
|
||||
//持仓价值
|
||||
curretEod.SwapPositionValue = curretEod.InterestProfitSum + curretEod.PosiProfitSum;
|
||||
curretEod.DV01 = curretEod.PosiQuantity * curretEod.ContractSize * vobp * shortRatio * directionRatio * 0.01m;
|
||||
UpdateDbOption(curretEod);
|
||||
curretEod.Invalid = false;
|
||||
if (curretEod.id == 0)
|
||||
@@ -1277,16 +1240,6 @@ namespace YLErp.Modules.SwapModule
|
||||
return curretEod;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新浮动端收益
|
||||
/// </summary>
|
||||
/// <param name="curretEod"></param>
|
||||
private void UpdateHTData(eod_swap_position curretEod)
|
||||
{
|
||||
UpdateVTradingFee(curretEod);
|
||||
curretEod.PosiProfitSum = curretEod.HTPosiProfitSum + curretEod.VTradingFee;
|
||||
curretEod.SwapPositionValue = curretEod.HTSwapPositionValue + curretEod.VTradingFee;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新虚拟交易费用
|
||||
/// </summary>
|
||||
/// <param name="curretEod"></param>
|
||||
@@ -1312,7 +1265,6 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod = eod.Clone();
|
||||
curretEod.id = 0;
|
||||
curretEod.ValueDate = valueDate;
|
||||
curretEod.IsSkipEod = false;
|
||||
}
|
||||
|
||||
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(eod.UnderlyingCode);
|
||||
@@ -1324,14 +1276,7 @@ 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);
|
||||
SetPriceInfoByFlowEvent(eod, curretEod, unwindEvents, swapPosition, !curretEod.IsSkipEod);
|
||||
if (curretEod.IsSkipEod)
|
||||
{
|
||||
curretEod.DV01 = curretEod.PosiQuantity * curretEod.ContractSize * vobp * shortRatio * directionRatio * 0.01m;
|
||||
UpdateHTData(curretEod);
|
||||
UpdateDbOption(curretEod);
|
||||
return curretEod;
|
||||
}
|
||||
SetPriceInfoByFlowEvent(eod, curretEod, unwindEvents, swapPosition);
|
||||
curretEod.UnderlyingPrice = price;
|
||||
curretEod.UnderlyingMarketValue = curretEod.UnderlyingPrice * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio;
|
||||
curretEod.PosiMtmPnL = (curretEod.UnderlyingPrice - curretEod.PosiGrossPrice) * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio * directionRatio;
|
||||
@@ -1351,7 +1296,6 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.TdCurrency = Convert.ToDecimal(currencyRate);
|
||||
//持仓价值
|
||||
curretEod.SwapPositionValue = curretEod.InterestProfitSum + curretEod.PosiProfitSum;
|
||||
curretEod.DV01 = curretEod.PosiQuantity * curretEod.ContractSize * vobp * shortRatio * directionRatio * 0.01m;
|
||||
UpdateDbOption(curretEod);
|
||||
curretEod.Invalid = false;
|
||||
if (curretEod.id == 0)
|
||||
@@ -1366,7 +1310,7 @@ namespace YLErp.Modules.SwapModule
|
||||
/// <param name="eod"></param>
|
||||
/// <param name="curretEod"></param>
|
||||
/// <param name="unwindEvents"></param>
|
||||
public void SetPriceInfoByFlowEvent(eod_swap_position eod, eod_swap_position curretEod, List<swap_flow_event> unwindEvents, swap_position position, bool coverageQty=true)
|
||||
public void SetPriceInfoByFlowEvent(eod_swap_position eod, eod_swap_position curretEod, List<swap_flow_event> unwindEvents, swap_position position)
|
||||
{
|
||||
if (eod.PosiDirection == 0)
|
||||
{
|
||||
@@ -1379,21 +1323,14 @@ namespace YLErp.Modules.SwapModule
|
||||
decimal unwindQty = unwindFlowEvents.Sum(s => s.Quantity);
|
||||
decimal openQty = openFlowEvents.Sum(s => s.Quantity);
|
||||
var qty = eod.PosiQuantity + openQty - unwindQty;
|
||||
if (coverageQty)
|
||||
{
|
||||
curretEod.PosiQuantity = qty < 0 ? 0 : Math.Abs(qty);
|
||||
}
|
||||
|
||||
curretEod.PosiQuantity = qty < 0 ? 0 : Math.Abs(qty);
|
||||
if (unwindEvents.Count == 0)
|
||||
{
|
||||
curretEod.PosiNetPrice = position.PosiNetPrice;
|
||||
curretEod.PosiGrossPrice = position.PosiGrossPrice;
|
||||
curretEod.PosiNetFeePrice = position.PosiNetFeePrice;
|
||||
curretEod.PosiNetNoFeePrice = position.PosiNetNoFeePrice;
|
||||
if (coverageQty)
|
||||
{
|
||||
curretEod.PosiQuantity = position.PosiQuantity;
|
||||
}
|
||||
curretEod.PosiQuantity = position.PosiQuantity;
|
||||
curretEod.PosiTradingFee = position.PosiTradingFee;
|
||||
}
|
||||
else
|
||||
@@ -1496,7 +1433,6 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
//持仓价值
|
||||
curretEod.SwapPositionValue = curretEod.InterestProfitSum + curretEod.PosiProfitSum;
|
||||
curretEod.DV01 = curretEod.PosiQuantity * curretEod.ContractSize * vobp * shortRatio * directionRatio * 0.01m;
|
||||
var currencyRate = new EodCurrencyRateService(UserInfo).GetCurrencyRate(td.QuoteCurrency, td.SettlementCurrency, td.StartDate.Value
|
||||
, seekPreday: true, currencyRateType: curretEod.PosiDirection == (int)SwapDirectionEnum.收取 ? CurrencyRateType.Buy : CurrencyRateType.Sell);
|
||||
curretEod.TdCurrency = Convert.ToDecimal(currencyRate);
|
||||
@@ -1572,17 +1508,6 @@ namespace YLErp.Modules.SwapModule
|
||||
eod_Swap.NotionalValueLong = positions.Where(x => x.PositionType == (int)PositionTypeFlag.Long).Sum(s => s.PosiNotionalValue);
|
||||
eod_Swap.NotionalValueShort = positions.Where(x => x.PositionType == (int)PositionTypeFlag.Short).Sum(s => s.PosiNotionalValue);
|
||||
eod_Swap.NotionalValue = eod_Swap.NotionalValueLong + eod_Swap.NotionalValueShort;
|
||||
if (eod_Swap.IsSkipEod == true)
|
||||
{
|
||||
var vtradingFee = eodSwapPositions.Sum(x => x.VTradingFee);
|
||||
eod_Swap.VTradingFee = vtradingFee;
|
||||
eod_Swap.DV01 = positions.Sum(s => s.DV01 ?? 0);
|
||||
eod_Swap.PostionValue = eod_Swap.HTPostionValue + vtradingFee;
|
||||
eod_Swap.FloatingPnL = eod_Swap.HTFloatingPnL + vtradingFee;
|
||||
eod_Swap.TdRealizedPnL = eod_Swap.RealizedPnL - (preEodSwap?.RealizedPnL??0);// 当日已实现-上日已实现
|
||||
UpdateDbOption(eod_Swap);
|
||||
return;
|
||||
}
|
||||
eod_Swap.SwapTradeId = td.id;
|
||||
eod_Swap.SwapTradeNo = td.TradeNumber;
|
||||
eod_Swap.ClientId = td.ClientId;
|
||||
@@ -1617,7 +1542,6 @@ namespace YLErp.Modules.SwapModule
|
||||
eod_Swap.PostionValue = eodSwapPositions.Sum(s => s.SwapPositionValue);
|
||||
eod_Swap.RealizedPnL = eodSwapPositions.Sum(s => s.RealizedMtmPnL + s.RealizedDividend + s.RealizedFee + s.RealizedInterest + s.RealizedInterestFee);
|
||||
eod_Swap.TdCloseQty = positions.Sum(s => s.TdCloseQty);
|
||||
eod_Swap.DV01 = positions.Sum(s => s.DV01 ?? 0);
|
||||
var initMargin = Convert.ToDecimal(tradeSpan?.InitialMargin ?? 0);
|
||||
var maintainMargin = Convert.ToDecimal(tradeSpan?.WorstCastClientPayable ?? 0);
|
||||
if (initMargin < 0)
|
||||
@@ -1688,7 +1612,6 @@ namespace YLErp.Modules.SwapModule
|
||||
eod_Swap.PostionValue = eodSwapPositions.Sum(s => s.SwapPositionValue);
|
||||
eod_Swap.RealizedPnL = eodSwapPositions.Sum(s => s.RealizedMtmPnL + s.RealizedDividend + s.RealizedFee + s.RealizedInterest + s.RealizedInterestFee);
|
||||
eod_Swap.TdCloseQty = positions.Sum(s => s.TdCloseQty);
|
||||
eod_Swap.DV01 = positions.Sum(s => s.DV01 ?? 0);
|
||||
var tradeInitMarginObj = DbContext.trade_initial_margin.FirstOrDefault(x => x.TradeId == td.id);
|
||||
var initMarginList = interestPositions.Where(x => x.InterestMode == (int)InterestModeEnum.初始预付金 && x.HappenDate == settleDate).ToList();
|
||||
var addMarginList = interestPositions.Where(x => x.InterestMode == (int)InterestModeEnum.追加预付金 && x.HappenDate == settleDate).ToList();
|
||||
|
||||
Reference in New Issue
Block a user