Skip to content

Guard against NaN currency codes in portfolio conversion#201

Merged
JerBouma merged 1 commit intoJerBouma:mainfrom
wavebyrd:fix/skip-nan-currency-conversion
Mar 13, 2026
Merged

Guard against NaN currency codes in portfolio conversion#201
JerBouma merged 1 commit intoJerBouma:mainfrom
wavebyrd:fix/skip-nan-currency-conversion

Conversation

@wavebyrd
Copy link
Copy Markdown

Summary

Fixes #197.

When a portfolio has no explicit currency column (or individual currency
values are missing/NaN), collect_historical_data builds a Yahoo Finance
symbol like NAN=X or USDNAN=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 currency
or 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 a pd.isna
    / falsy check on both currency and data_currency before building
    the =X pair, with a continue to skip the ticker.

Test plan

  • pytest tests/portfolio/test_portfolio_controller.py -- all 4 tests pass
  • pytest tests/test_currencies_model.py -- all 14 tests pass
  • Full portfolio + currencies suite (26 tests) passes cleanly

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
@JerBouma
Copy link
Copy Markdown
Owner

Looks good, linters and unit tests fail but I'll fix that another time. I'll do the release.

@JerBouma JerBouma merged commit 4cca791 into JerBouma:main Mar 13, 2026
1 of 3 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.

Portfolio currency conversion can construct NAN=X and break recordings

2 participants