Repository navigation
fix(wash-sale): block a loss only when FIFO really keeps replacement shares, and name the EEA in the market test - #461
Merged
Merged
Conversation
…ly brokers from moving deferred losses Late review of #459 (CodeRabbit on the exact diff): - Same-day covers now take the short in FIFO's processing order. FIFO runs a C;O buy before a C buy, so an orphan C buy listed first in the file was indexed as a repurchase and blocked a loss with no replacement shares. The comparator is now exported from fifo.ts (compareFifoTradeOrder) and used by both. - The total exit gives the rest of the queue to the day's last long sale, never to a same-day short cover. - A TC row that names no new security is booked as a merger of the ISIN into itself; it no longer stamps entryDate, so held shares do not look bought on the TC date and an earlier sale is not a total exit. - The window-past-data coverage index counts a broker with a statement end and no trades, so its later statement end cannot hide another broker's incomplete window. - The short-cover unit test flags the cover buy C, as FIFO data does. No fixture number changes in any FX method.
…e equivalent markets (DGT V0778-25) DGT V0778-25 (binding, 05/05/2025) reads art. 33.5.f to cover any third-country market the European Commission declared equivalent to an EU regulated market; Implementing Decision (EU) 2017/2320 lists NYSE and Nasdaq. So a share listed only there gets the 2-month window, as the engine already does. The 1-year window (33.5.g) is only for securities admitted to neither, e.g. OTC Markets; that is the one case where the ISIN heuristic deviates (#452). The FAQ, casillas, modelos-fiscales and design docs, CLAUDE.md, the anti-churning hints and the window-past-data warning (5 locales, plus the Spanish text report.ts writes) now say this. guide-consistency pins the new wording and rejects the EU-only one. No engine change. The design doc and CLAUDE.md also record the late-review fixes of #459.
… as a repurchase A C;O buy runs before the day's SELL O rows in FIFO and a C buy runs after them, so a C;O buy can only cover a short opened on an earlier day. The detector shared one day budget between them, gave the flip's same-day short to the C;O buy, and then indexed nothing for the C buy that FIFO keeps: a loss FIFO-held shares replace was deducted at once. Split the covered shares by the short's open day (the short disposal's acquireDate).
…Kong as equivalent markets, and keep crypto out of letter g V0778-25 places letter f's regulated markets in the whole European Economic Area, so an Oslo-only share read as 1 year in the hints. Only Implementing Decisions 2017/2318, 2017/2319 and 2017/2320 are in force (Switzerland's lapsed on 30/06/2019, the UK has none), so a share listed only in London, SIX or Toronto falls under letter g: the #452 gap is wider than OTC Markets. Crypto is no «valor o participación»: the law applies art. 33.5.e to it, which the engine does not (#457). Docs, CLAUDE.md, engine comments and the hints in all 5 locales now say so; the guide test pins it.
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #461 +/- ##
=======================================
Coverage 94.06% 94.06%
=======================================
Files 64 64
Lines 8338 8347 +9
Branches 2888 2892 +4
=======================================
+ Hits 7843 7852 +9
Misses 407 407
Partials 88 88
🚀 New features to boost your workflow:
|
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.
Problem
CodeRabbit reviewed #459 after it shipped in v0.66.8, and a second review of this fix found more. Four engine paths could block or release a deferred loss in the wrong place:
The docs and the in-app hints also described the market test wrongly. They called NYSE- and Nasdaq-only shares a DeclaRenta deviation, and they put crypto under letter g.
Fix
Market wording, in the docs,
CLAUDE.md, the engine comments and all 5 locales:guide-consistency.test.tsnow rejects the old EU-only wording.What users see
Left on purpose
Follow-up to #459, from the CodeRabbit review of its exact diff on the fork mirror.