Show semi risk-based open size from ask and unit ratio.
Semi sizing uses market ask with semi units; Plan panel previews option/perp qty under the form. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -119,6 +119,41 @@ def test_selection_basis_yields_smaller_k_when_ask_cheap() -> None:
|
||||
assert r_act.k is not None and r_act.k > r_sel.k
|
||||
|
||||
|
||||
def test_compute_risk_sizing_unit_overrides(tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setenv("MODE", "SIM")
|
||||
from app.models.db import Database
|
||||
from app.strategy.risk_sizing import compute_risk_sizing
|
||||
|
||||
db = Database(tmp_path / "risk_units.db")
|
||||
db.set_setting("sizing_mode", "risk_based")
|
||||
db.set_setting("risk_loss_mode", "absolute")
|
||||
db.set_setting("risk_loss_usdt", "83")
|
||||
db.set_setting("fee_rate", "0.0005")
|
||||
db.set_setting("risk_leverage_basis", "selection")
|
||||
db.set_setting("min_option_leverage", "100")
|
||||
db.set_setting("risk_perp_unit", "1")
|
||||
db.set_setting("risk_option_unit", "2")
|
||||
db.set_setting("risk_exit_unit", "15")
|
||||
|
||||
# 覆盖为单位 0.5:4、出场 5,并强制实际卖一(ask=20 → cost=80+3=83 → k=1)
|
||||
r = compute_risk_sizing(
|
||||
index_px=2000.0,
|
||||
option_ask=20.0,
|
||||
db=db,
|
||||
perp_unit=0.5,
|
||||
option_unit=4.0,
|
||||
exit_unit=5.0,
|
||||
leverage_basis="actual",
|
||||
)
|
||||
assert r.ok
|
||||
assert r.leverage_basis == "actual"
|
||||
assert r.k == 1.0
|
||||
assert r.perp_qty_eth == 0.5
|
||||
assert r.option_qty_eth == 4.0
|
||||
assert r.net_profit_target == 5.0
|
||||
db.close()
|
||||
|
||||
|
||||
def test_compute_risk_sizing_respects_basis(tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setenv("MODE", "SIM")
|
||||
from app.models.db import Database
|
||||
|
||||
Reference in New Issue
Block a user