Guard against NaN currency codes in portfolio conversion#201
Merged
JerBouma merged 1 commit intoJerBouma:mainfrom Mar 13, 2026
Merged
Guard against NaN currency codes in portfolio conversion#201JerBouma merged 1 commit intoJerBouma:mainfrom
JerBouma merged 1 commit intoJerBouma:mainfrom
Conversation
When the portfolio has no currency column (or a currency value is missing/NaN), the conversion loop would build a symbol like "NAN=X" and send it to Yahoo Finance, which returns a 404. Skip the conversion step for any ticker where either the transaction currency or the historical-data currency is missing or NaN. Fixes JerBouma#197
Owner
|
Looks good, linters and unit tests fail but I'll fix that another time. I'll do the release. |
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.
Summary
Fixes #197.
When a portfolio has no explicit currency column (or individual currency
values are missing/NaN),
collect_historical_databuilds a Yahoo Financesymbol like
NAN=XorUSDNAN=X. Yahoo returns a 404 for these,which blanks out Current Value / Return / Alpha in recorded CSVs.
This PR adds a guard in the currency-conversion loop inside
Portfolio.collect_historical_data(): if either the transaction currencyor the historical-data currency is missing, empty, or NaN, the ticker is
skipped instead of constructing a bogus symbol.
Changes
financetoolkit/portfolio/portfolio_controller.py-- added apd.isna/ falsy check on both
currencyanddata_currencybefore buildingthe
=Xpair, with acontinueto skip the ticker.Test plan
pytest tests/portfolio/test_portfolio_controller.py-- all 4 tests passpytest tests/test_currencies_model.py-- all 14 tests pass