Skip to content

Conversation

@luciaxoll
Copy link

Changes were made to address Issue #2593:

  1. Added _sanitize_price_to_book() helper method in quote.py (lines 614-631). This method detects when currency and financialCurrency fields differ in the info dictionary. When mismatched currencies are detected AND priceToBook exists, it sets priceToBook to None. This prevents propagating invalid price-to-book ratios caused by Yahoo's backend computing ratios with mismatched currencies. Other fields (currentPrice, bookValue, currency, financialCurrency) remain unchanged

  2. Integrated sanitization call in _fetch_info() method (line 690). After the info dictionary is fully populated and formatted, _sanitize_price_to_book() is called. This ensures all raw data from Yahoo is processed for currency mismatches before being returned to users.

  3. Added regression test in test_ticker.py (lines 1054-1129).

Test Results: All key tests pass:

@ValueRaider
Copy link
Collaborator

Why is priceToBook useless when FX different? User can't do FX conversion?

@luciaxoll
Copy link
Author

Thanks for the reply!

It’s not that users can’t do FX conversion – it’s that the ratio we expose isn’t a standard P/B anymore once the currencies differ. In the case of Issue #2593, priceToBook is literally “price in INR ÷ book value in USD,” which doesn’t match Yahoo’s own UI or any conventional definition of P/B. To “fix” it, a user would need to know exactly which currency bookValue is in, which FX rate/date to use, and whether Yahoo has already transformed it upstream – none of that is available in the API (described in the Issue comment). So the 573× value is just a misleading artifact.

So my idea is that for now: if we detect mixed currencies, we return None but still expose currentPrice, bookValue, currency, and financialCurrency so users can apply their own FX logic if they want.

Hopefully this clarifies things a bit.

@ValueRaider
Copy link
Collaborator

ValueRaider commented Dec 2, 2025

a user would need to know exactly which currency bookValue is in

Surely it the financial currency? Book is financial.

Can the sanitize be optional via an argument, e.g like I do with prices: history(..., repair=True)

Bigger picture, the info fetch needs a rethink - in this merge there are other data issues (I've added some debug checks)

processed_info = {}
for k, v in query1_info.items():
# Handle nested dictionary
if isinstance(v, dict):
for k1, v1 in v.items():
if v1 is not None:
processed_info[k1] = 86400 if k1 == "maxAge" and v1 == 1 else v1
elif v is not None:
processed_info[k] = v

Value mismatch: 'defaultKeyStatistics'['forwardPE'] = '20.81062', but already seen it with value '21.584623'
Value mismatch: 'dividendYield' = '2.88', but already seen it with value '0.028800001'

Interested?

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.

2 participants