Skip to content

Fix Portfolio Optimizer failing on mixed datetime resolutions between prices and FX closes - #248

Merged
alfwro13 merged 1 commit into
mainfrom
fix-fx-merge-asof-dtype
Oct 11, 2026
Merged

alfwro13 merged 1 commit into
mainfrom
fix-fx-merge-asof-dtype

Conversation

@alfwro13

@alfwro13 alfwro13 commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Portfolio Optimizer run failed with MergeError: incompatible merge keys [0] dtype('<M8[us]') and dtype('<M8[ms]') raised from fx_conversion_helpers.fx_levels_on().
  • Cause: under pandas 3 the X-ray return dates (parsed from stored strings) are datetime64[us], while the FX closes read back from Parquet are datetime64[ms]; merge_asof requires identical key dtypes.
  • Fix: align the FX index to the dates' resolution before the merge, building the right-hand frame without mutating the in-memory cached FX series. Same helper serves the Strategy Backtester, so its currency conversion is covered too.

Test plan

  • pytest tests/test_fx_conversion_helpers.py tests/test_portfolio_optimizer_engine.py tests/test_fx_drag_engine.py tests/test_accounts_engine.py tests/test_strategy_backtest_engine.py tests/test_strategy_backtest_runs.py
  • New tests fail on the previous code (13 failures) and pass with the fix: all s/ms/us/ns date/FX resolution pairs, plus an end-to-end returns_in_base case with string-parsed dates against millisecond FX

… prices and FX closes

fx_levels_on() passed merge_asof a us-resolution date key and a ms-resolution FX index (Parquet-read closes vs dates parsed from stored strings under pandas 3), which pandas rejects as incompatible merge keys. The FX index is now aligned to the dates' resolution before the merge, without mutating the cached FX series.
@alfwro13
alfwro13 merged commit 60b65c2 into main Oct 11, 2026
5 checks passed
@alfwro13
alfwro13 deleted the fix-fx-merge-asof-dtype branch October 11, 2026 18:31
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