Use Torch forecast as primary strategy

This commit is contained in:
Codex
2026-06-22 05:21:05 +03:00
parent 85fecbfc36
commit 544b0f4409
9 changed files with 374 additions and 20 deletions
+75
View File
@@ -233,6 +233,81 @@ def test_trend_macd_exits_on_atr_trailing_stop(make_settings, tmp_path) -> None:
assert "ATR trailing" in signal.reason
def test_torch_forecast_buys_only_from_positive_torch_edge(make_settings, tmp_path) -> None:
settings = make_settings(
tmp_path,
strategy_mode="torch_forecast",
max_position_usdt=25,
stop_loss_percent=0.04,
risk_per_trade_percent=0.01,
)
strategy = SpotStrategy(settings)
ticker = Ticker("BTCUSDT", 105, 104.99, 105.01, 10_000_000, 1000, 1.0)
signal = strategy.entry_signal(
"BTCUSDT",
[],
ticker,
open_positions_for_symbol=0,
forecast={
"usable": True,
"model": "torch_gru",
"expected_return_percent": 0.24,
"probability_up": 0.63,
"skill": 0.22,
"block_entry": False,
},
account={"equity": 100.0},
)
assert signal.action == "BUY"
assert signal.diagnostics["strategy_mode"] == "torch_forecast"
assert signal.diagnostics["checks"]["torch_model_ok"] is True
assert signal.diagnostics["position_notional_usdt"] == 25.0
def test_torch_forecast_blocks_without_valid_torch_model(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path, strategy_mode="torch_forecast")
strategy = SpotStrategy(settings)
ticker = Ticker("ETHUSDT", 105, 104.99, 105.01, 10_000_000, 1000, 1.0)
signal = strategy.entry_signal(
"ETHUSDT",
_trend_entry_candles(),
ticker,
open_positions_for_symbol=0,
forecast={"usable": True, "model": "none", "expected_return_percent": 0.5, "probability_up": 0.7},
account={"equity": 100.0},
)
assert signal.action == "HOLD"
assert signal.diagnostics["checks"]["torch_model_ok"] is False
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)
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 == "SELL"
assert "torch_forecast" in signal.reason
def test_strategy_emits_buy_when_score_passes_threshold(make_settings, tmp_path) -> None:
settings = make_settings(tmp_path)
strategy = SpotStrategy(settings)