SPB Git forge
1commits 1branches 0releases
189.0 KBsize
maindefault branch
4 h agolast push
Python 54.7% TypeScript 42.5% SQL 1.9%
1.0 KB · 27 lines python
Raw Blame History
1"""Causality proof: for every registered strategy, the target at bar t computed on data[:t+1] equals the target2computed on the full series. Any use of future rows (centered windows, shift(-k), global normalisation…) fails."""34import numpy as np5import pytest67from ktrade.strategy.registry import _REGISTRY8from tests.conftest import synthetic_candles91011@pytest.mark.parametrize("name", sorted(_REGISTRY))12def test_targets_are_causal(name):13    cls = _REGISTRY[name]14    df = synthetic_candles(n=700, seed=3)15    full = cls().run(df).target.to_numpy()16    for cut in (320, 450, 600, 699):17        part = cls().run(df.iloc[: cut + 1].copy()).target.to_numpy()18        assert np.allclose(np.nan_to_num(part), np.nan_to_num(full[: cut + 1]), atol=1e-9), f"{name}: look-ahead at bar {cut}"192021@pytest.mark.parametrize("name", sorted(_REGISTRY))22def test_targets_within_bounds(name):23    cls = _REGISTRY[name]24    t = cls().run(synthetic_candles(n=400, seed=5)).target25    lo = -1.0 if cls.meta.allows_short else 0.026    assert ((t >= lo - 1e-12) & (t <= 1.0 + 1e-12)).all()27