Repository navigation
Fix lp_portfolio price alignment when ticker orders differ - #767
Open
kadyrbekovhamit-cyber wants to merge 1 commit into
Open
kadyrbekovhamit-cyber wants to merge 1 commit into
kadyrbekovhamit-cyber wants to merge 1 commit into
Conversation
Signed-off-by: kadyrbekovhamit-cyber <288885044+kadyrbekovhamit-cyber@users.noreply.github.com>
|
Read the diff against The
Nothing to change in the fix itself. |
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.
lp_portfoliopairs the weights in dictionary order withlatest_prices.valuesin Series order. When those orders differ, the returned share counts are attached to the wrong tickers, and the reported leftover can disagree with the cost of the returned allocation.For example, with a $10,000 budget:
Before this fix the allocation is
{'BBB': 500, 'AAA': 5}with zero leftover. Pricing that allocation by ticker costs $500,050. After the fix it is{'BBB': 5, 'AAA': 500}, which costs $10,000. This is a synthetic reproduction, not a report of executed trades or losses.Select prices by the weight tickers before constructing the optimization problem. No objective, solver policy or API change is needed. Tests cover both Series orders and a reversed price Series from the repository's stock-price fixture, checking the independent identity
sum(price[ticker] * shares) + leftover == budget.Validation on main
a6638d2e06dae6f444fd022cfd4b3c528902a85b:python -m pytest tests/test_discrete_allocation.py -q→ 20 passed.git diff --checkpasses.Prepared with AI assistance as part of GERO's numerical correctness work. The examples and tests were executed locally.