fix(engine): last_px 覆蓋全部持倉標的,不只 round-trip (closes #79)#83
Merged
Conversation
…closes #79) last_px 原本只在 fwd_from_px 的 round-trip 迴圈裡填——持有中、從未平倉的 標的(往往是最大倉位)被結構性排除:未實現損益/套牢診斷/what-if 全部靜默漏算。 sample_value.csv 實測:unrealized $204 → $46,406(修前漏掉的 INTC 一檔就 +$41,697), what_if 從誤導的「汽車板塊 $2k」變成正確的「半導體板塊 $54k」。 - 拆出 last_prices(data):對價格框全部欄位(rts ∪ held ∪ benchmark)填最新價; fwd 計算保持只掃 rts,簽名/回傳不變,呼叫端零改動 - staleness gate(codex review 抓的):最後有效價距框末日 >10 日曆日不當現價, 下市/停牌殭屍持倉降級成本基礎——殘價餵進未實現損益比「判不出」更糟 - 新增離線回歸測試(合成 DataFrame,不碰 yfinance):held-only 標的的 last_px/ unrealized/what_if/ticker_diagnosis + 殭屍殘價 gate;突變驗證非假綠燈 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 4, 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.
問題(#79)
fwd_from_px只for r in rts填last_px→ 持有中、從未平倉的標的拿不到現價,無論 yfinance 成功與否。sample_value.csv 的 5 檔持倉只有 F 曾部分平倉,佔 cost basis 43% 的 INTC 完全不在last_px:overview.unrealizedticker_diagnosiswhat_if修法
last_prices(data):對價格框全部欄位填最新價。抓價清單本來就是rts ∪ held ∪ benchmark(main:1325 + fetch_prices),之前只是把抓到的價白白丟掉。fwd_from_px簽名/回傳不變,呼叫端零改動。dim_size/dim_diversify/dim_avgdown/overview_stats/what_if/ticker_diagnosis/build_state)都以held/rts為主 key 查表。測試
test_last_px_covers_held_only_tickers(tests/test_price_paths.py):合成 DataFrame 離線確定性,斷言 held-only 標的的last_px/unrealized/what_if/ticker_diagnosis四層 + 殭屍殘價 gate。last_px初始化改回{}→ 測試轉紅(BBB 實得 None),非假綠燈。python3 tests/run_all.py全 5 套通過。與 #64 的邊界
#64 是 yfinance 失敗時 fallback 導致同輪混用成本/市值基礎;本修是設計上只掃 rts 的結構性排除,連網成功也重現。本 PR 不動 #64 的 fallback 語意。
🤖 Generated with Claude Code