Test: lock in risk-off regime guard blocking new buys - #24
Open
claude[bot] wants to merge 1 commit into
Open
Conversation
Today's issue #23 snapshot (2026-07-21) showed 40 BUY signals with 0 existing positions and 0 trades under a risk-off NIFTY regime. That matches the intended market_regime_guard behavior in paper_trader.py, but no test asserted it directly (only indirect coverage via a same-day snapshot-replacement test with an existing position). Add a dedicated regression test for the exact scenario: risk-off regime + BUY targets + no existing positions -> zero new orders queued.
This was referenced Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Today's daily post-market refinement review of issue #23 (2026-07-21 snapshot) investigated three data points to see if any code change was justified:
momentum_weekly_churn_control__news_onbacktest variant is byte-identical tomomentum_only_weekly.min_trading_daysandbacktest_oos_positiveat day 2/20.Investigation verdict: all three are expected, documented design, not bugs.
src/news_archive.py, added 2026-07-19) only started accumulating 2 days ago, so it has zero coverage over the historical backtest replay window.ablation_verdict()insrc/news_ablation.pycorrectly reportsinsufficient_datawhenevernews_days_used <= 0— this is called out explicitly in that module's own comments and will self-resolve as the archive accumulates days.src/daily_analysis.pytags BUY/HOLD/SELL for display only; the actual gate isUSE_MARKET_REGIME_GUARDinsrc/paper_trader.py(~line 611-617), which setsrisk_block_new_buys = Truewheneverregime.get("risk_on")isFalse, regardless of signal count. With 0 existing positions, there is also nothing to sell, so 0 trades total is correct — this matches the documented intent insrc/market_regime.py("bot should not force new risk when the broad market trend is weak").min_trading_daysis a plain day-count gate (MIN_TRADING_DAYS = 20) that fails by construction at day 2.backtest_oos_positiveindependently requires ≥2 of 3 walk-forward folds positive (src/incubation_report.py); today's artifact shows only 1/3 folds positive, so the gate is correctly protecting against a strategy whose OOS edge is driven by a single lucky fold.Since no bug exists, per the refinement rules no strategy/behavior change is warranted. However, the investigation found one real gap: there was no dedicated unit test proving that the risk-off regime guard actually blocks new BUY orders — existing coverage (
test_post_close_run_replaces_preliminary_same_day_snapshot) only setsrisk_on: Falseincidentally, while testing an unrelated snapshot-replacement path with an existing position, and never asserts new-buy blocking.Change
Adds
test_market_regime_risk_off_blocks_new_buystotests/test_paper_trader.py, modeled on the existingtest_circuit_breaker_blocks_new_buys_but_allows_stop_sellstest. It reproduces today's exact scenario (risk-off regime, BUY-ranked candidates, 0 existing positions) and asserts:risk_block_new_buysis set on the snapshot.This is test-only — no strategy parameters, execution logic, or trading behavior changed. Paper-trading only; the one-month incubation rule and readiness gate are untouched.
Validation
Ran 83 tests (up from 82), 1 pre-existing unrelated failure (
test_news_archivefails to import due to a missingrequestspackage in this sandbox — confirmed present onmainbefore this change viagit stash, not introduced by this PR). All other tests pass, including the new one.Expected effect on readiness gate
None. This is a test-coverage addition only; it does not change
min_trading_days,backtest_oos_positive, or any other incubation check, and does not touch trade execution logic.Closes #23