Revert "feat(swap): 新增基础费率字段,支持百分比/单位数量模式切换及自动计算"

This reverts commit c9071a4eff.
This commit is contained in:
tengyufan
2026-07-27 09:45:41 +08:00
parent c9071a4eff
commit a575de7bbe
8 changed files with 54 additions and 146 deletions
@@ -228,16 +228,6 @@ namespace YLErp.DBModels
[NotMapped]
public decimal BeforeCloseFee { get; set; }
/// <summary>
/// 单位交易费用(仅前端展示,不存库)
/// </summary>
[NotMapped]
public decimal PosiTradingFeeUnit { get; set; }
/// <summary>
/// 单位交易费用模式 0=百分比 1=单位数量(仅前端展示,不存库)
/// </summary>
[NotMapped]
public int PosiFeeType { get; set; }
/// <summary>
/// 持仓腿id
/// </summary>
[DisplayName("持仓腿id")]
@@ -113,11 +113,6 @@ namespace YLErp.DBModels
[DataChange]
public decimal PosiTradingFeeUnit { get; set; }
/// <summary>
/// 单位交易费用模式 0=百分比 1=单位数量
/// </summary>
[DataChange]
public int PosiFeeType { get; set; }
/// <summary>
/// 起始日
/// </summary>
[DisplayName("起始日")]
@@ -291,11 +291,6 @@ 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;
@@ -319,22 +314,6 @@ namespace YLErp.Modules.SwapModule
return unwindData;
}
/// <summary>
/// 计算初始平仓交易费用
/// </summary>
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);
}
}
/// <summary>
/// 校验上日是否收盘
/// </summary>
/// <param name="tradeId"></param>
@@ -1375,7 +1375,6 @@ 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;
@@ -450,7 +450,6 @@
<th v-if="trade.StructureType!='普通收益互换'">期初标的成交收益率%</th>
<th v-if="trade.StructureType=='普通收益互换'">期初标的价格</th>
<th>数量</th>
<th>基础费率</th>
<th>交易费用后付</th>
</tr>
<tr class="swapflowtr" v-for="item in paySwapList">
@@ -488,16 +487,6 @@
<td>
<vue-number-input v-model="item.PosiQuantity" v-on:input="changeQuantity(item)" v-bind:format="inputFormatTradeAmount"></vue-number-input>{{item.underlying!=null?item.underlying.QuoteUnitString:''}}
</td>
<td>
<template v-if="posiFeeModePercent">
<vue-number-input v-model="item.PosiTradingFeeUnit" v-on:input="changeTradingFeeUnit(item)" v-bind:format="inputFormatPosiFeePercent"></vue-number-input>
<a href="javascript:;" title="点击后切换成绝对值权利金" v-on:click="showPayAbsPrice" class="yt-input-group-append" tabindex="-1">%</a>
</template>
<template v-else>
<vue-number-input v-model="item.PosiTradingFeeUnit" v-on:input="changeTradingFeeUnit(item)" v-bind:format="inputFormatPosiFeeUnit"></vue-number-input>
<a href="javascript:;" title="点击后切换成标的价格百分比" v-on:click="showPayPercentPrice" class="yt-input-group-append" tabindex="-1">¥</a>
</template>
</td>
<td>
<vue-number-input v-model="item.PosiTradingFeePending" v-on:input="changeTradingFee(item)" v-bind:format="inputFormatTradeSinglePrice"></vue-number-input>
<div class="bubble-box">我方{{item.PosiDirection==1?"支付":"收取"}}交易费用</div>
+2 -13
View File
@@ -349,7 +349,7 @@
</td>
<td>@item.interest_rest_days</td>
<td>@((item.interest_rule != null) ? (SwapInterestRule)item.interest_rule : "")</td>
<td>互换利率</td>
<td>@(string.IsNullOrEmpty(item.category_tag) ? "互换利率" : item.category_tag)</td>
<td>
<button class="btn btn-sm btn-outline-danger" type="button" onclick="showSwapRate('@(item.InterestSwapInterval)', false)" style="height:22px;">查看</button>
</td>
@@ -384,7 +384,6 @@
<td>@initYtmTitle</td>
}
<td>数量</td>
<td>基础费率</td>
<td>交易费用后付</td>
</tr>
@foreach (var item in paySwapPositions)
@@ -410,16 +409,6 @@
<td>
@item.PosiQuantity.OtcFormat(OtcFormatFlag.StockEqvNotional)
</td>
<td>
@if (item.PosiFeeType == 0)
{
@(item.PosiTradingFeeUnit.ToString("0.0000") + "%")
}
else
{
@item.PosiTradingFeeUnit.OtcFormat(OtcFormatFlag.StockEqvNotional)
}
</td>
<td>
@item.PosiTradingFeePending.OtcFormat(OtcFormatFlag.StockEqvNotional)
</td>
@@ -563,7 +552,7 @@
<td>@(item.InterestType == 0 ? "单利" : "复利")</td>
<td>@item.interest_rest_days</td>
<td>@((item.interest_rule != null) ? (SwapInterestRule)item.interest_rule : "")</td>
<td>互换利率</td>
<td>@(string.IsNullOrEmpty(item.category_tag) ? "互换利率" : item.category_tag)</td>
<td><button class="btn btn-sm btn-outline-danger" type="button" onclick="showSwapRate('@(item.InterestSwapInterval)')" style="height:22px;">查看</button></td>
</tr>
}
@@ -12,8 +12,6 @@ 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 });
@@ -155,7 +153,6 @@ const vue = new Vue({
currencys: page.currencys,
getNotionalSingleFee: 0,
isSingleFee: page.Trade.trade_extend.ExtendObj.OpenFeeType == 0,
posiFeeModePercent: true,//单位交易费用模式: true=百分比模式, false=单位数量模式
observation: {//互换观察日
ObservationInterval: "",
IntervalList: [],
@@ -510,50 +507,28 @@ const vue = new Vue({
}
},
//变更单位交易费用(正算:单位交易费用→交易费用后付)
//变更单位交易费用
changeTradingFeeUnit(item) {
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);
}
//计算交易费用
//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);
//}
},
//变更交易费用(反算:交易费用后付→单位交易费用)
//变更交易费用
changeTradingFee(item) {
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;
});
//计算单位交易费用
//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);
//}
},
savetrade() {
if (!this.checkSubmitData()) {
@@ -643,7 +618,6 @@ 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 {
@@ -1602,7 +1576,6 @@ const vue = new Vue({
PosiTradingFee: 0,//交易费用
PosiTradingFeePending: 0,//交易费用后付
PosiTradingFeeUnit: 0,//单位交易费用
PosiFeeType: 0,//单位交易费用模式 0=百分比 1=单位数量
InterestDirection: 0,//利息收支方式
InterestRateDefault: 0,//计息利率
InterestMode: 0,//计息基本类型
@@ -60,12 +60,9 @@ const vue = new Vue({
this.ratio = this.floatPosition.PayDirection == 1 ? -1 : 1;
this.shortRatio = this.floatPosition.PositionType == 1 ? 1 : -1;
this.TradeStartDate = model.TradeStartDate;
// 多次部分平仓后 ClosePercent 语义为"占剩余持仓比例"。
// 仅当"全部平仓"(CloseMethod==1) 时修正旧口径(model.ClosePercent 可能=剩余/原始<1)为 1
// "部分平仓"(CloseMethod==2) 时保留已提交比例(平仓待复核场景),避免覆盖用户已提交的 closePercent
if (this.deal.CloseMethod === 1) {
this.deal.ClosePercent = 1;
}
// 最多可平比例(占期初口径) = 剩余名义本金 / 期初名义本金;分母为 0 时兜底为 1
this.oriClosePercent = (this.deal.NotionalValue && this.deal.PosiNotionalValue)
? this.deal.PosiNotionalValue / this.deal.NotionalValue : 1;
// 转换期末标的价格为百分比形式
if (this.floatPosition.TradingAmountAvg) {
this.floatPosition.TradingAmountAvg = this.floatPosition.TradingAmountAvg * this.multiplier;
@@ -139,46 +136,39 @@ const vue = new Vue({
this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.PosiNotionalValue));
this.deal.CloseQty = this.deal.PositionQty;
} else {
this.deal.CloseQty = otcformat.trading.notional(parseFloat(this.deal.PositionQty) * parseFloat(this.deal.ClosePercent));
// ClosePercent 是占期初口径(A),需除以 oriClosePercent 转占剩余(B) 再乘剩余数量
this.deal.CloseQty = this.calcCloseQtyByPercent(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;
}
this.deal.ClosePercent = otcformat.fixed6(parseFloat(this.deal.CloseQty) / parseFloat(this.deal.PositionQty));
// 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);
if (parseFloat(this.deal.CloseQty) == parseFloat(this.deal.PositionQty)) {
this.deal.CloseMethod = 1;
} else {
this.deal.CloseMethod = 2;
}
// 多次部分平仓后 PosiNotionalValue 才是剩余本金,不能用原始 NotionalValue,否则平仓名义本金偏大
this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.PosiNotionalValue));
// 占期初口径:平仓名义本金 = 平仓比例 × 期初名义本金(NotionalValue)
this.deal.CloseNotionalValue = otcformat.trading.StockEqvNotional(parseFloat(this.deal.ClosePercent) * parseFloat(this.deal.NotionalValue));
this.calcTradingFeePending();
this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
@@ -188,16 +178,15 @@ const vue = new Vue({
this.deal.ClosePercent = this.oriClosePercent;
return;
}
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;
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;
} else {
this.floatPosition.CloseMethod = 2;
this.deal.CloseMethod = 2;
}
this.calcTradingFeePending();
this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
@@ -207,11 +196,15 @@ const vue = new Vue({
this.deal.CloseNotionalValue = this.deal.PosiNotionalValue;
return;
}
// 多次部分平仓后应以 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));
// 占期初口径:平仓比例 = 平仓名义本金 / 期初名义本金(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;
}
this.calcTradingFeePending();
this.calcTradingFee();
this.getInterestList();
this.calcFloatClosePnl();
},
@@ -296,7 +289,8 @@ const vue = new Vue({
},
getInterestList() {//根据平仓日期获取利息腿信息
var thisObj = this;
var postData = { valueDate: thisObj.deal.ValueDate, unwindDate: thisObj.deal.UnwindDate, tradeId: thisObj.deal.SwapTradeId, closePercent: thisObj.deal.ClosePercent, eventType: 2 }
// 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 }
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;