|
@@ -129,7 +129,7 @@ def test_sell_final_pnl_uses_the_same_row() -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_note_distance_ratios_use_cleared_prices_and_round_half_up() -> None:
|
|
def test_note_distance_ratios_use_cleared_prices_and_round_half_up() -> None:
|
|
|
- """风控距离比例用票据清算结果重算,按百分数保留两位。"""
|
|
|
|
|
|
|
+ """风控距离比例用票据清算结果重算,按百分数保留两位;卡片公式用中文且 × 100。"""
|
|
|
|
|
|
|
|
note = {
|
|
note = {
|
|
|
"id": 31,
|
|
"id": 31,
|
|
@@ -143,16 +143,22 @@ def test_note_distance_ratios_use_cleared_prices_and_round_half_up() -> None:
|
|
|
"distance_force": Decimal("30.02"),
|
|
"distance_force": Decimal("30.02"),
|
|
|
}
|
|
}
|
|
|
lines = check_order(_order(_sub(), notes=(note,)))
|
|
lines = check_order(_order(_sub(), notes=(note,)))
|
|
|
- warning = _one(lines, "distance_warning")
|
|
|
|
|
|
|
+ warning = _one(lines, "距预警比例")
|
|
|
assert warning.verdict == "correct"
|
|
assert warning.verdict == "correct"
|
|
|
assert warning.calc_value == Decimal("10.01")
|
|
assert warning.calc_value == Decimal("10.01")
|
|
|
assert warning.check_value == Decimal("10.01")
|
|
assert warning.check_value == Decimal("10.01")
|
|
|
- danger = _one(lines, "distance_danger")
|
|
|
|
|
|
|
+ assert warning.formula_text == "距预警比例 = (最新价 − 预警价) / 最新价 × 100"
|
|
|
|
|
+ assert warning.calc_text == "(200.000000 - 179.990000) / 200.000000 × 100 = 10.01%"
|
|
|
|
|
+ assert "100%" not in warning.formula_text
|
|
|
|
|
+ assert "× 100%" not in warning.calc_text
|
|
|
|
|
+ danger = _one(lines, "距危险比例")
|
|
|
assert danger.verdict == "correct"
|
|
assert danger.verdict == "correct"
|
|
|
assert danger.calc_value == Decimal("20.01")
|
|
assert danger.calc_value == Decimal("20.01")
|
|
|
- force = _one(lines, "distance_force")
|
|
|
|
|
|
|
+ assert danger.formula_text == "距危险比例 = (最新价 − 危险价) / 最新价 × 100"
|
|
|
|
|
+ force = _one(lines, "距强平比例")
|
|
|
assert force.verdict == "correct"
|
|
assert force.verdict == "correct"
|
|
|
assert force.calc_value == Decimal("30.02")
|
|
assert force.calc_value == Decimal("30.02")
|
|
|
|
|
+ assert force.formula_text == "距强平比例 = (最新价 − 强平价) / 最新价 × 100"
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_note_distance_ratio_mismatch_is_error_and_zero_latest_is_suspect() -> None:
|
|
def test_note_distance_ratio_mismatch_is_error_and_zero_latest_is_suspect() -> None:
|
|
@@ -167,14 +173,15 @@ def test_note_distance_ratio_mismatch_is_error_and_zero_latest_is_suspect() -> N
|
|
|
"distance_danger": Decimal("20.00"),
|
|
"distance_danger": Decimal("20.00"),
|
|
|
"distance_force": Decimal("30.00"),
|
|
"distance_force": Decimal("30.00"),
|
|
|
}
|
|
}
|
|
|
- warning = _one(check_order(_order(_sub(), notes=(note,))), "distance_warning")
|
|
|
|
|
|
|
+ warning = _one(check_order(_order(_sub(), notes=(note,))), "距预警比例")
|
|
|
assert warning.verdict == "error"
|
|
assert warning.verdict == "error"
|
|
|
assert warning.calc_value == Decimal("10.00")
|
|
assert warning.calc_value == Decimal("10.00")
|
|
|
|
|
|
|
|
note["latest_px"] = Decimal("0")
|
|
note["latest_px"] = Decimal("0")
|
|
|
- warning = _one(check_order(_order(_sub(), notes=(note,))), "distance_warning")
|
|
|
|
|
|
|
+ warning = _one(check_order(_order(_sub(), notes=(note,))), "距预警比例")
|
|
|
assert warning.verdict == "suspect"
|
|
assert warning.verdict == "suspect"
|
|
|
assert warning.calc_value is None
|
|
assert warning.calc_value is None
|
|
|
|
|
+ assert warning.calc_text == "最新价为 0,无法计算"
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_sell_order_checks_note_distance_ratios() -> None:
|
|
def test_sell_order_checks_note_distance_ratios() -> None:
|
|
@@ -193,9 +200,9 @@ def test_sell_order_checks_note_distance_ratios() -> None:
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
lines = check_order(order)
|
|
lines = check_order(order)
|
|
|
- assert _one(lines, "distance_warning").verdict == "correct"
|
|
|
|
|
- assert _one(lines, "distance_danger").verdict == "correct"
|
|
|
|
|
- assert _one(lines, "distance_force").verdict == "correct"
|
|
|
|
|
|
|
+ assert _one(lines, "距预警比例").verdict == "correct"
|
|
|
|
|
+ assert _one(lines, "距危险比例").verdict == "correct"
|
|
|
|
|
+ assert _one(lines, "距强平比例").verdict == "correct"
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_sell_ratio_without_exec_notional_is_not_checked() -> None:
|
|
def test_sell_ratio_without_exec_notional_is_not_checked() -> None:
|
|
@@ -315,7 +322,8 @@ def test_force_and_maturity_use_sell_formulas() -> None:
|
|
|
force = _formulas(_sell_order(direction="buy", op_type="force"))
|
|
force = _formulas(_sell_order(direction="buy", op_type="force"))
|
|
|
maturity = _formulas(_sell_order(direction="sell", op_type="maturity"))
|
|
maturity = _formulas(_sell_order(direction="sell", op_type="maturity"))
|
|
|
assert sell == force == maturity
|
|
assert sell == force == maturity
|
|
|
- assert all("强平" not in text and "到期" not in text for text in force)
|
|
|
|
|
|
|
+ # 不因 op_type 另造「强平…」「到期…」公式;距强平比例是三线字段名,不算另造。
|
|
|
|
|
+ assert all(not text.startswith(("强平", "到期")) for text in force)
|
|
|
assert not any(text.startswith("票据发行价") for text in force)
|
|
assert not any(text.startswith("票据发行价") for text in force)
|
|
|
assert any(text.startswith("最终盈亏") for text in force)
|
|
assert any(text.startswith("最终盈亏") for text in force)
|
|
|
buy = _formulas(_order(_issue_sub()))
|
|
buy = _formulas(_order(_issue_sub()))
|