Files
zszq-trs/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindLegSign.js
T

46 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* unwindLegSign.js — 平仓页收付方向符号(纯函数)
* ============================================================================
* 把散落在 unwindSwapTrade.js 各计算式里的裸三元(xxx==1 ? ±1 : ∓1)显式化为命名函数。
* 【为什么必须显式化】利息盈亏与保证金返还本金对同一 InterestDirection 枚举符号相反——
* 这是业务事实而非笔误,任何"顺手统一"都会翻转保证金返还方向(资损级 bug):
* 利息盈亏(利息腿/保证金腿通用,changeInterestAmount 对两类行都生效):
* 收益互换中买方为持有标的向交易商融资,利息=融资成本(买方付出去的钱),
* InterestDirection==1(收取) → 盈亏记 +1
* 保证金返还本金:保证金是客户自己交的抵押金,返息/返还本金是把客户自己的钱退回来,
* 本金流方向与利息(成本)相反 → 同枚举符号取镜像 -1。
*
* 其余两个符号:PayDirection==1(浮动端收取) → +1PositionType==1(多头) → +1。
*
* 加载:浏览器 script 标签(先于 unwindSwapTrade.js);Nodemodule.exports 供 jest。
*/
var UnwindLegSign = (function () {
'use strict';
// Number()===1 与页面原 ==1 对 '1'/true/数字等实际入参等价,且对 null/undefined 同样落到 -1 分支
function interestPnlSign(interestDirection) {
return Number(interestDirection) === 1 ? 1 : -1;
}
function marginRebatePrincipalSign(interestDirection) {
return Number(interestDirection) === 1 ? -1 : 1;
}
function payDirectionSign(payDirection) {
return Number(payDirection) === 1 ? 1 : -1;
}
function positionTypeSign(positionType) {
return Number(positionType) === 1 ? 1 : -1;
}
return Object.freeze({
interestPnlSign: interestPnlSign,
marginRebatePrincipalSign: marginRebatePrincipalSign,
payDirectionSign: payDirectionSign,
positionTypeSign: positionTypeSign
});
}());
if (typeof module === 'object' && module.exports) module.exports = UnwindLegSign;