Keep bot operational when forecast model is unavailable

This commit is contained in:
Курнат Андрей
2026-07-13 11:57:25 +03:00
parent da53483164
commit 668e606ee2
22 changed files with 706 additions and 73 deletions
+26
View File
@@ -334,6 +334,29 @@ def test_time_series_forecaster_uses_symbol_calibration(make_settings, tmp_path)
assert forecast.calibrated_min_confidence == 0.45
def test_time_series_forecaster_blocks_symbol_outside_train_only_allowlist(make_settings, tmp_path) -> None:
artifact_path = tmp_path / "lstm_forecaster.json"
_write_torch_gru_artifact(artifact_path, head_bias=0.2)
(tmp_path / "torch_threshold_calibration.json").write_text(
json.dumps(
{
"validation": {"status": "pass", "passed": True},
"eligible_symbols": ["ETHUSDT"],
}
),
encoding="utf-8",
)
settings = make_settings(tmp_path, time_series_lstm_model_path=artifact_path)
forecast = TimeSeriesForecaster(settings).forecast(
_candles_from_returns([0.0001] * 140), symbol="BTCUSDT"
)
assert forecast.usable is True
assert forecast.block_entry is True
assert forecast.reason == "symbol excluded by train-only calibration"
def test_time_series_forecaster_averages_ensemble_members(make_settings, tmp_path) -> None:
artifact_path = tmp_path / "lstm_forecaster.json"
_write_torch_gru_artifact(artifact_path, head_bias=0.9)
@@ -343,6 +366,9 @@ def test_time_series_forecaster_averages_ensemble_members(make_settings, tmp_pat
{"state_dict": entry["state_dict"], "head_weight": [0.0, 0.0], "head_bias": bias}
for bias in (0.1, 0.3)
]
entry.pop("state_dict")
entry.pop("head_weight")
entry.pop("head_bias")
artifact_path.write_text(json.dumps(artifact), encoding="utf-8")
settings = make_settings(
tmp_path,