Add single-command GTL tuning matrix
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
from datetime import date, timedelta
|
||||
from types import SimpleNamespace
|
||||
@@ -803,6 +804,7 @@ def test_sr_research_variant_is_explicit_and_validated(monkeypatch):
|
||||
"rewrite_range504_structural_primary2",
|
||||
"production_structural_overlay",
|
||||
"explicit_target_ladder",
|
||||
"gtl_tuning",
|
||||
):
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", variant)
|
||||
assert bt._sr_research_variant() == variant
|
||||
@@ -861,6 +863,24 @@ def test_residual_arms_change_only_the_primary_rr_floor():
|
||||
"explicit_target_ladder",
|
||||
activation,
|
||||
) == 1.5
|
||||
assert bt._primary_min_rr_for_variant("gtl_tuning", activation) == 1.5
|
||||
|
||||
|
||||
def test_gtl_research_config_parses_and_rejects_unknown_fields():
|
||||
config = bt._parse_gtl_research_config(json.dumps({
|
||||
"name": "lookback_504",
|
||||
"lookback_bars": 504,
|
||||
"candidate_limit": None,
|
||||
}))
|
||||
assert config.name == "lookback_504"
|
||||
assert config.lookback_bars == 504
|
||||
assert config.candidate_limit is None
|
||||
assert config.ladder_config().grid_bins == 20
|
||||
|
||||
with pytest.raises(ValueError, match="Unknown GTL research config fields"):
|
||||
bt._parse_gtl_research_config('{"mystery_knob": 1}')
|
||||
with pytest.raises(ValueError, match="valid JSON"):
|
||||
bt._parse_gtl_research_config("{")
|
||||
|
||||
|
||||
def test_structural_overlay_tags_production_geometry_without_replacing_it(monkeypatch):
|
||||
@@ -972,6 +992,45 @@ def test_window_setups_routes_full_explicit_target_ladder(monkeypatch):
|
||||
}
|
||||
|
||||
|
||||
def test_window_setups_routes_gtl_tuning_config(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
def fake_detector(highs, lows, closes, *, config):
|
||||
captured.update({
|
||||
"highs": highs,
|
||||
"lows": lows,
|
||||
"closes": closes,
|
||||
"config": config,
|
||||
})
|
||||
return []
|
||||
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", bt.GTL_TUNING_VARIANT)
|
||||
monkeypatch.setenv("BACKTEST_GTL_CONFIG", json.dumps({
|
||||
"name": "lookback_252",
|
||||
"lookback_bars": 252,
|
||||
"grid_bins": 12,
|
||||
}))
|
||||
monkeypatch.setattr(bt, "detect_gate_target_ladder", fake_detector)
|
||||
records = [
|
||||
SimpleNamespace(
|
||||
date=date(2024, 1, 1) + timedelta(days=i),
|
||||
open=100.0,
|
||||
high=101.0,
|
||||
low=99.0,
|
||||
close=100.0,
|
||||
volume=1_000_000,
|
||||
)
|
||||
for i in range(bt.MIN_LOOKBACK)
|
||||
]
|
||||
|
||||
assert bt._window_setups(records, {}, {}) == []
|
||||
assert captured["highs"] == [101.0] * bt.MIN_LOOKBACK
|
||||
assert captured["lows"] == [99.0] * bt.MIN_LOOKBACK
|
||||
assert captured["closes"] == [100.0] * bt.MIN_LOOKBACK
|
||||
assert captured["config"].lookback_bars == 252
|
||||
assert captured["config"].grid_bins == 12
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"variant",
|
||||
["legacy_geometry_neutral", "legacy_range_grid_neutral"],
|
||||
|
||||
Reference in New Issue
Block a user