Skip to content

fix: dividend yield was nulled for every company - #20

Merged
YashvantHange merged 1 commit into
mainfrom
fix/dividend-yield
Jul 18, 2026
Merged

fix: dividend yield was nulled for every company#20
YashvantHange merged 1 commit into
mainfrom
fix/dividend-yield

Conversation

@YashvantHange

Copy link
Copy Markdown
Owner

The follow-up bug I flagged after the RFC series — now confirmed against live data and fixed.

The bug

yfinance reports dividendYield as a percent (1.61 = 1.61%), but ratios.py filtered it as a fraction with a 0 <= y <= 0.15 bound. So every real yield was nulled — even AAPL's 0.32 exceeds 0.15. Dividend yield came back None for every company and never appeared in any report.

Confirmed live (yfinance 1.5.1), and cross-checked against dividendRate / price as ground truth:

Ticker dividendYield (raw) trailingAnnualDividendYield rate/price Old result New result
HDFC Bank 1.61 0.0161 1.59% None 1.61%
ITC 5.73 0.0519 5.7% None 5.2%
Coal India 5.15 0.0620 5.14% None 6.2%
AAPL 0.32 0.0031 0.32% None 0.31%

The fix

Rather than guess dividendYield's scale (which has flipped between fraction and percent across yfinance versions), _dividend_yield prefers the fields that are unambiguous:

  1. trailingAnnualDividendYield — a decimal fraction, stable across versions.
  2. dividendRate / price — a computed fraction (matches the trailing figure in practice).
  3. 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 + mypy clean; 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" --html now 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.

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.
@YashvantHange
YashvantHange merged commit 39b2440 into main Jul 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant