Add fractional Kelly position sizing

This commit is contained in:
Codex
2026-06-20 22:22:19 +03:00
parent ccf457481b
commit 7bbb721da1
8 changed files with 147 additions and 21 deletions
+3
View File
@@ -58,6 +58,9 @@ def make_settings():
rebound_entry_confidence=0.58,
rebound_min_probability=0.58,
rebound_max_position_usdt=6.0,
kelly_sizing_enabled=True,
kelly_fraction=0.25,
kelly_max_fraction=0.20,
time_series_forecast_enabled=True,
time_series_min_candles=120,
time_series_validation_window=30,
+31
View File
@@ -198,6 +198,37 @@ def test_strategy_activates_grid_and_sets_position_size(make_settings, tmp_path)
assert 1 <= signal.diagnostics["position_notional_usdt"] <= settings.grid_max_position_usdt
def test_strategy_uses_fractional_kelly_position_size(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path, max_position_usdt=20, kelly_fraction=0.25, kelly_max_fraction=0.20)
strategy = SpotStrategy(settings)
ticker = Ticker(
symbol="BTCUSDT",
last_price=101,
bid=100.99,
ask=101.01,
turnover_24h=10_000_000,
volume_24h=1000,
change_24h=1.0,
)
signal = strategy.entry_signal(
"BTCUSDT",
_ready_candles(),
ticker,
open_positions_for_symbol=0,
forecast={"usable": True, "probability_up": 0.70, "volatility_percent": 0.2},
account={"equity": 200.0},
)
sizing = signal.diagnostics["position_sizing"]
assert signal.action == "BUY"
assert sizing["method"] == "fractional_kelly"
assert sizing["kelly_probability_source"] == "forecast"
assert sizing["kelly_bankroll_usdt"] == 200.0
assert sizing["kelly_effective_fraction"] > 0
assert signal.diagnostics["position_notional_usdt"] == settings.max_position_usdt
def test_strategy_buys_probabilistic_rebound_after_stabilized_drop(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path, rebound_entry_confidence=0.58, rebound_min_probability=0.58)
strategy = SpotStrategy(settings)