1061 lines
39 KiB
JavaScript
1061 lines
39 KiB
JavaScript
const inputFormatPercent = Object.freeze({ precision: 2, append: '%' });
|
|
const inputFormatNegative = Object.freeze({ precision: 2, negative: true });
|
|
const consPriceNormalRender = _.template(($('#priceNormal').html() || '').trim().replace(/[\r\n]+\s+/g, '') || ' ');
|
|
const consPriceCalcRender = _.template(($('#priceCalc').html() || '').trim().replace(/[\r\n]+\s+/g, '') || ' ');
|
|
const consVolNormalRender = _.template(($('#volNormal').html() || '').trim().replace(/[\r\n]+\s+/g, '') || ' ');
|
|
const consVolCalcRender = _.template(($('#volCalc').html() || '').trim().replace(/[\r\n]+\s+/g, '') || ' ');
|
|
var totalPv = 0;
|
|
var originalTotalPv = 0;
|
|
var totalPnl = 0;
|
|
var originalTotalPnl = 0;
|
|
var totalPvClient = 0;
|
|
var originalTotalPvClient = 0;
|
|
var totalPnlClient = 0;
|
|
var originalTotalPnlClient = 0;
|
|
var g_grid = {};
|
|
var originalRowDatas = [];
|
|
$(function () {
|
|
var PostData = {};
|
|
|
|
//控件选择时的触发事件
|
|
main.setTradeDatePicker("", "#ValueDate", page.calcDate);
|
|
|
|
//默认初始值赋值逻辑
|
|
$("#ValueDate").val(page.valueDate || page.calcDate);
|
|
$("#ValueDate").prop("disabled", true);
|
|
$("#ParentFlag").val(page.ParentFlag ? "True" : "False");
|
|
|
|
PostData.ValueDate = $("#ValueDate").val();
|
|
PostData.ClientId = $("#ClientId").val();
|
|
PostData.ParentFlag = $("#ParentFlag").val();
|
|
var url = $("#ClientId").val() > 0 ? '/trade_span/clientTradePositionChildrenQuery' : '';
|
|
var grid = jQuery('#listGrid').jqGrid({
|
|
url: url,
|
|
datatype: 'json',
|
|
height: 'auto',
|
|
width: '96%',
|
|
multiselect: true,
|
|
autowidth: false,
|
|
shrinkToFit: false,
|
|
viewrecords: true,
|
|
jsonReader: { repeatitems: false },
|
|
caption: '',
|
|
mtype: 'POST',
|
|
onSortCol: onSortCol,
|
|
postData: PostData,
|
|
afterInsertRow: AfterInsertRow,
|
|
onSelectRow: rowclick,
|
|
ondblClickRow: rowdblclick,
|
|
onSelectAll: allRowSelect,
|
|
colModel: colModelGrid,
|
|
pager: jQuery('#pagerGrid'),
|
|
pagerpos: 'left',
|
|
rowNum: 100,
|
|
rowList: [100, 1000],
|
|
footerrow: true,
|
|
loadComplete: gridComplete,
|
|
grouping: true
|
|
});
|
|
main.setcolumnChooser(grid, page.configcolumn);
|
|
|
|
let underlyingCtrl = new tradeHelper.UnderlyingSelectCtrl('#UnderlyingId').setFlag(tradeHelper.UnderlyingSelectFlag.OtcTrade);
|
|
|
|
$(".datepicker").datepicker({
|
|
changeMonth: true,
|
|
changeYear: true,
|
|
showButtonPanel: true,
|
|
showOtherMonths: true,
|
|
selectOtherMonths: true
|
|
});
|
|
|
|
try {
|
|
SetAceDropDown();
|
|
|
|
} catch (e) {
|
|
//
|
|
}
|
|
|
|
function AfterInsertRow(rowid, aData) {
|
|
}
|
|
});
|
|
|
|
function onSortCol(index, icol, sortorder) {
|
|
g_sort.name = index;
|
|
g_sort.order = sortorder;
|
|
}
|
|
|
|
const minusDoubleFormat = function (cellValue, options, rowObject) {
|
|
return otcformat.trading.greek(-cellValue);
|
|
};
|
|
|
|
var g_sort = { name: "TradeNumber", order: "desc" };
|
|
|
|
var i = 0;
|
|
|
|
var colModelGrid = (function () {
|
|
var col = [
|
|
{
|
|
name: 'EncryptTradeId', index: 'EncryptTradeId', hidden: true, optionHide: true
|
|
}, {
|
|
name: 'TradeId', index: 'TradeId', key: true, hidden: true, optionHide: true
|
|
}, {
|
|
name: 'ClientName',
|
|
label: '客户名称',
|
|
index: 'ClientName',
|
|
width: 180,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
sorttype: "text",
|
|
align: 'center'
|
|
}, {
|
|
name: 'TradeNumber',
|
|
label: '交易编号',
|
|
index: 'TradeNumber',
|
|
width: 180,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
sorttype: "text",
|
|
align: 'center'
|
|
}, {
|
|
name: 'BuySell',
|
|
label: '交易方向',
|
|
index: 'BuySell',
|
|
width: 90,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center'
|
|
}, {
|
|
name: 'TradeDate',
|
|
label: '交易日期',
|
|
index: 'TradeDate',
|
|
width: 90,
|
|
sortable: false,
|
|
sorttype: "date",
|
|
align: 'center',
|
|
sortIndex: i++,
|
|
formatter: 'date',
|
|
unformat: unformatStr
|
|
}, {
|
|
name: 'ExerciseDate',
|
|
label: '到期日期',
|
|
index: 'ExerciseDate',
|
|
width: 100,
|
|
sortable: false,
|
|
sorttype: "date",
|
|
align: 'center',
|
|
sortIndex: i++,
|
|
formatter: 'date',
|
|
unformat: unformatStr
|
|
}, {
|
|
name: 'TradeMultipleType',
|
|
label: '结构类型',
|
|
index: 'TradeMultipleType',
|
|
width: 120,
|
|
sortable: false,
|
|
align: 'center',
|
|
sortIndex: i++
|
|
}, {
|
|
name: 'TradeType',
|
|
label: 'TradeType',
|
|
index: 'TradeType',
|
|
width: 120,
|
|
sortable: false,
|
|
hidden: true,
|
|
optionHide: true,
|
|
sortIndex: i++
|
|
}, {
|
|
name: 'UnderlyingCode',
|
|
label: '标的代码',
|
|
index: 'UnderlyingCode',
|
|
width: 80,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center',
|
|
formatter: ShowStructFormater,
|
|
unformat: unformatStr
|
|
}, {
|
|
name: 'UnderlyingAssetName',
|
|
label: '标的名称',
|
|
index: 'UnderlyingAssetName',
|
|
width: 80,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center'
|
|
}, {
|
|
name: 'SpotPrice',
|
|
label: '期初标的价格',
|
|
index: 'SpotPrice',
|
|
width: 100,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center',
|
|
formatter: otcformat.trading.umprice,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'Strike',
|
|
label: '执行价格',
|
|
index: 'Strike',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: StrikeFormat,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'TradeOpenVolatility',
|
|
label: '成交波动率',
|
|
index: 'TradeOpenVolatility',
|
|
width: 100,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center',
|
|
formatter: volPercentFormat,
|
|
unformat: unformat,
|
|
hidden: true,
|
|
optionHide: !page.isTradeVol
|
|
}, {
|
|
name: 'IsUsePremiumRate',
|
|
label: 'IsUsePremiumRate',
|
|
index: 'IsUsePremiumRate',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
optionHide: true,
|
|
hidden: true
|
|
}, {
|
|
name: 'TradeSinglePrice',
|
|
label: '权利金(单价)',
|
|
index: 'TradeSinglePrice',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: TradeSinglePriceFormat,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'TradeOriginalAmountV',
|
|
label: '交易数量',
|
|
width: 70,
|
|
sortable: false,
|
|
formatter: function (cellvalue, options, rowObject) {
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? tradeHelper.getTradeAmountV(rowObject.trade) * (rowObject.CountRatio || 1) : tradeHelper.getTradeAmountV(rowObject.trade));
|
|
},
|
|
unformat: unformat
|
|
}, {
|
|
name: 'TradeOriginalAmount',
|
|
label: '有效交易数量',
|
|
index: 'TradeOriginalAmount',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: TradeAmountFormat,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'TradePrice',
|
|
label: '交易总额',
|
|
index: 'TradePrice',
|
|
width: 120,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: TradePriceFormat,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'OriginalStockEqvNotional',
|
|
label: '名义本金',
|
|
index: 'OriginalStockEqvNotional',
|
|
width: 120,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: otcformat.trading.StockEqvNotional,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'StockEqvNotional',
|
|
label: '持仓名义本金',
|
|
index: 'StockEqvNotional',
|
|
width: 120,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: otcformat.trading.StockEqvNotional,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: 'UnderlyingPrice',
|
|
label: '当前标的价格',
|
|
index: 'UnderlyingPrice',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: spotPriceFormat,
|
|
unformat: unformat
|
|
}, {
|
|
name: 'Vol',
|
|
label: page.isTradeVol ? '持仓波动率' : "当前波动率",
|
|
index: 'Vol',
|
|
width: 100,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center',
|
|
formatter: volFormat,
|
|
unformat: unformat
|
|
}, {
|
|
name: 'CurrentPrice',
|
|
label: '期权现价(单价)',
|
|
index: 'CurrentPrice',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: CurrentPriceFormat,
|
|
unformat: unformat
|
|
}, {
|
|
name: 'TradeAmountV',
|
|
label: '持仓数量',
|
|
width: 70,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: function (cellvalue, options, rowObject) {
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? tradeHelper.getTradeAmountV(rowObject.trade, rowObject.TradeAmount, 1) * (rowObject.CountRatio || 1) : tradeHelper.getTradeAmountV(rowObject.trade, rowObject.TradeAmount, 1));
|
|
},
|
|
unformat: unformat
|
|
}, {
|
|
name: 'TradeAmount',
|
|
label: '有效持仓数量',
|
|
index: 'TradeAmount',
|
|
width: 100,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: TradeAmountFormat,
|
|
unformat: unformat,
|
|
hidden: true
|
|
}, {
|
|
name: page.isPvRounded ? 'RoundedPv' : 'Pv',
|
|
label: '持仓市值',
|
|
index: page.isPvRounded ? 'RoundedPv' : 'Pv',
|
|
width: 120,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: TradePriceFormat,
|
|
unformat: unformat,
|
|
summaryType: 'sum'
|
|
}, {
|
|
name: page.isPvRounded ? 'RoundedPnl' : 'Pnl',
|
|
label: '持仓盈亏',
|
|
index: page.isPvRounded ? 'RoundedPnl' : 'Pnl',
|
|
width: 120,
|
|
align: 'center',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
formatter: otcformat.trading.tradePrice,
|
|
unformat: unformat,
|
|
summaryType: 'sum'
|
|
}, {
|
|
name: 'Delta',
|
|
label: 'Delta',
|
|
index: 'Delta',
|
|
width: 100,
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
align: 'center',
|
|
formatter: minusDoubleFormat,
|
|
unformat: unformat
|
|
}, {
|
|
name: 'MaturityDay',
|
|
label: 'MaturityDay',
|
|
index: 'MaturityDay',
|
|
sortable: false,
|
|
sortIndex: i++,
|
|
hidden: true,
|
|
optionHide: true
|
|
}
|
|
];
|
|
return col;
|
|
}());
|
|
|
|
function gridComplete() {
|
|
var jgrid = $(this);
|
|
var rowNum = parseInt(jgrid.getGridParam('records'), 10);
|
|
if (rowNum > 0) {
|
|
$(".ui-jqgrid-sdiv").show();
|
|
totalPv = arguments[0].Sum == null ? "" : (page.isPvRounded ? arguments[0].Sum.RoundedPvSum : arguments[0].Sum.PvSum);
|
|
totalPnl = arguments[0].Sum == null ? "" : (page.isPvRounded ? arguments[0].Sum.RoundedDailyPnLSum : arguments[0].Sum.DailyPnLSum);
|
|
originalTotalPv = totalPv;
|
|
originalTotalPnl = totalPnl;
|
|
if (page.isPvRounded) {
|
|
jgrid.footerData("set", { ClientName: "合计", RoundedPv: totalPv, RoundedPnl: totalPnl });
|
|
}
|
|
else {
|
|
jgrid.footerData("set", { ClientName: "合计", Pv: totalPv, Pnl: totalPnl });
|
|
}
|
|
$(".ui-jqgrid-sortable").css("text-align", "center");
|
|
|
|
var newHeight = $(window).height() - 270;
|
|
$(".ui-jqgrid .ui-jqgrid-bdiv").css("cssText", "height: " + newHeight + "px!important;");
|
|
$('.ui-jqgrid-bdiv', '#gbox_listGrid').floatingScroll();
|
|
|
|
if ($("#PvSum").val() == "" && $("#PnlSum").val() == "") {
|
|
$("#PvSum").val(otcformat.trading.tradePrice(totalPv));
|
|
$("#PvSum").css('color', totalPv > 0 ? 'red' : (totalPv < 0 ? 'green' : ''));
|
|
$("#PnlSum").val(otcformat.trading.tradePrice(totalPnl));
|
|
$("#PnlSum").css('color', totalPnl > 0 ? 'red' : (totalPnl < 0 ? 'green' : ''));
|
|
totalPvClient = numeral(otcformat.trading.tradePrice(totalPv)).value();
|
|
totalPnlClient = numeral(otcformat.trading.tradePrice(totalPnl)).value();
|
|
originalTotalPvClient = totalPvClient;
|
|
originalTotalPnlClient = totalPnlClient;
|
|
}
|
|
|
|
originalRowDatas = jgrid.getRowData();
|
|
} else {
|
|
$(".ui-jqgrid-sdiv").hide();
|
|
}
|
|
//jgrid.sortGrid(g_sort.name, g_sort.order);
|
|
main.setcolumnChooser(jgrid, page.configcolumn);
|
|
$(".selftooltip").tooltip({ html: true, show: 50000, trigger: "hover" });
|
|
}
|
|
|
|
function rowdblclick(rowid) {
|
|
var rowData = $(this).getRowData(rowid);
|
|
if (rowData.EncryptTradeId) {
|
|
starttradeView(rowData.TradeMultipleType, rowData.EncryptTradeId);
|
|
}
|
|
}
|
|
|
|
function starttradeView(tradetype, id) {
|
|
if (tradetype.indexOf("远期") >= 0) {
|
|
let srcurl = "/forwardtrade/tradeView/?enid=" + id + "&isFromPositionReport=true";
|
|
main.open("查看远期交易", srcurl, { area: ['1260px', '100%'] });
|
|
}
|
|
else {
|
|
let srcurl = "/trade/tradeView/?enid=" + id + "&isFromPositionReport=true";
|
|
main.open("查看交易", srcurl, { area: ['1260px', '100%'] });
|
|
}
|
|
}
|
|
|
|
function showExerciseMode(cellValue, options, rowObject) {
|
|
if ("American" === rowObject.ExerciseMode || "American" === rowObject.ExerciseMode) {
|
|
return "美式";
|
|
} else if ("European" === rowObject.ExerciseMode || "European" === rowObject.ExerciseMode) {
|
|
return "欧式";
|
|
}
|
|
}
|
|
|
|
function ShowStructFormater(cellValue, options, rowObject) {
|
|
var html;
|
|
if (rowObject.TradeType === "合成价差期权") {
|
|
html =
|
|
"<a href=\"#\" class=\"selftooltip\" style=\"z-index:10000000\" data-toggle=\"tooltip\" title=\"{1}\">{0}</a>"
|
|
.template(cellValue, rowObject.SyntheticUnderlyingTipsInfo);
|
|
return html;
|
|
}
|
|
return cellValue;
|
|
}
|
|
|
|
function CurrentPriceFormat(cellValue, options, rowObject) {
|
|
if (rowObject.IsUsePremiumRate) {
|
|
var premiumRate = tradeHelper.GetPremiumRateByTradeSinglePrice(cellValue, rowObject.SpotPrice);
|
|
return otcformat.trading.premiumRateP(premiumRate);
|
|
} else {
|
|
return otcformat.trading.tradeSinglePrice(cellValue);
|
|
}
|
|
}
|
|
|
|
function volPercentFormat(cellValue, options, rowObject) {
|
|
if (page.g_volMoreAccurate) {
|
|
return cellValue == null || cellValue == undefined ? "0.0000%" : numeral(cellValue).format("0.0000%") == "NaN" ? "0.0000%" : numeral(cellValue).format("0.0000%");
|
|
}
|
|
else {
|
|
return cellValue == null || cellValue == undefined ? "0.00%" : numeral(cellValue).format("0.00%") == "NaN" ? "0.00%" : numeral(cellValue).format("0.00%");
|
|
}
|
|
}
|
|
|
|
function percentFormatOne(cellValue, options, rowObject) {
|
|
return cellValue == null || cellValue == undefined ? "0.0%" : numeral(cellValue).format("0.0%") == "NaN" ? "0.0%" : numeral(cellValue).format("0.0%");
|
|
}
|
|
|
|
function TradePriceFormat(cellValue, options, rowObject) {
|
|
return otcformat.trading.tradePrice(cellValue);
|
|
}
|
|
|
|
function StrikeFormat(cellValue, options, rowObject) {
|
|
if (rowObject.TradeType == "自定义交易") {
|
|
return rowObject.StrikeToShow;
|
|
}
|
|
else if (rowObject.TradeType === "收益互换") {
|
|
return "--";
|
|
}
|
|
|
|
if (rowObject.Strike) {
|
|
if (rowObject.IsMoneynessOption === "是") {
|
|
return otcformat.trading.umprice(rowObject.SpotPrice * rowObject.Strike);
|
|
} else {
|
|
return otcformat.trading.umprice(rowObject.Strike);
|
|
}
|
|
} else {
|
|
if (rowObject.Strike === 0) {
|
|
return otcformat.trading.umprice(0);
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
function TradeSinglePriceFormat(cellValue, options, rowObject) {
|
|
if (rowObject.IsUsePremiumRate) {
|
|
return otcformat.trading.premiumRateP(rowObject.PremiumRate);
|
|
}
|
|
else {
|
|
return otcformat.trading.tradeSinglePrice(cellValue);
|
|
}
|
|
}
|
|
|
|
function TradeAmountFormat(cellValue, options, rowObject) {
|
|
if (rowObject.TradeType == "现金流交易") {
|
|
return "";
|
|
}
|
|
else {
|
|
return otcformat.trading.notional(page.IsUseDisplayNotional ? cellValue * (rowObject.CountRatio || 1) : cellValue);
|
|
}
|
|
}
|
|
|
|
function spotPriceFormat(cellValue, options, rowObject) {
|
|
var originalPrice = rowObject.OriginalPrice !== undefined ? rowObject.OriginalPrice : cellValue;
|
|
var formatVal = otcformat.trading.umprice(cellValue);
|
|
var originalFormatVal = otcformat.trading.umprice(originalPrice);
|
|
|
|
return rowObject.IsPriceCalc ? consPriceCalcRender({ price: originalPrice, formatVal: formatVal, TradeId: rowObject.TradeId })
|
|
: consPriceNormalRender({
|
|
TradeId: rowObject.TradeId,
|
|
formatVal: originalFormatVal
|
|
});
|
|
}
|
|
|
|
function volFormat(cellValue, options, rowObject) {
|
|
var originalVol = rowObject.OriginalVol !== undefined ? rowObject.OriginalVol : cellValue;
|
|
var formatVal = volPercentFormat(cellValue);
|
|
var originalFormatVal = volPercentFormat(originalVol);
|
|
|
|
return rowObject.IsVolCalc ? consVolCalcRender({ vol: originalVol, formatVal: formatVal, TradeId: rowObject.TradeId })
|
|
: consVolNormalRender({
|
|
TradeId: rowObject.TradeId,
|
|
formatVal: originalFormatVal
|
|
});
|
|
}
|
|
|
|
function unformatStr(cellValue, options, rowObject) {
|
|
return cellValue;
|
|
}
|
|
|
|
function unformat(cellValue, options, rowObject) {
|
|
return numeral(cellValue).value();
|
|
}
|
|
|
|
function rowclick(id) {
|
|
setFooter();
|
|
}
|
|
|
|
function allRowSelect(rowids, status) {
|
|
setFooter();
|
|
}
|
|
|
|
function reloadTradeMarketReport() {
|
|
//重新加载
|
|
SearchClick(true);
|
|
}
|
|
|
|
//搜索持仓明细
|
|
function SearchClick(isSearchclick) {
|
|
if (!$("#ClientId").val()) {
|
|
main.message("请选择需要查看的客户!");
|
|
return;
|
|
}
|
|
|
|
var listGrid = $('#listGrid');
|
|
listGrid.jqGrid('setGridParam', {
|
|
url: '/trade_span/clientTradePositionChildrenQuery',
|
|
datatype: 'json'
|
|
})
|
|
listGrid.appendPostData({ ClientId: $("#ClientId").val() });
|
|
listGrid.appendPostData({ ValueDate: $("#ValueDate").val() });
|
|
listGrid.appendPostData({ ParentFlag: $("#ParentFlag").val() });
|
|
listGrid.appendPostData({ TradeNumber: $("#TradeNumber").val() });
|
|
listGrid.appendPostData({ TradeTypes: $("#TradeTypes").val() });
|
|
listGrid.appendPostData({ BookIds: $("#AssetId").val() })
|
|
listGrid.appendPostData({ AssetIdGroupList: $("#GroupId").val() })
|
|
listGrid.appendPostData({ UnderlyingIds: $("#UnderlyingId").val() });
|
|
listGrid.appendPostData({ TradeDateStart: $("#DateFromTradeDate").val() });
|
|
listGrid.appendPostData({ TradeDateEnd: $("#DateToTradeDate").val() });
|
|
listGrid.appendPostData({ ExerciseDateStart: $("#DateFromExerciseDate").val() });
|
|
listGrid.appendPostData({ ExerciseDateEnd: $("#DateToExerciseDate").val() });
|
|
|
|
if (!$("#ValueDate").val()) {
|
|
main.message("请选择要查看报告的结束日期!");
|
|
return;
|
|
}
|
|
|
|
if ($("#ValueDate").val() > page.calcDate) {
|
|
main.message("结束日期不能大于当前系统日期!");
|
|
return;
|
|
}
|
|
|
|
if (typeof (isSearchclick) != "undefined" && isSearchclick) {
|
|
//点击搜索时默认第一页
|
|
listGrid.jqGrid('setGridParam',
|
|
{
|
|
page: 1
|
|
});
|
|
}
|
|
listGrid.trigger('reloadGrid');
|
|
originalRowDatas = listGrid.getRowData();
|
|
history.replaceState(null, null, window.location.href.replace(/([?&]clientId)=[^&]+/, '$1=' + $("#ClientId").val()));
|
|
|
|
var req = {};
|
|
req.ValueDate = $("#ValueDate").val();
|
|
req.ClientId = $("#ClientId").val();
|
|
req.ParentFlag = $("#ParentFlag").val();
|
|
main.post("/trade_span/clientTradePositionQuery", { req: req }).done(function (resp) {
|
|
var pvSum = otcformat.trading.tradePrice(page.isPvRounded ? resp.Sum.RoundedPvSum : resp.Sum.PvSum);
|
|
var pnlSum = otcformat.trading.tradePrice(page.isPvRounded ? resp.Sum.RoundedDailyPnLSum : resp.Sum.DailyPnLSum);
|
|
$("#PvSum").val(pvSum);
|
|
$("#PvSum").css('color', (page.isPvRounded ? resp.Sum.RoundedPvSum : resp.Sum.PvSum) > 0 ? 'red' : ((page.isPvRounded ? resp.Sum.RoundedPvSum : resp.Sum.PvSum) < 0 ? 'green' : ''));
|
|
$("#PnlSum").val(pnlSum);
|
|
$("#PnlSum").css('color', (page.isPvRounded ? resp.Sum.RoundedDailyPnLSum : resp.Sum.DailyPnLSum) > 0 ? 'red' : ((page.isPvRounded ? resp.Sum.RoundedDailyPnLSum : resp.Sum.DailyPnLSum) < 0 ? 'green' : ''));
|
|
totalPvClient = numeral(pvSum).value();
|
|
totalPnlClient = numeral(pnlSum).value();
|
|
originalTotalPvClient = totalPvClient;
|
|
originalTotalPnlClient = totalPnlClient;
|
|
});
|
|
}
|
|
|
|
function numFormart(num) {
|
|
return main.formatNumber(num);
|
|
}
|
|
|
|
function showChiCang() {
|
|
main.showcolumnChooser(jQuery('#listGrid'), page.configcolumn);
|
|
}
|
|
|
|
function locationChange(tab) {
|
|
if ($("#ValueDate").val() > page.calcDate) {
|
|
main.message("结束日期不能大于当前系统日期!");
|
|
return;
|
|
}
|
|
|
|
window.location.href = tab + "?clientId=" + $("#ClientId").val() + "&valueDate=" + $("#ValueDate").val() + "&ParentFlag=" + $("#ParentFlag").val();
|
|
return;
|
|
}
|
|
|
|
function execPriceCalc(tradeId, thisobj) {
|
|
var listGrid = $('#listGrid');
|
|
var rowData = listGrid.getRowData(tradeId);
|
|
var needRowData = {};
|
|
needRowData.IsPriceCalc = true;
|
|
needRowData.UnderlyingPrice = numeral(thisobj.value).value();
|
|
needRowData.OriginalPrice = numeral(thisobj.dataset.originalprice).value();
|
|
|
|
ajaxCalcTradesPrice(tradeId, rowData, needRowData, listGrid);
|
|
}
|
|
|
|
function showPriceCalcInput(tradeId) {
|
|
var listGrid = $('#listGrid');
|
|
var rowData = listGrid.getRowData(tradeId);
|
|
|
|
if (rowData.TradeType === "自定义交易" || rowData.TradeType === "现金流交易") {
|
|
main.message(rowData.TradeType + "无法参与试算");
|
|
return false;
|
|
}
|
|
|
|
var needRowData = {};
|
|
needRowData.IsPriceCalc = true;
|
|
needRowData.UnderlyingPrice = rowData.UnderlyingPrice;
|
|
needRowData.OriginalPrice = rowData.OriginalPrice;
|
|
needRowData.TradeId = rowData.TradeId;
|
|
listGrid.setRowData(tradeId, needRowData);
|
|
$('#' + tradeId).find("td").addClass("calcBG");
|
|
}
|
|
|
|
function removePriceCalc(tradeId, price) {
|
|
var listGrid = $('#listGrid');
|
|
var rowData = listGrid.getRowData(tradeId);
|
|
var needRowData = {};
|
|
needRowData.IsPriceCalc = false;
|
|
needRowData.UnderlyingPrice = numeral(price).value();
|
|
needRowData.OriginalPrice = rowData.OriginalPrice;
|
|
|
|
ajaxCalcTradesPrice(tradeId, rowData, needRowData, listGrid);
|
|
if (rowData.Vol !== null) {
|
|
$('#' + tradeId).find("td").removeClass("calcBG");
|
|
}
|
|
}
|
|
|
|
function ajaxCalcTradesPrice(tradeId, rowData, needRowData, listGrid) {
|
|
needRowData.TradeId = tradeId;
|
|
needRowData.IsUsePremiumRate = rowData.IsUsePremiumRate == "true";
|
|
needRowData.SpotPrice = rowData.SpotPrice;
|
|
|
|
var request = {};
|
|
var tradeIds = [];
|
|
tradeIds.push(tradeId);
|
|
request.TradeIds = tradeIds;
|
|
request.ValueDate = $("#ValueDate").val();
|
|
var pricesDic = [];
|
|
pricesDic.push({ key: rowData.UnderlyingCode, value: needRowData.UnderlyingPrice });
|
|
request.PricesDic = pricesDic;
|
|
var volsDic = [];
|
|
volsDic.push({ key: tradeId, value: numeral(rowData.Vol ? rowData.Vol : $("#volInput" + tradeId).val()).value() });
|
|
request.VolsDic = volsDic;
|
|
main.post("/pricing/AjaxCalcTrades", { request: request }).done(function (resp) {
|
|
var optionValue = resp.obj.TradeOptionValueDic[tradeId];
|
|
if (optionValue != undefined) {
|
|
needRowData.Pv = -optionValue.Pv;
|
|
needRowData.RoundedPv = -optionValue.Pv;
|
|
needRowData.CurrentPrice = -optionValue.SinglePv;
|
|
needRowData.Pnl = -optionValue.Pnl;
|
|
needRowData.RoundedPnl = -optionValue.Pnl;
|
|
needRowData.Delta = optionValue.Delta;
|
|
|
|
var pvGap = (-optionValue.Pv) - (page.isPvRounded ? rowData.RoundedPv : rowData.Pv);
|
|
var pnlGap = (-optionValue.Pnl) - (page.isPvRounded ? rowData.RoundedPnl : rowData.Pnl);
|
|
totalPv = numeral(otcformat.trading.tradePrice(totalPv + pvGap)).value();
|
|
totalPnl = numeral(otcformat.trading.tradePrice(totalPnl + pnlGap)).value();
|
|
totalPvClient = numeral(otcformat.trading.tradePrice(totalPvClient + pvGap)).value();
|
|
totalPnlClient = numeral(otcformat.trading.tradePrice(totalPnlClient + pnlGap)).value();
|
|
|
|
listGrid.setRowData(tradeId, needRowData);
|
|
|
|
setFooter();
|
|
}
|
|
});
|
|
}
|
|
|
|
function execVolCalc(tradeId, thisobj) {
|
|
var listGrid = $('#listGrid');
|
|
var rowData = listGrid.getRowData(tradeId);
|
|
var needRowData = {};
|
|
needRowData.IsVolCalc = true;
|
|
needRowData.Vol = numeral(thisobj.value).value();
|
|
needRowData.OriginalVol = numeral(thisobj.dataset.originalvol).value();
|
|
|
|
ajaxCalcTradesVol(tradeId, rowData, needRowData, listGrid);
|
|
}
|
|
|
|
function showVolCalcInput(tradeId) {
|
|
var listGrid = $('#listGrid');
|
|
var rowData = listGrid.getRowData(tradeId);
|
|
|
|
if (rowData.TradeType === "自定义交易" || rowData.TradeType === "现金流交易") {
|
|
main.message(rowData.TradeType + "无法参与试算");
|
|
return false;
|
|
}
|
|
|
|
var needRowData = {};
|
|
needRowData.IsVolCalc = true;
|
|
needRowData.Vol = rowData.Vol;
|
|
needRowData.OriginalVol = rowData.OriginalVol;
|
|
needRowData.TradeId = rowData.TradeId;
|
|
listGrid.setRowData(tradeId, needRowData);
|
|
$('#' + tradeId).find("td").addClass("calcBG");
|
|
}
|
|
|
|
function removeVolCalc(tradeId, vol) {
|
|
var listGrid = $('#listGrid');
|
|
var rowData = listGrid.getRowData(tradeId);
|
|
var needRowData = {};
|
|
needRowData.IsVolCalc = false;
|
|
needRowData.Vol = numeral(vol).value();
|
|
needRowData.OriginalVol = rowData.OriginalVol;
|
|
|
|
ajaxCalcTradesVol(tradeId, rowData, needRowData, listGrid);
|
|
if (rowData.UnderlyingPrice !== null) {
|
|
$('#' + tradeId).find("td").removeClass("calcBG");
|
|
}
|
|
}
|
|
|
|
function ajaxCalcTradesVol(tradeId, rowData, needRowData, listGrid) {
|
|
needRowData.TradeId = tradeId;
|
|
needRowData.IsUsePremiumRate = rowData.IsUsePremiumRate == "true";
|
|
needRowData.SpotPrice = rowData.SpotPrice;
|
|
|
|
var request = {};
|
|
var tradeIds = [];
|
|
tradeIds.push(tradeId);
|
|
request.TradeIds = tradeIds;
|
|
request.ValueDate = $("#ValueDate").val();
|
|
var pricesDic = [];
|
|
pricesDic.push({ key: rowData.UnderlyingCode, value: (rowData.UnderlyingPrice ? rowData.UnderlyingPrice : $("#priceInput" + tradeId).val()) });
|
|
request.PricesDic = pricesDic;
|
|
var volsDic = [];
|
|
volsDic.push({ key: tradeId, value: needRowData.Vol });
|
|
request.VolsDic = volsDic;
|
|
main.post("/pricing/AjaxCalcTrades", { request: request }).done(function (resp) {
|
|
var optionValue = resp.obj.TradeOptionValueDic[tradeId];
|
|
if (optionValue !== undefined) {
|
|
needRowData.Pv = -optionValue.Pv;
|
|
needRowData.RoundedPv = -optionValue.Pv;
|
|
needRowData.CurrentPrice = -optionValue.SinglePv;
|
|
needRowData.Pnl = -optionValue.Pnl;
|
|
needRowData.RoundedPnl = -optionValue.Pnl;
|
|
needRowData.Delta = optionValue.Delta;
|
|
|
|
var pvGap = (-optionValue.Pv) - (page.isPvRounded ? rowData.RoundedPv : rowData.Pv);
|
|
var pnlGap = (-optionValue.Pnl) - (page.isPvRounded ? rowData.RoundedPnl : rowData.Pnl);
|
|
totalPv = numeral(otcformat.trading.tradePrice(totalPv + pvGap)).value();
|
|
totalPnl = numeral(otcformat.trading.tradePrice(totalPnl + pnlGap)).value();
|
|
totalPvClient = numeral(otcformat.trading.tradePrice(totalPvClient + pvGap)).value();
|
|
totalPnlClient = numeral(otcformat.trading.tradePrice(totalPnlClient + pnlGap)).value();
|
|
|
|
listGrid.setRowData(tradeId, needRowData);
|
|
|
|
setFooter();
|
|
}
|
|
});
|
|
}
|
|
|
|
function batchSetVols() {
|
|
var jgrid = $("#listGrid");
|
|
var rowObjs = main.GetGridObjs(jgrid);
|
|
if (rowObjs.length > 0) {
|
|
vueVol.count = rowObjs.length;
|
|
$('#volModal').modal('show');
|
|
}
|
|
else {
|
|
main.alert("请选择需要设置的交易");
|
|
}
|
|
}
|
|
|
|
function batchSetPrices() {
|
|
var jgrid = $("#listGrid");
|
|
var rowObjs = main.GetGridObjs(jgrid);
|
|
var pricesDic = [];
|
|
if (rowObjs.length > 0) {
|
|
rowObjs.forEach(obj => {
|
|
if (!pricesDic.find(t => t.key == obj.UnderlyingCode) && obj.UnderlyingCode) {
|
|
pricesDic.push({ key: obj.UnderlyingCode, value: numeral(obj.UnderlyingPrice ? obj.UnderlyingPrice : $("#priceInput" + obj.TradeId).val()).value() });
|
|
}
|
|
});
|
|
vuePrice.count = rowObjs.length;
|
|
vuePrice.pricesDic = pricesDic;
|
|
$('#priceModal').modal('show');
|
|
}
|
|
else {
|
|
main.alert("请选择需要设置的交易");
|
|
}
|
|
}
|
|
|
|
function backAll() {
|
|
var jgrid = $("#listGrid");
|
|
|
|
originalRowDatas.forEach(obj => {
|
|
var needRowData = {};
|
|
needRowData.Vol = obj.Vol;
|
|
needRowData.UnderlyingPrice = obj.UnderlyingPrice;
|
|
needRowData.TradeId = obj.TradeId;
|
|
needRowData.IsUsePremiumRate = obj.IsUsePremiumRate == "true";
|
|
needRowData.SpotPrice = obj.SpotPrice;
|
|
needRowData.Pv = obj.Pv;
|
|
needRowData.RoundedPv = obj.RoundedPv;
|
|
needRowData.CurrentPrice = obj.CurrentPrice;
|
|
needRowData.Pnl = obj.Pnl;
|
|
needRowData.RoundedPnl = obj.RoundedPnl;
|
|
needRowData.Delta = -obj.Delta;
|
|
jgrid.setRowData(obj.TradeId, needRowData);
|
|
$('#' + obj.TradeId).find("td").removeClass("calcBG");
|
|
});
|
|
|
|
if (page.isPvRounded) {
|
|
jgrid.footerData("set", { ClientName: "合计", RoundedPv: originalTotalPv, RoundedPnl: originalTotalPnl });
|
|
}
|
|
else {
|
|
jgrid.footerData("set", { ClientName: "合计", Pv: originalTotalPv, Pnl: originalTotalPnl });
|
|
}
|
|
$("#PvSum").val(otcformat.trading.tradePrice(originalTotalPvClient));
|
|
$("#PvSum").css('color', originalTotalPvClient > 0 ? 'red' : (originalTotalPvClient < 0 ? 'green' : ''));
|
|
$("#PnlSum").val(otcformat.trading.tradePrice(originalTotalPnlClient));
|
|
$("#PnlSum").css('color', originalTotalPnlClient > 0 ? 'red' : (originalTotalPnlClient < 0 ? 'green' : ''));
|
|
|
|
jgrid.jqGrid('resetSelection');
|
|
|
|
main.message("重置成功");
|
|
}
|
|
|
|
function setFooter() {
|
|
var jgrid = $("#listGrid");
|
|
var rowObjs = main.GetGridObjs(jgrid);
|
|
var pvSum = rowObjs.length > 0 ? 0 : totalPv;
|
|
var roundedPvSum = rowObjs.length > 0 ? 0 : totalPv;
|
|
var pnlSum = rowObjs.length > 0 ? 0 : totalPnl;
|
|
var roundedPnlSum = rowObjs.length > 0 ? 0 : totalPnl;
|
|
|
|
rowObjs.forEach(obj => {
|
|
pvSum += numeral(obj.Pv).value();
|
|
roundedPvSum += numeral(obj.RoundedPv).value();
|
|
pnlSum += numeral(obj.Pnl).value();
|
|
roundedPnlSum += numeral(obj.RoundedPnl).value();
|
|
});
|
|
|
|
if (page.isPvRounded) {
|
|
jgrid.footerData("set", { ClientName: "合计", RoundedPv: roundedPvSum, RoundedPnl: roundedPnlSum });
|
|
}
|
|
else {
|
|
jgrid.footerData("set", { ClientName: "合计", Pv: pvSum, Pnl: pnlSum });
|
|
}
|
|
|
|
$("#PvSum").val(otcformat.trading.tradePrice(totalPvClient));
|
|
$("#PvSum").css('color', totalPvClient > 0 ? 'red' : (totalPvClient < 0 ? 'green' : ''));
|
|
$("#PnlSum").val(otcformat.trading.tradePrice(totalPnlClient));
|
|
$("#PnlSum").css('color', totalPnlClient > 0 ? 'red' : (totalPnlClient < 0 ? 'green' : ''));
|
|
}
|
|
|
|
var vueVol = new Vue({
|
|
el: "#volModal",
|
|
data: {
|
|
count: 0,
|
|
vol: 0
|
|
},
|
|
created: function () {
|
|
},
|
|
methods: {
|
|
closeModal: function () {
|
|
$('#volModal').modal('hide');
|
|
},
|
|
saveModal: function () {
|
|
var thisobj = this;
|
|
var request = {};
|
|
var tradeIds = [];
|
|
var tradePricesDic = [];
|
|
var volsDic = [];
|
|
|
|
var listGrid = $("#listGrid");
|
|
var rowObjs = main.GetGridObjs(listGrid);
|
|
rowObjs.forEach(obj => {
|
|
tradeIds.push(obj.TradeId);
|
|
tradePricesDic.push({ key: obj.TradeId, value: numeral(obj.UnderlyingPrice ? obj.UnderlyingPrice : $("#priceInput" + obj.TradeId).val()).value() });
|
|
volsDic.push({ key: obj.TradeId, value: numeral(thisobj.vol).value() });
|
|
});
|
|
request.TradeIds = tradeIds;
|
|
request.ValueDate = $("#ValueDate").val();
|
|
request.TradePricesDic = tradePricesDic;
|
|
request.VolsDic = volsDic;
|
|
|
|
main.post("/pricing/AjaxCalcTrades", { request: request }).done(function (resp) {
|
|
rowObjs.forEach(obj => {
|
|
var optionValue = resp.obj.TradeOptionValueDic[obj.TradeId];
|
|
if (optionValue !== undefined) {
|
|
var needRowData = {};
|
|
needRowData.IsVolCalc = true;
|
|
needRowData.Vol = numeral(thisobj.vol).value();
|
|
needRowData.OriginalVol = numeral(obj.Vol !== null ? obj.Vol : $("#volInput" + obj.TradeId).data().originalvol).value();
|
|
needRowData.TradeId = obj.TradeId;
|
|
needRowData.IsUsePremiumRate = obj.IsUsePremiumRate == "true";
|
|
needRowData.SpotPrice = obj.SpotPrice;
|
|
needRowData.Pv = -optionValue.Pv;
|
|
needRowData.RoundedPv = -optionValue.Pv;
|
|
needRowData.CurrentPrice = -optionValue.SinglePv;
|
|
needRowData.Pnl = -optionValue.Pnl;
|
|
needRowData.RoundedPnl = -optionValue.Pnl;
|
|
needRowData.Delta = optionValue.Delta;
|
|
|
|
var pvGap = (-optionValue.Pv) - (page.isPvRounded ? obj.RoundedPv : obj.Pv);
|
|
var pnlGap = (-optionValue.Pnl) - (page.isPvRounded ? obj.RoundedPnl : obj.Pnl);
|
|
totalPv = numeral(otcformat.trading.tradePrice(totalPv + pvGap)).value();
|
|
totalPnl = numeral(otcformat.trading.tradePrice(totalPnl + pnlGap)).value();
|
|
totalPvClient = numeral(otcformat.trading.tradePrice(totalPvClient + pvGap)).value();
|
|
totalPnlClient = numeral(otcformat.trading.tradePrice(totalPnlClient + pnlGap)).value();
|
|
|
|
listGrid.setRowData(obj.TradeId, needRowData);
|
|
$('#' + obj.TradeId).find("td").addClass("calcBG");
|
|
}
|
|
});
|
|
|
|
setFooter();
|
|
});
|
|
$('#volModal').modal('hide');
|
|
}
|
|
},
|
|
components: {
|
|
'vue-number-input': FastVue.vueNumberInput()
|
|
}
|
|
});
|
|
|
|
var vuePrice = new Vue({
|
|
el: "#priceModal",
|
|
data: {
|
|
count: 0,
|
|
pricesDic: []
|
|
},
|
|
created: function () {
|
|
},
|
|
methods: {
|
|
closeModal: function () {
|
|
$('#priceModal').modal('hide');
|
|
},
|
|
saveModal: function () {
|
|
var thisobj = this;
|
|
var request = {};
|
|
var tradeIds = [];
|
|
var volsDic = [];
|
|
|
|
var listGrid = $("#listGrid");
|
|
var rowObjs = main.GetGridObjs(listGrid);
|
|
rowObjs.forEach(obj => {
|
|
tradeIds.push(obj.TradeId);
|
|
volsDic.push({ key: obj.TradeId, value: numeral(obj.Vol ? obj.Vol : $("#volInput" + obj.TradeId).val()).value() });
|
|
});
|
|
request.TradeIds = tradeIds;
|
|
request.ValueDate = $("#ValueDate").val();
|
|
request.PricesDic = thisobj.pricesDic;
|
|
request.VolsDic = volsDic;
|
|
|
|
main.post("/pricing/AjaxCalcTrades", { request: request }).done(function (resp) {
|
|
rowObjs.forEach(obj => {
|
|
var optionValue = resp.obj.TradeOptionValueDic[obj.TradeId];
|
|
if (optionValue !== undefined) {
|
|
var needRowData = {};
|
|
needRowData.IsPriceCalc = true;
|
|
needRowData.UnderlyingPrice = numeral(thisobj.pricesDic.find(t => t.key == obj.UnderlyingCode).value).value();
|
|
needRowData.OriginalPrice = numeral(obj.UnderlyingPrice !== null ? obj.UnderlyingPrice : $("#priceInput" + obj.TradeId).data().originalprice).value();
|
|
needRowData.TradeId = obj.TradeId;
|
|
needRowData.IsUsePremiumRate = obj.IsUsePremiumRate == "true";
|
|
needRowData.SpotPrice = obj.SpotPrice;
|
|
needRowData.Pv = -optionValue.Pv;
|
|
needRowData.RoundedPv = -optionValue.Pv;
|
|
needRowData.CurrentPrice = -optionValue.SinglePv;
|
|
needRowData.Pnl = -optionValue.Pnl;
|
|
needRowData.RoundedPnl = -optionValue.Pnl;
|
|
needRowData.Delta = optionValue.Delta;
|
|
|
|
var pvGap = (-optionValue.Pv) - (page.isPvRounded ? obj.RoundedPv : obj.Pv);
|
|
var pnlGap = (-optionValue.Pnl) - (page.isPvRounded ? obj.RoundedPnl : obj.Pnl);
|
|
totalPv = numeral(otcformat.trading.tradePrice(totalPv + pvGap)).value();
|
|
totalPnl = numeral(otcformat.trading.tradePrice(totalPnl + pnlGap)).value();
|
|
totalPvClient = numeral(otcformat.trading.tradePrice(totalPvClient + pvGap)).value();
|
|
totalPnlClient = numeral(otcformat.trading.tradePrice(totalPnlClient + pnlGap)).value();
|
|
$('#' + obj.TradeId).find("td").addClass("calcBG");
|
|
|
|
listGrid.setRowData(obj.TradeId, needRowData);
|
|
}
|
|
});
|
|
|
|
setFooter();
|
|
});
|
|
$('#priceModal').modal('hide');
|
|
}
|
|
},
|
|
components: {
|
|
'vue-number-input': FastVue.vueNumberInput()
|
|
}
|
|
}); |