diff --git a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs
index b9079e27..675154f7 100644
--- a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs
+++ b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs
@@ -228,6 +228,16 @@ namespace YLErp.DBModels
[NotMapped]
public decimal BeforeCloseFee { get; set; }
///
+ /// 单位交易费用(仅前端展示,不存库)
+ ///
+ [NotMapped]
+ public decimal PosiTradingFeeUnit { get; set; }
+ ///
+ /// 单位交易费用模式 0=百分比 1=单位数量(仅前端展示,不存库)
+ ///
+ [NotMapped]
+ public int PosiFeeType { get; set; }
+ ///
/// 持仓腿id
///
[DisplayName("持仓腿id")]
diff --git a/Framework/YLErp.Core/DBModels/SwapPosition.cs b/Framework/YLErp.Core/DBModels/SwapPosition.cs
index 44fb89d9..04a306f9 100644
--- a/Framework/YLErp.Core/DBModels/SwapPosition.cs
+++ b/Framework/YLErp.Core/DBModels/SwapPosition.cs
@@ -113,6 +113,11 @@ namespace YLErp.DBModels
[DataChange]
public decimal PosiTradingFeeUnit { get; set; }
///
+ /// 单位交易费用模式 0=百分比 1=单位数量
+ ///
+ [DataChange]
+ public int PosiFeeType { get; set; }
+ ///
/// 起始日
///
[DisplayName("起始日")]
diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs
index 05182f5f..fdde80ea 100644
--- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs
@@ -291,6 +291,11 @@ namespace YLErp.Modules.SwapModule
floatEvent.UnderlyingInstrumentType = position.UnderlyingInstrumentType;
floatEvent.CloseFee = 0;
floatEvent.BeforeCloseFee = oriPosition.PosiTradingFeePending;
+ //自动计算平仓交易费用
+ floatEvent.TradingFee = CalcInitTradingFee(oriPosition, unwindData);
+ //向前端传递单位交易费用和模式标记(NotMapped,不存库)
+ floatEvent.PosiTradingFeeUnit = oriPosition.PosiTradingFeeUnit;
+ floatEvent.PosiFeeType = oriPosition.PosiFeeType;
floatEvent.MarkClosePnl = 0;
floatEvent.PayDirection = position.PosiDirection;
floatEvent.PosiGrossPrice = position.PosiGrossPrice;
@@ -314,6 +319,22 @@ namespace YLErp.Modules.SwapModule
return unwindData;
}
///
+ /// 计算初始平仓交易费用
+ ///
+ private decimal CalcInitTradingFee(swap_position oriPosition, UnwindData unwindData)
+ {
+ if (oriPosition.PosiFeeType == 0)
+ {
+ //百分比模式:费率%/100 × 平仓名义本金
+ return Math.Round(oriPosition.PosiTradingFeeUnit / 100m * (decimal)unwindData.CloseNotionalValue, 2, MidpointRounding.AwayFromZero);
+ }
+ else
+ {
+ //单位数量模式:单位费率 × 平仓数量
+ return Math.Round(oriPosition.PosiTradingFeeUnit * (decimal)unwindData.CloseQty, 2, MidpointRounding.AwayFromZero);
+ }
+ }
+ ///
/// 校验上日是否收盘
///
///
diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeService.cs
index ca343cbc..f32f97fe 100644
--- a/YLErpDAL/Modules/SwapModule/SwapTradeService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapTradeService.cs
@@ -1375,6 +1375,7 @@ namespace YLErp.Modules.SwapModule
position.PosiTradingFee = swap.PosiTradingFee;
position.PosiTradingFee=Math.Round(position.PosiTradingFee, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
position.PosiTradingFeeUnit = swap.PosiTradingFeeUnit;
+ position.PosiFeeType = swap.PosiFeeType;
position.PosiTradingFeePending = swap.PosiTradingFeePending;
position.PosiTradingFeePending = Math.Round(position.PosiTradingFeePending, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
position.UnderlyingCode = swap.UnderlyingCode;
diff --git a/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml b/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml
index 6409fe53..9c2a9196 100644
--- a/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml
+++ b/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml
@@ -450,6 +450,7 @@
期初标的成交收益率% |
期初标的价格 |
数量 |
+ 基础费率 |
交易费用后付 |
@@ -487,6 +488,16 @@
|
{{item.underlying!=null?item.underlying.QuoteUnitString:''}}
|
+
+
+
+ %
+
+
+
+ ¥
+
+ |
我方{{item.PosiDirection==1?"支付":"收取"}}交易费用
diff --git a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml
index 9172e401..ed573429 100644
--- a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml
+++ b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml
@@ -349,7 +349,7 @@
|
@item.interest_rest_days |
@((item.interest_rule != null) ? (SwapInterestRule)item.interest_rule : "") |
- @(string.IsNullOrEmpty(item.category_tag) ? "互换利率" : item.category_tag) |
+ 互换利率 |
|
@@ -384,6 +384,7 @@
@initYtmTitle |
}
数量 |
+ 基础费率 |
交易费用后付 |
@foreach (var item in paySwapPositions)
@@ -409,6 +410,16 @@
@item.PosiQuantity.OtcFormat(OtcFormatFlag.StockEqvNotional)
|
+
+ @if (item.PosiFeeType == 0)
+ {
+ @(item.PosiTradingFeeUnit.ToString("0.0000") + "%")
+ }
+ else
+ {
+ @item.PosiTradingFeeUnit.OtcFormat(OtcFormatFlag.StockEqvNotional)
+ }
+ |
@item.PosiTradingFeePending.OtcFormat(OtcFormatFlag.StockEqvNotional)
|
@@ -552,7 +563,7 @@
@(item.InterestType == 0 ? "单利" : "复利") |
@item.interest_rest_days |
@((item.interest_rule != null) ? (SwapInterestRule)item.interest_rule : "") |
- @(string.IsNullOrEmpty(item.category_tag) ? "互换利率" : item.category_tag) |
+ 互换利率 |
|
}
diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js
index fa6b7011..70a91ff2 100644
--- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js
+++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js
@@ -12,6 +12,8 @@ const inputFormatTradeAmount = Object.freeze({ precision: otcformat.trading.noti
const inputFormatSwapRate = Object.freeze({ precision: otcformat.trading.premiumRateP.precision, negative: true, append: '%' });
const inputFormatTradePrice = Object.freeze({ precision: otcformat.trading.tradePrice.precision, negative: true, append: '' });
const inputFormatTradeSinglePrice = Object.freeze({ precision: otcformat.trading.tradeSinglePrice.precision, negative: true, append: '', percent: false });
+const inputFormatPosiFeePercent = Object.freeze({ precision: 4, negative: true, append: '' });//单位交易费用-百分比模式(精度4)
+const inputFormatPosiFeeUnit = Object.freeze({ precision: 2, negative: true, append: '' });//单位交易费用-单位数量模式(精度2)
const inputFormatMarginRate = Object.freeze({ precision: otcformat.trading.marginRateP.precision, append: '%' });
const inputFormatSwapDeliveryPrice = Object.freeze({ precision: 9, negative: true, append: '', percent: false });
const inputFormatSwapBondDeliveryPrice = Object.freeze({ precision: 9, negative: true, append: '', percent: true });
@@ -153,6 +155,7 @@ const vue = new Vue({
currencys: page.currencys,
getNotionalSingleFee: 0,
isSingleFee: page.Trade.trade_extend.ExtendObj.OpenFeeType == 0,
+ posiFeeModePercent: true,//单位交易费用模式: true=百分比模式, false=单位数量模式
observation: {//互换观察日
ObservationInterval: "",
IntervalList: [],
@@ -507,28 +510,50 @@ const vue = new Vue({
}
},
- //变更单位交易费用
+ //变更单位交易费用(正算:单位交易费用→交易费用后付)
changeTradingFeeUnit(item) {
- //计算交易费用
- //if (this.trade.trade_extend.ExtendObj.OpenFeeType == 0) {//按手数收费
- // item.PosiTradingFee = item.ContractSize == 0 ? 0 : otcformat.trading.tradeSinglePrice(item.PosiQuantity * item.PosiTradingFeeUnit / item.ContractSize);
- //} else {
- // item.PosiTradingFee = otcformat.trading.tradeSinglePrice(item.PosiQuantity * item.PosiTradingFeeUnit);
- //}
-
+ if (this.posiFeeModePercent) {
+ //百分比模式: 交易费用后付 = round(费率%/100 × 名义本金, 2)
+ var stockEqvNotional = Number(this.trade.StockEqvNotional) || 0;
+ item.PosiTradingFeePending = stockEqvNotional == 0 ? 0 : otcformat.trading.tradeSinglePrice(Number(item.PosiTradingFeeUnit) / 100 * stockEqvNotional);
+ } else {
+ //单位数量模式: 交易费用后付 = round(单位费率 × 数量, 2)
+ var quantity = Number(item.PosiQuantity) || 0;
+ item.PosiTradingFeePending = otcformat.trading.tradeSinglePrice(Number(item.PosiTradingFeeUnit) * quantity);
+ }
},
- //变更交易费用
+ //变更交易费用(反算:交易费用后付→单位交易费用)
changeTradingFee(item) {
- //计算单位交易费用
- //if (item.PosiQuantity == 0) {
- // item.PosiTradingFeeUnit = 0;
- // return
- //}
- //if (this.trade.trade_extend.ExtendObj.OpenFeeType == 0) {//按手数收费
- // item.PosiTradingFeeUnit = item.ContractSize == 0 ? 0 : otcformat.trading.tradeSinglePrice(item.PosiTradingFee * item.ContractSize / item.PosiQuantity);
- //} else {
- // item.PosiTradingFeeUnit = otcformat.trading.tradeSinglePrice(item.PosiTradingFee / item.PosiQuantity);
- //}
+ if (item.PosiQuantity == 0) {
+ item.PosiTradingFeeUnit = 0;
+ return;
+ }
+ if (this.posiFeeModePercent) {
+ //百分比模式反算: 单位交易费用 = round(交易费用后付 / 名义本金 × 100, 4)
+ var stockEqvNotional = Number(this.trade.StockEqvNotional) || 0;
+ item.PosiTradingFeeUnit = stockEqvNotional == 0 ? 0 : _.round(Number(item.PosiTradingFeePending) / stockEqvNotional * 100, 4);
+ } else {
+ //单位数量模式反算: 单位交易费用 = round(交易费用后付 / 数量, 2)
+ item.PosiTradingFeeUnit = _.round(Number(item.PosiTradingFeePending) / Number(item.PosiQuantity), 2);
+ }
+ },
+ //切换到单位数量模式
+ showPayAbsPrice() {
+ this.posiFeeModePercent = false;
+ this.paySwapList.forEach(item => {
+ item.PosiFeeType = 1;
+ item.PosiTradingFeeUnit = 0;
+ item.PosiTradingFeePending = 0;
+ });
+ },
+ //切换到百分比模式
+ showPayPercentPrice() {
+ this.posiFeeModePercent = true;
+ this.paySwapList.forEach(item => {
+ item.PosiFeeType = 0;
+ item.PosiTradingFeeUnit = 0;
+ item.PosiTradingFeePending = 0;
+ });
},
savetrade() {
if (!this.checkSubmitData()) {
@@ -618,6 +643,7 @@ const vue = new Vue({
x.PosiGrossPrice = thisObj.roundStorageDeliveryPrice(x, x.PosiGrossPrice);
x.PosiNetNoFeePrice = thisObj.roundStorageBondNetPriceAndYtm(x.PosiNetNoFeePrice);
x.InitYtm = x.InitYtm == null ? null : thisObj.roundStorageBondNetPriceAndYtm(x.InitYtm);
+ x.PosiFeeType = x.PosiFeeType ?? (this.posiFeeModePercent ? 0 : 1);
thisObj.trade.swap_positions.push(x);
});
} else {
@@ -1576,6 +1602,7 @@ const vue = new Vue({
PosiTradingFee: 0,//交易费用
PosiTradingFeePending: 0,//交易费用后付
PosiTradingFeeUnit: 0,//单位交易费用
+ PosiFeeType: 0,//单位交易费用模式 0=百分比 1=单位数量
InterestDirection: 0,//利息收支方式
InterestRateDefault: 0,//计息利率
InterestMode: 0,//计息基本类型
diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js
index 3838b7ea..3204b525 100644
--- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js
+++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js
@@ -60,9 +60,12 @@ const vue = new Vue({
this.ratio = this.floatPosition.PayDirection == 1 ? -1 : 1;
this.shortRatio = this.floatPosition.PositionType == 1 ? 1 : -1;
this.TradeStartDate = model.TradeStartDate;
- // 最多可平比例(占期初口径) = 剩余名义本金 / 期初名义本金;分母为 0 时兜底为 1
- this.oriClosePercent = (this.deal.NotionalValue && this.deal.PosiNotionalValue)
- ? this.deal.PosiNotionalValue / this.deal.NotionalValue : 1;
+ // 多次部分平仓后 ClosePercent 语义为"占剩余持仓比例"。
+ // 仅当"全部平仓"(CloseMethod==1) 时修正旧口径(model.ClosePercent 可能=剩余/原始<1)为 1;
+ // "部分平仓"(CloseMethod==2) 时保留已提交比例(平仓待复核场景),避免覆盖用户已提交的 closePercent
+ if (this.deal.CloseMethod === 1) {
+ this.deal.ClosePercent = 1;
+ }
// 转换期末标的价格为百分比形式
if (this.floatPosition.TradingAmountAvg) {
this.floatPosition.TradingAmountAvg = this.floatPosition.TradingAmountAvg * this.multiplier;
@@ -136,39 +139,46 @@ const vue = new Vue({
this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.PosiNotionalValue));
this.deal.CloseQty = this.deal.PositionQty;
} else {
- // ClosePercent 是占期初口径(A),需除以 oriClosePercent 转占剩余(B) 再乘剩余数量
- this.deal.CloseQty = this.calcCloseQtyByPercent(this.deal.ClosePercent);
+ this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent));
}
this.calcTradingFeePending();
+ this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
- // 按"占期初口径(A)"的 ClosePercent 反算平仓数量:CloseQty = PositionQty × (ClosePercent / oriClosePercent)
- // 多次部分平仓后必须这样转换,否则全部↔部分切换时 ClosePercent 没变但 CloseQty 会变(不自洽)
- // 使用 swapCalc.calcCloseQtyByOriginalPercent 的 roundHalfAwayFromZero 避免 JS 浮点精度偏差
- // (如 32500000*(0.5/0.65)=24999999.999999996 而非 25000000)
- calcCloseQtyByPercent(closePercent) {
- return SwapCalc.calcCloseQtyByOriginalPercent(closePercent, this.oriClosePercent, this.deal.PositionQty);
- },
calcTradingFeePending() {
this.floatPosition.TradingFeePending = this.floatPosition.BeforeCloseFee * parseFloat(this.deal.ClosePercent);
},
+ //自动计算平仓交易费用(根据单位交易费用 + 模式)
+ calcTradingFee() {
+ var unit = parseFloat(this.floatPosition.PosiTradingFeeUnit) || 0;
+ var type = parseInt(this.floatPosition.PosiFeeType) || 0;
+ if (type === 0) {
+ //百分比模式:费率%/100 × 平仓名义本金
+ this.floatPosition.TradingFee = _.round(unit / 100 * parseFloat(this.deal.CloseNotionalValue), 2);
+ } else {
+ //单位数量模式:单位费率 × 平仓数量
+ this.floatPosition.TradingFee = _.round(unit * parseFloat(this.deal.CloseQty), 2);
+ }
+ //用格式化函数确保显示一致
+ this.floatPosition.TradingFee = otcformat.trading.StockEqvNotional(this.floatPosition.TradingFee);
+ this.calcFloatClosePnl();
+ },
changeCloseQty() {//修改平仓数量
if (parseFloat(this.deal.CloseQty) > parseFloat(this.deal.PositionQty)) {
main.message("平仓数量不能超过持仓数量");
return;
}
- // CloseQty/PositionQty 得占剩余(B),× oriClosePercent 转回占期初(A)
- var ori = parseFloat(this.oriClosePercent) || 0;
- this.deal.ClosePercent = otcformat.fixed6((parseFloat(this.deal.CloseQty) / parseFloat(this.deal.PositionQty)) * ori);
+ this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseQty) / parseFloat(this.deal.PositionQty));
if (parseFloat(this.deal.CloseQty) == parseFloat(this.deal.PositionQty)) {
this.deal.CloseMethod = 1;
} else {
this.deal.CloseMethod = 2;
}
- // 占期初口径:平仓名义本金 = 平仓比例 × 期初名义本金(NotionalValue)
- this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.NotionalValue));
+ // 多次部分平仓后 PosiNotionalValue 才是剩余本金,不能用原始 NotionalValue,否则平仓名义本金偏大
+ this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.PosiNotionalValue));
this.calcTradingFeePending();
+ this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
@@ -178,15 +188,16 @@ const vue = new Vue({
this.deal.ClosePercent = this.oriClosePercent;
return;
}
- this.deal.CloseQty = this.calcCloseQtyByPercent(this.deal.ClosePercent);
- // 占期初口径:平仓名义本金 = 平仓比例 × 期初名义本金(NotionalValue)
- this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.NotionalValue));
- if (parseFloat(this.deal.ClosePercent) == parseFloat(this.oriClosePercent)) {
- this.deal.CloseMethod = 1;
+ this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent));
+ // 多次部分平仓后 PosiNotionalValue 才是剩余本金,不能用原始 NotionalValue,否则平仓名义本金偏大
+ this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.PosiNotionalValue));
+ if (parseFloat(this.deal.CloseNotionalValue) == parseFloat(this.deal.PosiNotionalValue)) {
+ this.floatPosition.CloseMethod = 1;
} else {
- this.deal.CloseMethod = 2;
+ this.floatPosition.CloseMethod = 2;
}
this.calcTradingFeePending();
+ this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
@@ -196,15 +207,11 @@ const vue = new Vue({
this.deal.CloseNotionalValue = this.deal.PosiNotionalValue;
return;
}
- // 占期初口径:平仓比例 = 平仓名义本金 / 期初名义本金(NotionalValue)
- this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseNotionalValue) / parseFloat(this.deal.NotionalValue));
- this.deal.CloseQty = this.calcCloseQtyByPercent(this.deal.ClosePercent);
- if (parseFloat(this.deal.ClosePercent) == parseFloat(this.oriClosePercent)) {
- this.deal.CloseMethod = 1;
- } else {
- this.deal.CloseMethod = 2;
- }
+ // 多次部分平仓后应以 PosiNotionalValue(剩余) 为分母,否则 ClosePercent 偏小,导致后端预付金返还本金计算错误
+ this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseNotionalValue) / parseFloat(this.deal.PosiNotionalValue));
+ this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent));
this.calcTradingFeePending();
+ this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
@@ -289,8 +296,7 @@ const vue = new Vue({
},
getInterestList() {//根据平仓日期获取利息腿信息
var thisObj = this;
- // closePercent 按"占期初(original)"语义(A)传给后端,由 GetUnwindInterestList 转为"占剩余(B)"计算
- var postData = { valueDate: thisObj.deal.ValueDate, unwindDate: thisObj.deal.UnwindDate, tradeId: thisObj.deal.SwapTradeId, closePercent: thisObj.deal.ClosePercent, eventType: 2, notionalValue: thisObj.deal.NotionalValue, posiNotionalValue: thisObj.deal.PosiNotionalValue }
+ var postData = { valueDate: thisObj.deal.ValueDate, unwindDate: thisObj.deal.UnwindDate, tradeId: thisObj.deal.SwapTradeId, closePercent: thisObj.deal.ClosePercent, eventType: 2 }
main.post("/swaptrade2/GetUnwindInterestList", postData, { async: true }).done(function (resp) {
thisObj.interestList = resp.obj.filter((item) => {
return item.InterestMode == 1 || item.InterestMode == 2 || item.InterestMode == 7 || item.InterestMode == 8 || item.InterestMode == 9;