Polish risk sizing: 2dp money preview, editable ratio/exit, plan badge.
Exit unit and perp/option units scale with k; plan page shows 以损定仓. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -29,6 +29,33 @@ def test_compute_k_scales_1_2_15() -> None:
|
||||
assert r.option_qty_eth == BASE_OPTION_ETH
|
||||
assert r.net_profit_target == BASE_EXIT_USDT
|
||||
assert r.max_loss is not None and r.max_loss <= 43.0 + 1e-6
|
||||
assert r.budget == 43.0
|
||||
|
||||
|
||||
def test_compute_k_custom_units() -> None:
|
||||
# option_unit=4 → premium unit = 20*4=80; fee=3; cost=83; budget=83 → k=1
|
||||
r = compute_k(
|
||||
budget=83.0,
|
||||
index_px=2000.0,
|
||||
option_ask=20.0,
|
||||
fee_rate=0.0005,
|
||||
perp_unit=0.5,
|
||||
option_unit=4.0,
|
||||
exit_unit=30.0,
|
||||
)
|
||||
assert r.ok
|
||||
assert r.k == 1.0
|
||||
assert r.perp_qty_eth == 0.5
|
||||
assert r.option_qty_eth == 4.0
|
||||
assert r.net_profit_target == 30.0
|
||||
|
||||
|
||||
def test_money_rounds_2dp() -> None:
|
||||
r = compute_k(budget=50.123456, index_px=1900.0, option_ask=18.5, fee_rate=0.0005)
|
||||
assert r.ok
|
||||
assert r.budget == round(50.123456, 2)
|
||||
assert r.max_loss is not None
|
||||
assert abs(r.max_loss * 100 - round(r.max_loss * 100)) < 1e-9
|
||||
|
||||
|
||||
def test_compute_k_never_exceeds_budget() -> None:
|
||||
|
||||
Reference in New Issue
Block a user