//otcformat禁止千分位分组
window.otcformat.options.disableGrouping = true;
var vue = new Vue({
el: "#vueDiv",
data: {
tradeCash: model,
tradeForward: otcTradeForward,
variety: variety,
singleOptionValueResult: null,
UnwindFee: 0,
ForwardProfit: 0,
AmountCheck: 0,
UnwindPriceCheck: 0,
tradeDate: tradeDate,
exerciseDate: exerciseDate
},
mounted: function () {
},
watch: {
'tradeCash.UnwindPrice': function (val) {
var valueArray = String(val).split(".");
if (valueArray.length > 1 && valueArray[1].length > 2) {
this.tradeCash.UnwindPrice = otcformat.trading.tradePrice(val);
}
},
'tradeCash.UnwindType': function () {
var thisObj = this;
if (thisObj.tradeCash.UnwindType === "全部平仓") {
thisObj.tradeCash.UnwindTradeAmount = this.tradeCash.TradeAmount;
thisObj.changeUnwindTradeAmount();
}
}
},
methods: {
setUnwindDate: function (e) {
this.tradeCash.ValueDate = e;
this.refreshUnderlyingPrice();
},
changeUnderlyingPrice: function () {
this.tradeCash.FinalPriceType = "User";
this.computeForwardProfit();
},
refreshUnderlyingPrice: function () {
var thisObj = this;
main.post("/underlying_manager/TryGetTradeForwardFinalPrice",
{ tradeId: thisObj.tradeCash.TradeId, underlyingId: thisObj.tradeCash.UnderlyingId, voltype: "交易", tradeDate: thisObj.tradeCash.ValueDate })
.done(function (res) {
thisObj.tradeCash.FinalPrice = otcformat.trading.umprice(res.obj.Price);
thisObj.tradeCash.FinalPriceType = "System";
thisObj.computeForwardProfit();
if (res.message && res.message != "") {
main.message(res.message);
}
});
},
changeUnwindTradeAmount: function () {
if (parseFloat(this.tradeCash.UnwindTradeAmount) > parseFloat(this.tradeCash.TradeAmount)) {
main.message("平仓数量不能超过持仓数量");
this.tradeCash.UnwindTradeAmount = "";
}
this.computeForwardProfit();
this.computeExtraAmount();
},
//计算预付金成本
computeExtraAmount: function () {
var thisObj = this;
var unwindAmount = thisObj.tradeCash.UnwindTradeAmount;
var holidayMarginTotal = unwindAmount * holidayMargin;
var lastMargin = (lastMarginRecord.MarginSum - lastMarginRecord.CloseMarginSum) * ((unwindAmount) / lastMarginRecord.Notional) + lastMarginRecord.CloseMarginSum;
thisObj.tradeCash.ExtraAmount = otcformat.trading.notional(lastMargin + holidayMarginTotal, 2);
},
//计算平仓总费用
//平仓的总费用 =远期收益+每手平仓费用×平仓手数+补充远期价值×平仓比例+预付金成本
computeUnwindTotalFee: function () {
var thisObj = this;
var tradeCash = thisObj.tradeCash;
var tradeForward = this.tradeForward;
if (g_isReCheckConfirm && !g_isUseApproval) {
tradeCash.UnwindPrice = thisObj.UnwindPriceCheck;
}
thisObj.computeExtraAmount();
var unwindRatio = tradeCash.UnwindTradeAmount / tradeCash.TradeOriginalAmount;
var unwindPrice = parseFloat(tradeCash.UnwindPrice == "" ? 0 : tradeCash.UnwindPrice) * tradeForward.Lots * unwindRatio;
var supplyPrice = tradeForward.MetaDic["IsSupplyForwardValue"] == "1" ? tradeForward.ForwardValue : tradeForward.MetaDic["IsSupplyForwardValue"] == "-1" ? -tradeForward.ForwardValue : 0;
var unwindTotalFee = Number(thisObj.ForwardProfit) + unwindPrice - (supplyPrice * unwindRatio) + Number(thisObj.tradeCash.ExtraAmount);
thisObj.UnwindFee = otcformat.trading.tradePrice(unwindTotalFee);
thisObj.AmountCheck = thisObj.UnwindFee;
},
//计算平仓费用
//平仓费用 = (补充远期价值* 平仓比例)- 平仓远期价值 )/ (平仓比例 *手数)
computeUnwindPrice: function () {
var thisObj = this;
var tradeCash = thisObj.tradeCash;
var tradeForward = this.tradeForward;
thisObj.computeExtraAmount();
thisObj.computeForwardPrice();
//复核页面 平仓总费用
if (g_isReCheckConfirm) {
thisObj.UnwindFee = thisObj.AmountCheck;
}
var unwindRatio = tradeCash.UnwindTradeAmount / tradeCash.TradeOriginalAmount;
var supplyPrice = tradeForward.MetaDic["IsSupplyForwardValue"] == "1" ? tradeForward.ForwardValue : tradeForward.MetaDic["IsSupplyForwardValue"] == "-1" ? -tradeForward.ForwardValue : 0;
var unwindPrice = (parseFloat(thisObj.UnwindFee) + (supplyPrice * unwindRatio) - Number(thisObj.ForwardProfit)) / (unwindRatio * tradeForward.Lots);
thisObj.tradeCash.UnwindPrice = otcformat.trading.tradePrice(unwindPrice);
thisObj.UnwindPriceCheck = thisObj.tradeCash.UnwindPrice;
},
//计算远期价值
//(交割价格-平仓价格)*成交数量 * CountRatio*(多-1,空1)*(买入1,卖出-1)
//这里的交易方向为开仓时的交易方向
computeForwardPrice: function () {
var thisObj = this;
var tradeForward = this.tradeForward;
thisObj.tradeCash.FinalPrice = otcformat.trading.umprice(thisObj.tradeCash.FinalPrice);
var strikePrice = parseFloat(thisObj.tradeCash.Strike);
var underlringPrice = parseFloat(thisObj.tradeCash.FinalPrice);
var tradeAmount = parseFloat(thisObj.tradeCash.UnwindTradeAmount);
thisObj.ForwardProfit = otcformat.trading.umprice((strikePrice - underlringPrice) * tradeAmount * thisObj.variety.CountRatio * (thisObj.tradeCash.CallPutDesc == "看涨" ? -1 : 1) * (tradeForward.BuySell == "买入" ? 1 : -1));
},
computeForwardProfit: function () {
var thisObj = this;
thisObj.computeForwardPrice();
if (!g_isUseApproval) {
thisObj.computeUnwindTotalFee();
} else {
this.UnwindFee = this.tradeCash.Amount;
}
},
getSumbitText: function () {
return g_isShowReCheckClose ? "平仓审核提交" : "平仓";
},
previewTradeAbstract: function (tradeCash, trade) {
var textContent = "";
var htmlContent = "";
var thisObj = this;
var rowData = [
{
name: "交易编号",
value: trade.TradeNumber,
func: function (colVal, rowModel) {
return main.isEmpty(rowModel.TradeNumber) ? "" : colVal;
}
},
{
name: "开仓日期",
value: trade.TradeDate,
func: function (colVal) {
return colVal.substring(0, 10);
}
},
{
name: "开仓方向",
value: this.getValidVal(trade.ClientName)
+ "
                "
+ (this.getValidVal(trade.BuySell) === "买入" ? " 卖出" : " 买入")
}, {
name: "结构类型",
value: this.getValidVal(trade.ExerciseModeCn) +
this.getValidVal(trade.TradeType).replace("期权", "") +
this.getValidVal(trade.OptionType) +
"期权",
func: function (colVal, rowModel) {
if (rowModel.TradeType == "远期") {
return trade.TradeType + (trade.OptionType == "看涨" ? "多头" : "空头");
}
return colVal;
}
}, {
name: "标的代码",
value: trade.UnderlyingCode,
func: function (colVal, rowModel) {
if (rowModel.TradeType == "合成价差期权") {
return rowModel.SyntheticUnderlyingTipsInfo;
}
return colVal;
}
}, {
name: "执行价格",
value: this.getValidVal(trade.Strike, 0),
func: function (colVal, rowModel) {
if (rowModel.IsMoneynessOption == "是") {
return otcformat.trading.premiumRateP(colVal);
}
return otcformat.trading.tradePrice(colVal);
}
}, {
name: "到期日期",
value: trade.ExerciseDate,
func: function (colVal) {
return colVal.substring(0, 10);
}
}, {
name: "平仓日期",
value: tradeCash.ValueDate
}, {
name: "标的价格",
value: main.toNumberExcludingNaN(trade.SpotPrice),
func: function (colVal, rowModel) {
if (rowModel.UnderlyingInstrumentType == "CommodityFutures") {
return colVal + "(开仓)"
+ "
                "
+ otcformat.trading.umprice(tradeCash.FinalPrice) + "(平仓)";
}
return otcformat.trading.umprice(trade.InitialSpotPrice) + "(开仓)"
+ "
                "
+ otcformat.trading.umprice(tradeCash.FinalPrice) + "(平仓)";
}
}, {
name: "平仓数量",
value: trade.UnderlyingInstrumentType == "Stock"
? tradeCash.UnwindNotional + " 股"
: tradeCash.UnwindTradeAmount + " " + this.getValidVal(trade.QuoteUnitSingle)
}, {
name: "平仓总额",
value: otcformat.trading.tradePrice(thisObj.UnwindFee * (-1), 3) + " 元" //客户角度,故为相反金额
}, {
name: "实现盈亏",
value: otcformat.trading.tradePrice((trade.BuySell === "卖出" ? 1 : -1) * (tradeCash.Amount - tradeCash.UnwindNotional * trade.TradeSinglePrice)) + " 元",
func: function (colVal, rowModel) {
var notional = (tradeCash.UnwindNotional);
var amount = thisObj.UnwindFee;
return otcformat.trading.tradePrice((-1) * amount - (trade.BuySell === "卖出" ? 1 : -1) * (trade.TradePrice) * (notional / trade.OriginalNotional)) + " 元";
}
}
];
textContent += this.getRowText(rowData, trade, '{0}:{1}\r\n') + "\r\n\r\n";
htmlContent += this.getRowText(rowData, trade, '{0}:{1}
') + "
";
layer.open({
type: 1,
title: "平仓摘要",
shadeClose: false,
btn: ['保存', '关闭'],
yes: function (index, layero) {
var dateTemp = new Date().Format("yyyyMMddhhmmss");
var exKey = "Trade_" + "平仓" + "_" + dateTemp;
thisObj.downCsv(exKey, textContent, ".txt");
main.message("导出成功", 50);
thisObj.closeLayer();
},
cancel: function (index, layero) {
thisObj.closeLayer();
},
shade: 0.4,
area: ['380px', '400px'],
content: "
' + abstractText + '', buttons: [{ text: '保存', click() { var dateTemp = new Date().Format("yyyyMMddhhmmss"); var exKey = "Trade_" + "平仓" + "_" + dateTemp; thisObj.downCsv(exKey, abstractText, ".txt"); main.message("导出成功", 50); thisObj.closeLayer(); } }, { text: '关闭', style: 'secondary', close: true, click: thisObj.closeLayer }], onHide: thisObj.closeLayer }); }, getValidVal: function (val, defaultVal) { if (val == null || val === "undefined") { return defaultVal || ""; } return val; }, getRowText: function (data, rowModel, template) { var rowText = ""; for (var i = 0; i < data.length; i++) { var val = this.getValidVal(data[i].value, rowModel); if (data[i].visible != undefined && data[i].visible != null) { if (typeof data[i].visible == "boolean" && !data[i].visible) { continue; } if (typeof data[i].visible == "function" && !data[i].visible(val, rowModel)) { continue; } } if (val !== "" && data[i].func && typeof data[i].func == "function") { val = data[i].func(val, rowModel); } rowText += template.template(data[i].name, val); } return rowText; }, downCsv: function (fileName, exStrr, fileExtension) { //针对换行符和空格符转换 exStrr = exStrr.replace(/                 /g, " ").replace(/                /g, " ").replace(/权  利  金/g, "权 利 金").replace(/