feat: market context: SPY regime, VIX and breadth in the report and on backtest rows - #105
Merged
Merged
Conversation
….market and on backtest rows The scan fetches SPY and ^VIX through the same download and cleaning as the universe, cut to the scanned bar, and computes the breadth of the universe (share of scanned symbols above their own SMA200). meta.market carries the index close, its distance from the SMA200, the SMA50's distance from the SMA200, the regime those name (bull, bear, neutral), the VIX and the breadth; the report header gets one line. A failed fetch leaves the fields null and the line names what is missing; nothing gates on the context. The backtest puts the regime, VIX, breadth and SPY-vs-SMA200 at the scan day on every row through the same market_series, adds a per-regime slice to every summary, and VIX and breadth to the feature buckets. Closes #93. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
6 tasks done
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.
Description
Implements #93. Informational only: nothing gates on the context.
MARKET_INDEX(SPY) andMARKET_VOL(^VIX) go through the samedownload_historyas the universe, cut to the scanned bar; breadth comes from the histories already downloaded (share of scanned symbols whose close is above their own 200-bar SMA, among those with 200 bars).meta.marketcarries the index close, its distance from the SMA200 and the SMA50's distance from the SMA200 in percent, the regime those name (bull: both above, bear: both below, neutral otherwise), the VIX close and the breadth. One header line in the report:Market: SPY 8.5 % above its SMA200, SMA50 > SMA200 (bull); VIX 14.5; 90% of 10 symbols above their SMA200.A failed fetch leaves the fieldsnulland the line names what is missing; it never fails the run.scan.market_series, so the scan and the replay define the context identically. Summaries gain a per-regime slice; VIX and breadth join the feature buckets. JSON gainsmarket_symbols.Verified locally:
ruffclean, 128 tests pass (4 new: series and context arithmetic including a bear-regime index, header line formatting and degradation, end to end with SPY and ^VIX in the fake yfinance, backtest rows and the regime slice). A 10-ticker real scan renders the header line andmeta.market; a 30-ticker two-year backtest with--splitshows the regime slices and the VIX and breadth buckets per window.Related Issues
Closes #93
Related: #101 (VIX below 15), #95 (multi-year replay before any rule)
Checklist
scan.py(two new constants, commented; no threshold changed)python -m pytest -q)docs/wiki/CHANGELOG.mdupdated🤖 Generated with Claude Code