diff --git a/tests/test_prepare_hourly.py b/tests/test_prepare_hourly.py index 68a3881..4450815 100644 --- a/tests/test_prepare_hourly.py +++ b/tests/test_prepare_hourly.py @@ -194,17 +194,14 @@ def test_ret_intrabar_formula(ph): assert abs(rib - expected) < 1e-6, f"ret_intrabar={rib:.8f}, expected={expected:.8f}" -# 10. build() in train.py uses 4 feature channels when hl_range + ret_intrabar present -def test_build_uses_4_channels(tmp_path): +# 10. build() in train.py uses 2 feature channels (HPO: hl_range/ret_intrabar redundant) +def test_build_uses_2_channels(tmp_path): import importlib.util, os hourly_path = "data/processed/eurusd_hourly.parquet" if not os.path.exists(hourly_path): pytest.skip("eurusd_hourly.parquet not present") - df = pd.read_parquet(hourly_path) - if "hl_range" not in df.columns: - pytest.skip("eurusd_hourly.parquet lacks hl_range — rebuild first") - spec = importlib.util.spec_from_file_location("train_4ch", "train.py") + spec = importlib.util.spec_from_file_location("train_2ch", "train.py") mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) (Xtr, _), _ = mod.build() - assert Xtr.shape[2] == 4, f"expected 4 channels, got {Xtr.shape[2]}" + assert Xtr.shape[2] == 2, f"expected 2 channels, got {Xtr.shape[2]}" diff --git a/train.py b/train.py index 803c0e0..2e1641f 100644 --- a/train.py +++ b/train.py @@ -154,10 +154,9 @@ def build(): else: df = pd.read_parquet(daily_path).reset_index(drop=True) df["date"] = pd.to_datetime(df["date"]) - # Use OHLCV-derived features when available; fall back to 2-channel - base_feats = ["ret", "realized_vol"] - extra_feats = [c for c in ["hl_range", "ret_intrabar"] if c in df.columns] - FEAT_COLS = base_feats + extra_feats + # 2-channel default (HPO: adding hl_range+ret_intrabar hurt — correlated with base feats) + # To experiment: change to ["ret", "realized_vol", "hl_range", "ret_intrabar"] + FEAT_COLS = ["ret", "realized_vol"] feats = df[FEAT_COLS].to_numpy(np.float32) target = df["realized_vol"].to_numpy(np.float32) tr_idx = df.index[df["date"].dt.year <= 2021].tolist()