"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(shadow): skip the entry-hour gate on daily bars
Robin1987Chinabb7a2cc00ee3
diff --git a/agent/src/shadow_account/templates/signal_engine.py.j2 b/agent/src/shadow_account/templates/signal_engine.py.j2index 61b829d2b..79e1d28f2 100644--- a/agent/src/shadow_account/templates/signal_engine.py.j2+++ b/agent/src/shadow_account/templates/signal_engine.py.j2@@ -94,6 +94,13 @@ class SignalEngine:ret_min = rule.get("prior_5d_return_min")ret_max = rule.get("prior_5d_return_max")+ # Daily (or coarser) bars share a single time-of-day, so an+ # entry-hour window mined from intraday journal fills carries no+ # information here — gating on it would reject every bar (daily+ # bars are typically stamped at midnight, before any market-hours+ # window). Enforce the window only on intraday data.+ intraday = len({pd.Timestamp(ts).time() for ts in index}) > 1+values = [0.0] * len(index)remaining_hold = 0@@ -103,9 +110,10 @@ class SignalEngine:remaining_hold -= 1continue- bar_hour = pd.Timestamp(index[i]).hour- if bar_hour < hour_min or bar_hour > hour_max:- continue+ if intraday:+ bar_hour = pd.Timestamp(index[i]).hour+ if bar_hour < hour_min or bar_hour > hour_max:+ continueif rsi_min is not None and rsi_max is not None:rsi_val = rsi.iloc[i]diff --git a/agent/tests/test_shadow_account.py b/agent/tests/test_shadow_account.pyindex ba22df910..3427b896f 100644--- a/agent/tests/test_shadow_account.py+++ b/agent/tests/test_shadow_account.py@@ -1708,3 +1708,62 @@ def test_conditional_entry_rsi_nan_bars_are_skipped() -> None:assert series.iloc[i] == 0.0, f"bar {i} should be zero (RSI warmup)"# At least one entry after warmup.assert (series.iloc[14:] > 0).any(), "no entry after RSI warmup"+++# ---- Daily-bar entry-hour window (mined from intraday journal fills) ----+++def test_daily_bars_ignore_mined_hour_window() -> None:+ """Market-hours window on midnight daily bars must not zero out the replay.++ Rules mined from real journals carry entry_hour bounds from actual fill+ times (e.g. 9-11). Daily bars are stamped at midnight, so gating on+ bar hour rejects every bar and the replay goes silently flat.+ """+ rule = _rule_with_rsi(0.0, 100.0, hour_min=9, hour_max=11)+ idx = _daily_index(periods=30)+ assert {pd.Timestamp(ts).hour for ts in idx} == {0} # midnight daily bars+ close = pd.Series(+ [10.0 + (i % 6) * 0.5 for i in range(30)], index=idx, dtype=float,+ )+ signals = _generate_signals(+ _profile(rule),+ {"600519.SH": pd.DataFrame({"close": close}, index=idx)},+ )+ series = signals["600519.SH"]+ assert (series > 0).any(), "daily replay must not be flat for market-hours rules"+++def test_intraday_bars_still_enforce_hour_window() -> None:+ """On intraday data the mined window keeps selecting entry bars."""+ rule = _rule_with_rsi(0.0, 100.0, hour_min=9, hour_max=11)+ idx = _hourly_index(periods=48) # 2 full days of hours+ close = pd.Series(+ [10.0 + (i % 6) * 0.5 for i in range(48)], index=idx, dtype=float,+ )+ signals = _generate_signals(+ _profile(rule),+ {"600519.SH": pd.DataFrame({"close": close}, index=idx)},+ )+ series = signals["600519.SH"]+ entry_hours = {pd.Timestamp(ts).hour for ts in series[series > 0].index}+ assert entry_hours, "expected entries within the window"+ assert entry_hours <= {9, 10, 11}+++def test_daily_bars_date_only_journal_window_still_enters() -> None:+ """Window {0, 0} mined from date-only journals keeps entering on daily bars."""+ rule = _rule_with_rsi(0.0, 100.0, hour_min=0, hour_max=0)+ idx = _daily_index(periods=30)+ close = pd.Series(+ [10.0 + (i % 6) * 0.5 for i in range(30)], index=idx, dtype=float,+ )+ signals = _generate_signals(+ _profile(rule),+ {"600519.SH": pd.DataFrame({"close": close}, index=idx)},+ )+ series = signals["600519.SH"]+ assert (series > 0).any(), "date-only journal window must still enter"