Fix Depot Transfer Cost Basis#73
Open
ma4nn wants to merge 3 commits into
Open
Conversation
|
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
This is a follow-up PR for #59 to separate the multiple changes in that PR into single ones.
It teaches the FIFO cost-basis engine to respect Portfolio Performance depot transfers. On a linked
TRANSFER_OUT/TRANSFER_INpair, the cost-basis lot is relocated from the source to the destination account, preserving original acquisition date, price, and (prorated) fees — so per-account cost basis,view securities, andsimulate share-sellstay correct after transfers.cost_basis.py): relocate lots on linked transfers; split + prorate on partial transfers; destinationconsumes by original acquisition date; FIFO scoped per
(account, security).pp_portfolio_builder.py,schemas.py): destination read from PP'sxact_cross_entry, surfaced astransferTargetAccount.tax.py): deemed income attributed per lot, fixing a double-count / crash when a transfer createstwo lots sharing one
(date, account, security)key.simulate_share_sell.py):--account-idscopes by net share balance; cross-account FIFO resolvestransferred lots.
rules.py): built-inunlinked-depot-transferrule (awarning, on by default) flags transfers withno cross-entry link.
Behavior changes
share-sell --shareswithout--account-idnow picks the globally-oldest lot across accounts (was per-account).share-sell --account-id <source>no longer offers an unlinked transfer's net-0 source lots; cost-basis totals staycorrect, and the data is surfaced by the default-on validation rule plus an engine
WARNINGduring computation.Known limitations
A → B → C(logs a warning).unlinked-depot-transferwarning and an engine log warning), not sellable via--account-id..cache.dbcanOperationalErroron the new join (low probability; delete cache or use--no-cache).Testing
New tests cover full/partial/chained/round-trip/over transfers, cross-account FIFO by acquisition date, per-lot
Vorabpauschale, share-sell scoping, per-security FIFO isolation, and the validation rule. Full suite passes; pylint 10/10;
bandit clean.