feat(engine): 市場背景注入 — SPY/QQQ/VIX 週漲跌進復盤卡 (refs #37)#145
Merged
Conversation
- engine/market_context.py (new): thin fetch layer (yfinance, honest degradation offline/uninstalled — error field, never crashes the main flow) + pure compute layer (zero-pandas, offline-testable) window_ret = prev-close-before-window -> last close in window; ytd_ret anchored at last close of prior year; VIX as level (last/prev/ delta), never treated as an asset return - SKILL.md Step 1: run after main engine; window = last log date_end -> state date_end (reconcile) or 7d back (first run); three uses — card header line, attribution context, Step 2 motive auxiliary signal (FOMO-candidate on up-week entries); account-vs-SPY numeric relative perf explicitly out of scope (needs weekly NAV series, #37 stays open) - card-spec.md: 〔市場那週〕context line in template (data-present only, offline -> line absent, never fabricated) - tests/test_market_context.py (new, suite 8): anchors, VIX level, honest-absence, unsorted input, single-day window, CLI arg guards, TR_TEST_NETWORK smoke; run_all.py + CLAUDE.md mirrors 七套->八套 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ardening Codex (stub-verified findings, all adopted): - build_output gains 'missing': partial symbol absence leaves error=None, callers must not assume all three benchmarks exist; SKILL/card-spec now say render-what-you-have, skip the absent ones - fetch parse wrapped in error-degradation (missing Close -> error, never raises: the never-crash header contract); single-symbol Series shape no longer probed via .get(sym) (would silently query the date index) - deterministic fake-yfinance tests: MultiIndex+NaN-column, Series shape, missing-Close, download-raise — fetch layer no longer covered only by the optional network smoke - cross-year window semantics locked by test (window_ret and ytd_ret may legitimately diverge in sign — correct but unintuitive, pin it) Gemini: two stale 七套 mirrors outside CLAUDE.md (pre_commit_test_gate.sh comment+deny message, prd-ledger.md PR checklist) — reworded count-free so the next suite addition cannot drift them again Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner
Author
Triad Review — PR #145(文本模式:Claude / Codex / Gemini)審查焦點:compute 錨點語意(跨年/單日/缺錨)、yfinance 回傳形狀容錯、離線退化契約、鏡像同步。
|
3 tasks
This was referenced Jul 7, 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.
這個 PR 做什麼
#129 次線執行序順序 3(#37):卡只有「你做了什麼」,沒有「市場那週在幹嘛」——虧 3% 是選錯股還是大盤本來就跌 3%?買在高點還是買在 QQQ +5% 的相對強勢週?
engine/market_context.py(新,獨立 CLI)
error欄誠實退化,絕不 crash 主流程(對齊 fetch_fx/fetch_prices 既有模式)。compute_context):吃{symbol: [(date, close)...]},零 pandas 依賴,離線可測。window_ret= 窗口前收→窗口末收;ytd_ret錨在去年最後收盤;VIX 是水平值(last/prev/delta),不當資產報酬;缺錨 → null 不硬算;窗口內沒價的 symbol 誠實缺席。SKILL.md + card-spec.md
測試(第八套)
窗口/YTD 錨點、VIX 水平值、缺資料誠實缺席、亂序輸入、單日窗口、CLI 參數防呆、TR_TEST_NETWORK smoke。run_all.py + CLAUDE.md 鏡像「七套→八套」同步。
掃過的範圍
測試結果
離線八套全綠;TR_TEST_NETWORK=1 smoke 過。
refs #37(語境版落地;數字級 relative perf 留 open)
🤖 Generated with Claude Code