diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index 80d0f28f..d29f4352 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -181,8 +181,8 @@ namespace YLErp.Modules.SwapModule unwindData.StartDate = preDealDate.Value; } unwindData.ValueDate = dealDate; - unwindData.UnwindDate = unwindData.UnwindDate; - unwindData.PayDate = QdpCalendarHelper.GetNonHoliday(unwindData.UnwindDate.Value.AddDays(td.trade_extend.ExtendObj.SettlementRules)); + unwindData.UnwindDate = dealDate; + unwindData.PayDate = QdpCalendarHelper.GetNonHoliday(dealDate.AddDays(td.trade_extend.ExtendObj.SettlementRules)); unwindData.SwapTradeId = tradeId; unwindData.NotionalValue = Convert.ToDecimal(td.OriginalStockEqvNotional ?? 0); unwindData.NotionalQty = positions.Sum(s => s.PosiQuantity); @@ -610,17 +610,17 @@ namespace YLErp.Modules.SwapModule DateTime lastSwapDate = preEodPosition.ValueDate; decimal interestProfitSum = preEodPosition.InterestProfitSum; var TdInterestPrincipal = preEodPosition.TdInterestPrincipal; - decimal interest = 0; - decimal tdinterest = 0; + decimal interest = interestProfitSum * closePercent; + decimal tdinterest = interestProfitSum * closePercent; int interestPeriod = position.interest_rest_days ?? 1; decimal dynomicPrincipal = principal; decimal tdDynomicPrincipal = posiPrincipal; - var calcDays = (endDate - tradeDate).Days; + var calcDays = (endDate - lastSwapDate).Days; double floatRate = Convert.ToDouble(floateRate); for (int i = 0; i <= calcDays; i++) { - var rateDate = tradeDate.AddDays(i); - if (rateDate > lastSwapDate || endDate == tradeDate) + var rateDate = lastSwapDate.AddDays(i); + if (rateDate > lastSwapDate || endDate == lastSwapDate) { if (i % interestPeriod == 0) { @@ -663,11 +663,6 @@ namespace YLErp.Modules.SwapModule tdinterest += tdinterest1; } - else if (lastSwapDate >= rateDate) - { - interest = interestProfitSum * closePercent; - tdinterest = interestProfitSum * closePercent; - } } InterestAmount = Math.Round(interest, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero); @@ -1150,8 +1145,8 @@ namespace YLErp.Modules.SwapModule }); } - unwindData.SwapCloseAmount = decimal.Parse(unwindData.SwapCloseAmount.ToString("0.00")); - unwindData.SwapRealizedPnL = unwindData.SwapCloseAmount; + unwindData.SwapCloseAmount = Math.Round(unwindData.SwapCloseAmount, 2, MidpointRounding.AwayFromZero); + unwindData.SwapRealizedPnL = Math.Round(unwindData.SwapRealizedPnL, 2, MidpointRounding.AwayFromZero); } /// /// 多空组合平仓 @@ -1188,7 +1183,7 @@ namespace YLErp.Modules.SwapModule catch (Exception ex) { trans.Rollback(); - throw ex; + throw; } finally { @@ -1214,12 +1209,20 @@ namespace YLErp.Modules.SwapModule { int clientCashId = AddClientCashInCashOut(td, Convert.ToDouble(unwindData.SwapCloseAmount), ClientCashInCashOut.系统操作_互换, unwindData.ValueDate); SaveSwapDeal(unwindData, (int)SwapEventTypeEnum.互换, clientCashId, "系统操作_互换"); + td.UnWindDate = unwindData.UnwindDate; + if (td.ExerciseDate <= unwindData.ValueDate) + { + td.Notional = 0; + td.StockEqvNotional = 0; + td.TradeStatus = "已到期"; + } + DbContext.SaveChanges(); trans.Commit(); } catch (Exception ex) { trans.Rollback(); - throw ex; + throw; } finally { @@ -1267,7 +1270,7 @@ namespace YLErp.Modules.SwapModule catch (Exception ex) { trans.Rollback(); - throw ex; + throw; } finally { @@ -1345,7 +1348,7 @@ namespace YLErp.Modules.SwapModule catch (Exception ex) { trans.Rollback(); - throw ex; + throw; } finally { @@ -1412,10 +1415,20 @@ namespace YLErp.Modules.SwapModule { if (!string.IsNullOrEmpty(position.UnderlyingCode)) { - position.PosiQuantity -= unwindData.CloseQty; - position.PosiNotionalValue = unwindData.PosiNotionalValue - unwindData.CloseNotionalValue; - position.PosiTradingFee -= position.PosiTradingFee * unwindData.ClosePercent; - position.PosiTradingFeePending -= position.PosiTradingFeePending * unwindData.ClosePercent; + // 收益结算(互换)不改变持仓数量和名义本金,只更新费用 + if (eventType == (int)SwapEventTypeEnum.互换) + { + position.PosiTradingFee -= position.PosiTradingFee * unwindData.ClosePercent; + position.PosiTradingFeePending -= position.PosiTradingFeePending * unwindData.ClosePercent; + } + else + { + // 平仓时才扣减持仓 + position.PosiQuantity -= unwindData.CloseQty; + position.PosiNotionalValue -= unwindData.CloseNotionalValue; + position.PosiTradingFee -= position.PosiTradingFee * unwindData.ClosePercent; + position.PosiTradingFeePending -= position.PosiTradingFeePending * unwindData.ClosePercent; + } } else { diff --git a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml index 6e68cac3..e16fd470 100644 --- a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml +++ b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml @@ -940,8 +940,8 @@ @((SwapDirectionEnum)closeFloat.PayDirection) @(closeFloat.PositionType == (int)PositionTypeFlag.Long ? "多头" : "空头") @closeFloat.UnderlyingCode - @(closeFloat.PosiGrossPrice * multiplier).OtcFormat(OtcFormatFlag.umpriceP) - @((closeFloat.TradingAmountNetAvg ?? 0) * multiplier).OtcFormat(OtcFormatFlag.umpriceP) + @((closeFloat.PosiGrossPrice * multiplier).OtcFormat(OtcFormatFlag.umpriceP)) + @(((closeFloat.TradingAmountNetAvg ?? 0) * multiplier).OtcFormat(OtcFormatFlag.umpriceP)) @((closeFloat.TradingAmountAvg * multiplier).OtcFormat(OtcFormatFlag.umpriceP)) @((closeFloat.PositionQty??0).OtcFormat(OtcFormatFlag.StockEqvNotional)) @(closeFloat.TradingFee.OtcFormat(OtcFormatFlag.StockEqvNotional)) diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/incomeSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/incomeSwapTrade.js index d623e349..ed510f43 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/incomeSwapTrade.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/incomeSwapTrade.js @@ -144,10 +144,10 @@ const vue = new Vue({ thisObj.deal.SwapMarginAmount = 0; thisObj.floatPosition.TradingAmount = parseFloat(thisObj.floatPosition.TradingAmountAvg) * parseFloat(thisObj.deal.CloseNotionalValue) * 0.01; thisObj.floatPosition.CloseFee = TradingFee; - if (thisObj.deal.PositionQty == 0) { - thisObj.floatPosition.TradingAmountFeeAvg = 0; - } else { + if (thisObj.deal.CloseQty > 0) { thisObj.floatPosition.TradingAmountFeeAvg = parseFloat(thisObj.floatPosition.TradingAmountAvg) * 0.01 + (TradingFee / thisObj.deal.CloseQty) * floatRatio; + } else { + thisObj.floatPosition.TradingAmountFeeAvg = parseFloat(thisObj.floatPosition.TradingAmountAvg) * 0.01; } this.interestList.forEach(x => { //let interestRatio = x.InterestDirection == 1 ? 1 : -1; diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapLongShort.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapLongShort.js index 920fec79..0cbe805b 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapLongShort.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapLongShort.js @@ -113,7 +113,8 @@ const vue = new Vue({ } let reqObj = _.cloneDeep(thisObj.deal); let marginCloneList = _.cloneDeep(thisObj.marginList); - reqObj.FlowEvents = thisObj.interestList; + + reqObj.FlowEvents = _.cloneDeep(thisObj.interestList); marginCloneList.forEach((item) => { reqObj.FlowEvents.push(item); })