Fix option-option exit preview to use budget times reward ratio.

Plan no longer shows perp exit_unit*k as the OO target.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-07 16:41:51 +08:00
parent eaf94448a2
commit 24943adf13
3 changed files with 136 additions and 2 deletions
+23
View File
@@ -66,6 +66,29 @@ def test_amplitude_range_pct() -> None:
assert abs(a.range_pct - 3.0) < 1e-9
def test_preview_oo_exit_budget_times_ratio(tmp_path, monkeypatch) -> None:
monkeypatch.setenv("MODE", "SIM")
from app.models.db import Database
from app.sim.ledger import Ledger
from app.strategy.risk_sizing import _preview_oo_sizing
db = Database(tmp_path / "oo_prev.db")
db.set_setting("hedge_mode", "option_option")
db.set_setting("sizing_mode", "risk_based")
db.set_setting("risk_loss_mode", "percent")
db.set_setting("risk_loss_pct", "1")
db.set_setting("risk_capital_source", "manual")
db.set_setting("risk_manual_capital_usdt", "10000")
db.set_setting("oo_reward_ratio", "2")
monkeypatch.setattr("app.strategy.risk_sizing.get_db", lambda: db)
# 无 session 盘口时仍应给出 预算×比
out = _preview_oo_sizing(db, Ledger(db), {"hedge_mode": "option_option"})
assert out.get("ok") is True
assert abs(float(out.get("budget") or 0) - 100.0) < 1e-6
assert abs(float(out.get("net_profit_target") or 0) - 200.0) < 1e-6
db.close()
def test_amplitude_max_gate() -> None:
from app.strategy.oo_selection import build_oo_pick_core