Retire completed GTL tuning harnesses
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
from datetime import date, timedelta
|
||||
from types import SimpleNamespace
|
||||
@@ -804,8 +803,6 @@ def test_sr_research_variant_is_explicit_and_validated(monkeypatch):
|
||||
"rewrite_range504_structural_primary2",
|
||||
"production_structural_overlay",
|
||||
"explicit_target_ladder",
|
||||
"gtl_tuning",
|
||||
"gtl_confirmation",
|
||||
):
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", variant)
|
||||
assert bt._sr_research_variant() == variant
|
||||
@@ -864,48 +861,6 @@ 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
|
||||
assert bt._primary_min_rr_for_variant("gtl_confirmation", 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_gtl_confirmation_config_parses_and_validates_composition():
|
||||
config = bt._parse_gtl_confirmation_config(json.dumps({
|
||||
"name": "touch_strength_intersection",
|
||||
"mode": "intersection",
|
||||
"confirmations": [
|
||||
{"name": "touch", "touch_tolerance": 0.0025},
|
||||
{"name": "strength", "strength_scale": 1000.0},
|
||||
],
|
||||
}))
|
||||
assert config.name == "touch_strength_intersection"
|
||||
assert config.mode == "intersection"
|
||||
assert len(config.confirmations) == 2
|
||||
assert config.confirmations[0].touch_tolerance == 0.0025
|
||||
assert config.confirmations[1].strength_scale == 1000.0
|
||||
|
||||
with pytest.raises(ValueError, match="exactly one tuned variant"):
|
||||
bt._parse_gtl_confirmation_config(json.dumps({
|
||||
"name": "invalid_union",
|
||||
"mode": "union",
|
||||
"confirmations": [],
|
||||
}))
|
||||
|
||||
|
||||
def test_structural_overlay_tags_production_geometry_without_replacing_it(monkeypatch):
|
||||
@@ -1017,116 +972,6 @@ 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
|
||||
|
||||
|
||||
def test_gtl_confirmation_intersection_keeps_control_geometry(monkeypatch):
|
||||
production = [{
|
||||
"direction": "long",
|
||||
"target": 111.0,
|
||||
"rr": 2.2,
|
||||
"meets_core": True,
|
||||
"sr_variant": bt.EXPLICIT_TARGET_LADDER_VARIANT,
|
||||
}]
|
||||
|
||||
def fake_window_setups(*args, sr_variant=None, gtl_research_config=None, **kwargs):
|
||||
if sr_variant == bt.EXPLICIT_TARGET_LADDER_VARIANT:
|
||||
return production
|
||||
assert sr_variant == bt.GTL_TUNING_VARIANT
|
||||
return [{
|
||||
"direction": "long",
|
||||
"target": 115.0,
|
||||
"rr": 3.0,
|
||||
"meets_core": gtl_research_config.name == "pass",
|
||||
}]
|
||||
|
||||
monkeypatch.setattr(bt, "_window_setups", fake_window_setups)
|
||||
research = bt.GTLConfirmationConfig(
|
||||
name="two_filters",
|
||||
mode="intersection",
|
||||
confirmations=(
|
||||
bt.GTLResearchConfig(name="pass"),
|
||||
bt.GTLResearchConfig(name="fail"),
|
||||
),
|
||||
)
|
||||
rows = bt._gtl_confirmation_window_setups(
|
||||
[], {}, {}, confirmation_config=research
|
||||
)
|
||||
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["target"] == 111.0
|
||||
assert rows[0]["rr"] == 2.2
|
||||
assert rows[0]["meets_core"] is False
|
||||
assert rows[0]["gtl_confirmation_passes"] == [True, False]
|
||||
assert production[0]["meets_core"] is True
|
||||
|
||||
|
||||
def test_gtl_confirmation_union_uses_tuned_geometry_only_for_addition(monkeypatch):
|
||||
production = [
|
||||
{"direction": "long", "target": 111.0, "meets_core": False},
|
||||
{"direction": "short", "target": 90.0, "meets_core": True},
|
||||
]
|
||||
tuned = [
|
||||
{"direction": "long", "target": 115.0, "meets_core": True},
|
||||
{"direction": "short", "target": 85.0, "meets_core": False},
|
||||
]
|
||||
|
||||
def fake_window_setups(*args, sr_variant=None, **kwargs):
|
||||
return production if sr_variant == bt.EXPLICIT_TARGET_LADDER_VARIANT else tuned
|
||||
|
||||
monkeypatch.setattr(bt, "_window_setups", fake_window_setups)
|
||||
research = bt.GTLConfirmationConfig(
|
||||
name="strength_union",
|
||||
mode="union",
|
||||
confirmations=(bt.GTLResearchConfig(name="strength"),),
|
||||
)
|
||||
rows = bt._gtl_confirmation_window_setups(
|
||||
[], {}, {}, confirmation_config=research
|
||||
)
|
||||
by_direction = {row["direction"]: row for row in rows}
|
||||
|
||||
assert by_direction["long"]["target"] == 115.0
|
||||
assert by_direction["long"]["gtl_confirmation_source"] == "tuned_addition"
|
||||
assert by_direction["short"]["target"] == 90.0
|
||||
assert by_direction["short"]["gtl_confirmation_source"] == "control"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"variant",
|
||||
["legacy_geometry_neutral", "legacy_range_grid_neutral"],
|
||||
|
||||
Reference in New Issue
Block a user