fix: dividend yield was nulled for every company - #20
Merged
Conversation
yfinance reports dividendYield as a percent (1.61 means 1.61%), but ratios.py filtered it as a fraction with a <=0.15 bound, so every real yield -- even a 0.3% one -- was dropped to None and never appeared in a report. Confirmed against live data across yfinance 1.5.1: HDFC Bank 1.61, ITC 5.73, AAPL 0.32, all discarded by the old filter. _dividend_yield now prefers the fields that are unambiguous across yfinance versions rather than guessing dividendYield's scale: trailingAnnualDividendYield (a decimal fraction), then dividendRate/price (a computed fraction, which matches the trailing figure in practice), and only falls back to dividendYield normalized from percent. Any candidate outside a sane 0-30% band is rejected. The figure is now shown in the research note's valuation grid, where the high-yield Indian names this tool targets (ITC 5.2%, Coal India 6.2%, ONGC, IOC) previously showed blank. Six offline tests pin the field shapes from real fetches. No scoring or Buffett logic keys off dividend yield, so nothing reprices.
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.
The follow-up bug I flagged after the RFC series — now confirmed against live data and fixed.
The bug
yfinance reports
dividendYieldas a percent (1.61= 1.61%), butratios.pyfiltered it as a fraction with a0 <= y <= 0.15bound. So every real yield was nulled — even AAPL's0.32exceeds0.15. Dividend yield came backNonefor every company and never appeared in any report.Confirmed live (yfinance 1.5.1), and cross-checked against
dividendRate / priceas ground truth:dividendYield(raw)trailingAnnualDividendYieldNoneNoneNoneNoneThe fix
Rather than guess
dividendYield's scale (which has flipped between fraction and percent across yfinance versions),_dividend_yieldprefers the fields that are unambiguous:trailingAnnualDividendYield— a decimal fraction, stable across versions.dividendRate / price— a computed fraction (matches the trailing figure in practice).dividendYield— last resort, normalized from percent.Any candidate outside a sane 0–30% band is rejected as an anomaly. The figure now appears in the research note's valuation grid — where the high-yield Indian names this tool exists to analyze (ITC, Coal India, ONGC, IOC) previously showed blank.
Verification
ruff+mypyclean; 269 tests pass (263 + 6 new). The new tests use the actual field shapes from live fetches, so a future yfinance scale-flip would be caught. Live check:investo analyze "ITC" --htmlnow renders Dividend yield 5.2%.No repricing: grep confirms nothing in scoring/Buffett/thesis keys off
dividend_yield— it's display-only, so no scores move.