Prevent torch forecast fee churn exits

This commit is contained in:
Codex
2026-06-30 14:37:00 +03:00
parent 0cfd89980e
commit 56701d02f1
2 changed files with 99 additions and 5 deletions
+72 -2
View File
@@ -826,7 +826,18 @@ def test_torch_forecast_rebound_fallback_can_be_disabled(make_settings, tmp_path
def test_torch_forecast_exits_when_forecast_turns_negative(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path, strategy_mode="torch_forecast", stop_loss_percent=0.04)
strategy = SpotStrategy(settings)
position = Position(1, "SOLUSDT", 1, 100, 100, 0.1, 96, 120, 103)
position = Position(
1,
"SOLUSDT",
1,
100,
100,
0.1,
96,
120,
103,
opened_at=utc_now() - timedelta(seconds=600),
)
ticker = Ticker("SOLUSDT", 101, 100.99, 101.01, 10_000_000, 1000, 1.0)
signal = strategy.exit_signal(
@@ -844,7 +855,66 @@ def test_torch_forecast_exits_when_forecast_turns_negative(make_settings, tmp_pa
)
assert signal.action == "SELL"
assert "torch_forecast" in signal.reason
assert "прогноз" in signal.reason
def test_torch_forecast_holds_negative_forecast_during_min_hold(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path, strategy_mode="torch_forecast", min_hold_seconds=180)
strategy = SpotStrategy(settings)
position = Position(1, "SOLUSDT", 1, 100, 100, 0.1, 96, 120, 103)
ticker = Ticker("SOLUSDT", 101, 100.99, 101.01, 10_000_000, 1000, 1.0)
signal = strategy.exit_signal(
position,
_trend_entry_candles(),
ticker,
forecast={
"usable": True,
"model": "torch_lstm",
"expected_return_percent": -0.08,
"probability_up": 0.43,
"skill": 0.18,
"block_entry": True,
},
)
assert signal.action == "HOLD"
assert signal.diagnostics["forecast_exit_blocked_by_min_hold"] is True
def test_torch_forecast_holds_fee_churn_exit_after_min_hold(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path, strategy_mode="torch_forecast", min_hold_seconds=60)
strategy = SpotStrategy(settings)
position = Position(
1,
"BTCUSDT",
1,
100,
100,
0.1,
96,
120,
100.1,
opened_at=utc_now() - timedelta(seconds=600),
)
ticker = Ticker("BTCUSDT", 99.99, 99.98, 100.0, 10_000_000, 1000, 1.0)
signal = strategy.exit_signal(
position,
_trend_entry_candles(),
ticker,
forecast={
"usable": True,
"model": "torch_lstm",
"expected_return_percent": -0.01,
"probability_up": 0.499,
"skill": 0.18,
"block_entry": False,
},
)
assert signal.action == "HOLD"
assert signal.diagnostics["forecast_exit_blocked_by_cost"] is True
def test_torch_forecast_rebound_fallback_holds_without_model(make_settings, tmp_path) -> None: