山证bug修复及功能 迁移
This commit is contained in:
@@ -118,7 +118,7 @@ namespace YLErp.Modules.SwapModule
|
||||
floatEvent.PositionQty = 0;
|
||||
floatEvent.ContractSize = position.ContractSize;
|
||||
floatEvent.TradingAmount = floatEvent.Quantity * floatEvent.ContractSize;
|
||||
var ratio = position.PosiDirection == (int)SwapDirectionEnum.收取 ? -1 : 1;
|
||||
var ratio = position.PosiDirection == (int)SwapDirectionEnum.收取 ? -1m : 1m;
|
||||
floatEvent.TradingFeePending = position.PosiTradingFeePending;
|
||||
floatEvent.DataState = (int)SwapFlowDateStateEnum.完成;
|
||||
floatEvent.InterestMode = position.InterestMode;
|
||||
@@ -385,7 +385,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
_closePosiNotionalValue = position.InterestPrincipalFix;
|
||||
_posiNotionalValue = position.InterestPrincipalFix;
|
||||
newClosePercent = 1;
|
||||
newClosePercent = 1m;
|
||||
}
|
||||
else if (position.InterestMode == (int)InterestModeEnum.多头存续名义本金)
|
||||
{
|
||||
@@ -410,8 +410,8 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
if (!string.IsNullOrEmpty(position.FloatRateUnderlyingCode))
|
||||
{
|
||||
var rateDate = QdpCalendarHelper.GetNonHolidayDefore(td.StartDate.Value.AddDays(-1));
|
||||
if (EodPriceQueryService.TryGetReferencePrice(rateDate, position.FloatRateUnderlyingCode, out double floatRate))
|
||||
var rateDate = td.StartDate.Value.AddDays(-1);
|
||||
if (EodPriceQueryService.TryGetPrice(rateDate, position.FloatRateUnderlyingCode, out double floatRate))
|
||||
{
|
||||
position.FloatRate = Convert.ToDecimal(floatRate);
|
||||
positionClone.FloatRate = position.FloatRate;
|
||||
@@ -508,7 +508,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
decimal InterestAmount = 0;
|
||||
decimal TdInterestAmount = 0;
|
||||
var interestRatio = position.InterestDirection == 1 ? 1 : -1;
|
||||
var interestRatio = position.InterestDirection == 1 ? 1m : -1m;
|
||||
if (position.InterestType == (int)InterestTypeEnum.复利)
|
||||
{
|
||||
var floateRate = preEodPosition.FloatRate;
|
||||
@@ -538,7 +538,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
if (itemDays > 1)//日期超算情况
|
||||
{
|
||||
decimal days = (decimal)itemDays - 1;
|
||||
decimal days = (decimal)itemDays - 1m;
|
||||
if (position.IsAnnualized)
|
||||
{
|
||||
InterestAmount = InterestAmount * (days / annualDays);
|
||||
@@ -554,8 +554,8 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
}
|
||||
|
||||
interest.InterestAmount = InterestAmount;
|
||||
interest.TdInterestAmount = TdInterestAmount;
|
||||
interest.InterestAmount = decimal.Parse(InterestAmount.ToString("0.0000"));
|
||||
interest.TdInterestAmount = decimal.Parse(TdInterestAmount.ToString("0.0000"));
|
||||
interest.InterestClosePnL = interest.InterestAmount * interestRatio;
|
||||
}
|
||||
if (add)
|
||||
@@ -597,15 +597,15 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
dynomicPrincipal = dynomicPrincipal + interest;
|
||||
tdDynomicPrincipal = tdDynomicPrincipal + interest;
|
||||
if (rateDate > tradeDate)
|
||||
{
|
||||
dynomicPrincipal += interestProfitSum;
|
||||
tdDynomicPrincipal += interestProfitSum;
|
||||
}
|
||||
//if (rateDate > tradeDate)
|
||||
//{
|
||||
// dynomicPrincipal += interestProfitSum;
|
||||
// tdDynomicPrincipal += interestProfitSum;
|
||||
//}
|
||||
if (!string.IsNullOrEmpty(position.FloatRateUnderlyingCode))
|
||||
{
|
||||
var fr007RateDate = QdpCalendarHelper.GetNonHolidayDefore(rateDate.AddDays(-1));
|
||||
if (EodPriceQueryService.TryGetReferencePrice(fr007RateDate, position.FloatRateUnderlyingCode, out double floatRate1))
|
||||
var fr007RateDate = rateDate.AddDays(-1);
|
||||
if (EodPriceQueryService.TryGetPrice(fr007RateDate, position.FloatRateUnderlyingCode, out double floatRate1))
|
||||
{
|
||||
if (floatRate1 != 0)
|
||||
{
|
||||
@@ -634,8 +634,8 @@ namespace YLErp.Modules.SwapModule
|
||||
interest1 /= annualDays;
|
||||
tdinterest1 /= annualDays;
|
||||
}
|
||||
interest += interest1;
|
||||
tdinterest += tdinterest1;
|
||||
interest += decimal.Parse(interest1.ToString("0.0000"));
|
||||
tdinterest += decimal.Parse(tdinterest1.ToString("0.0000"));
|
||||
|
||||
}
|
||||
else
|
||||
@@ -675,8 +675,8 @@ namespace YLErp.Modules.SwapModule
|
||||
tdDynomicPrincipal = tdDynomicPrincipal + interestProfitSum;
|
||||
if (!string.IsNullOrEmpty(position.FloatRateUnderlyingCode))
|
||||
{
|
||||
var fr007RateDate = QdpCalendarHelper.GetNonHolidayDefore(endDate.AddDays(-1));
|
||||
if (EodPriceQueryService.TryGetReferencePrice(fr007RateDate, position.FloatRateUnderlyingCode, out double floatRate1))
|
||||
var fr007RateDate = endDate.AddDays(-1);
|
||||
if (EodPriceQueryService.TryGetPrice(fr007RateDate, position.FloatRateUnderlyingCode, out double floatRate1))
|
||||
{
|
||||
if (floatRate1 != 0)
|
||||
{
|
||||
@@ -785,6 +785,7 @@ namespace YLErp.Modules.SwapModule
|
||||
/// <param name="unwindPriceFee"></param>
|
||||
public void AuotoSwapUnwind(int tradeid, decimal unwindPrice, decimal unwindPriceFee, decimal unwindNetFee, decimal unwindNet, DateTime valueDate, decimal unwindQty, decimal mergeQty, decimal penddingFee)
|
||||
{
|
||||
unwindPriceFee = decimal.Parse(unwindPriceFee.ToString("F10"));
|
||||
var td = DbContext.trade.Find(tradeid);
|
||||
var positions = DbContext.swap_position.Where(x => x.SwapTradeId == td.id && !x.Invalid);
|
||||
List<int> eventTypes = new List<int>() { (int)SwapEventTypeEnum.平仓, (int)SwapEventTypeEnum.互换 };
|
||||
@@ -823,8 +824,8 @@ namespace YLErp.Modules.SwapModule
|
||||
unwindData.CloseQty = unwindQty;
|
||||
if (position != null)
|
||||
{
|
||||
var floatRatio = position.PosiDirection == 1 ? 1 : -1;
|
||||
var longRatio = position.PositionType == 1 ? 1 : -1;
|
||||
decimal floatRatio = position.PosiDirection == 1 ? 1m : -1m;
|
||||
decimal longRatio = position.PositionType == 1 ? 1m : -1m;
|
||||
floatEvent.PositionId = position.PositionId;
|
||||
floatEvent.EventType = (int)SwapFlowEventTypeEnum.平仓;
|
||||
floatEvent.EventReason = "交易";
|
||||
@@ -850,6 +851,7 @@ namespace YLErp.Modules.SwapModule
|
||||
var mergeClosePercent = mergeQty == 0 ? 0 : unwindQty / mergeQty;
|
||||
floatEvent.TradingFee = penddingFee * mergeClosePercent;
|
||||
floatEvent.MarkClosePnl = (unwindPriceFee - position.PosiNetPrice) * unwindData.PosiNotionalValue * floatRatio * longRatio;
|
||||
floatEvent.MarkClosePnl = decimal.Parse(floatEvent.MarkClosePnl.ToString("0.00"));
|
||||
floatEvent.TradingAmount = floatEvent.Quantity * floatEvent.ContractSize;
|
||||
floatEvent.OptLog = "流水自动";
|
||||
floatEvent.ClientId = td.ClientId;
|
||||
@@ -910,7 +912,7 @@ namespace YLErp.Modules.SwapModule
|
||||
unwindData.CloseQty = allClose ? unwindData.PositionQty : unwindQty;
|
||||
if (position != null)
|
||||
{
|
||||
var floatRatio = position.PosiDirection == 1 ? 1 : -1;
|
||||
decimal floatRatio = position.PosiDirection == 1 ? 1m : -1m;
|
||||
floatEvent.PositionId = position.id;
|
||||
floatEvent.EventType = (int)SwapEventTypeEnum.平仓;
|
||||
floatEvent.EventReason = "接口合约终止交易";
|
||||
@@ -942,7 +944,7 @@ namespace YLErp.Modules.SwapModule
|
||||
var interestPositions = GetUnwindInterestsByHT(unwindData, td, interestAmount, fee);
|
||||
unwindData.FlowEvents.AddRange(interestPositions);
|
||||
CalcCloseAmount(unwindData);
|
||||
DealUnwind(unwindData, td, false, "合约终止接口回执");
|
||||
DealUnwind(unwindData, td, "合约终止接口回执");
|
||||
}
|
||||
private List<swap_flow_event> GetUnwindInterestsByHT(UnwindData unwindData, trade td, decimal interestAmount, decimal fee)
|
||||
{
|
||||
@@ -965,7 +967,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
_closePosiNotionalValue = item.InterestPrincipalFix;
|
||||
_posiNotionalValue = item.InterestPrincipalFix;
|
||||
newClosePercent = 1;
|
||||
newClosePercent = 1m;
|
||||
}
|
||||
else if (item.InterestMode == (int)InterestModeEnum.标的期初全价)
|
||||
{
|
||||
@@ -1012,7 +1014,7 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
return interests;
|
||||
}
|
||||
private void DealUnwind(UnwindData unwindData, trade td, bool addLog = true, string actionMsg = "系统操作_自动平仓")
|
||||
private void DealUnwind(UnwindData unwindData, trade td, string actionMsg = "系统操作_自动平仓")
|
||||
{
|
||||
int clientCashId = CloseTrade_ClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_平仓费, unwindData.ValueDate);
|
||||
if (unwindData.SwapMarginAmount != 0)
|
||||
@@ -1052,7 +1054,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
var floatPosition = unwindData.FlowEvents.FirstOrDefault(x => !string.IsNullOrEmpty(x.UnderlyingCode));
|
||||
var interestList = unwindData.FlowEvents.Where(x => string.IsNullOrEmpty(x.UnderlyingCode));
|
||||
var floatRatio = floatPosition.PayDirection == 1 ? 1 : -1;
|
||||
decimal floatRatio = floatPosition.PayDirection == 1 ? 1m : -1m;
|
||||
var pnl = floatPosition.MarkClosePnl;
|
||||
unwindData.SwapCloseAmount = pnl;
|
||||
unwindData.SwapRealizedPnL = pnl;
|
||||
@@ -1064,7 +1066,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
if (x.InterestMode == (int)InterestModeEnum.追加预付金 || x.InterestMode == (int)InterestModeEnum.初始预付金)
|
||||
{
|
||||
var interestRatio = x.InterestDirection == 1 ? -1 : 1;
|
||||
decimal interestRatio = x.InterestDirection == 1 ? -1m : 1m;
|
||||
unwindData.SwapMarginRebatePnl += x.InterestClosePnL;
|
||||
unwindData.SwapMarginAmount += x.InterestPrincipal * interestRatio;
|
||||
}
|
||||
@@ -1073,6 +1075,7 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
});
|
||||
}
|
||||
unwindData.SwapCloseAmount = decimal.Parse(unwindData.SwapCloseAmount.ToString("0.00"));
|
||||
unwindData.SwapRealizedPnL = unwindData.SwapCloseAmount;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -1245,7 +1248,6 @@ namespace YLErp.Modules.SwapModule
|
||||
td.TradeAmount -= Convert.ToDouble(swapEvent.unwindData.CloseQty);
|
||||
}
|
||||
td.StockEqvNotional -= Convert.ToDouble(swapEvent.unwindData.CloseNotionalValue);
|
||||
|
||||
}
|
||||
td.UnWindDate = swapEvent.unwindData.UnwindDate;
|
||||
UpdateInitalPosition(flowList, swapEvent.unwindData, eventType);
|
||||
@@ -1339,7 +1341,7 @@ namespace YLErp.Modules.SwapModule
|
||||
item.OptLog = "手工操作";
|
||||
if (item.PositionType > 0 && item.EventType == (int)SwapEventTypeEnum.平仓)
|
||||
{
|
||||
int shortRatio = item.PositionType == (int)PositionTypeFlag.Long ? 1 : -1;
|
||||
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;
|
||||
}
|
||||
@@ -1359,7 +1361,7 @@ namespace YLErp.Modules.SwapModule
|
||||
var dealFloat = flowList.FirstOrDefault(x => !string.IsNullOrEmpty(x.UnderlyingCode));
|
||||
if (dealFloat != null)
|
||||
{
|
||||
var ratio = dealFloat.EventType == (int)SwapFlowEventTypeEnum.平仓 ? -1 : 1;
|
||||
decimal ratio = dealFloat.EventType == (int)SwapFlowEventTypeEnum.平仓 ? -1m : 1m;
|
||||
position.PosiTradingFeePending += dealFloat.TradingFeePending * ratio;
|
||||
position.PosiDividendIncome += dealFloat.DividendPending;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user