Repository navigation
fix(wash-sale): stop short covers, empty sales and spin-offs from moving deferred losses to the wrong year - #459
Conversation
…easing deferred losses early Follow-up to #455 from its late review. - A short cover transmits no held shares: it no longer seeks rebuys as a gain lot, releases pending long losses or counts as a total exit. Its own loss still blocks. - A zero-share disposal no longer drains the queue as a total exit. - The total-exit holding test reads the date shares entered the security (new optional entryDate on spin-off and merger lots and their disposals), not the parent's inherited tax acquireDate. - The release walks the queue with a cursor: 10,000 one-share lots go from 20.6 s to 0.2 s. - One shared warning (report.antichurning_window_past_data, 5 locales) for a year's sale whose window ends after the last date the upload covers and whose block or release a later buy could change. Nothing is withheld. - Docs and the 5 locales say only the shares no rebuy covers are definitive, a sale that empties the position releases everything only with no rebuy, the FAQ gives the 1-year window for unlisted securities, and a filed year is corrected with an autoliquidación rectificativa from 2024 on (complementaria / solicitud de rectificación for 2023 and earlier). - The lifetime-total property sums Decimals before rounding.
…an release Review of the #455 follow-up. - The shares a buy-to-cover acquires go straight back to the lender and never stay in the patrimony, so they are no repurchase. The detector now indexes a C / C;O BUY only for what FIFO leaves after its short disposals that day, and a C buy with no open short not at all, as FIFO and fx-fifo already do. Before, a cover buy could block a loss, and once the position stayed flat nothing released it (lifetime blocked 20, released 0). A property over random long/short histories now pins blocked = released in all 3 FX methods. - The window-past-data warning checks each merged broker on its own: a security is covered up to the earliest end among the brokers that trade it, so a DEGIRO file ending on its December loss no longer hides behind an IBKR statement that runs into the next year. - From tax year 2024, a sale whose window ends after the 30 June filing deadline gets its own warning (5 locales): the window is still open when the return is filed, so it never says the result is already correct, and a later buy means an autoliquidación rectificativa. - annex.wash_hint (shown on every blocked sale) no longer reads as a whole-sale rule, in the 5 locales. - The FAQ states art. 33.5.g's real test (not admitted to an EU regulated market) and the engine's ISIN heuristic as a limit (#452). - Merger entry-date regression tests next to the spin-off ones.
# Conflicts: # src/generators/report.ts
|
Caution Review failedThe pull request is closed. Walkthrough
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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #459 +/- ##
==========================================
+ Coverage 93.90% 93.96% +0.06%
==========================================
Files 64 64
Lines 8103 8201 +98
Branches 2790 2838 +48
==========================================
+ Hits 7609 7706 +97
- Misses 405 406 +1
Partials 89 89
🚀 New features to boost your workflow:
|
…shares, and name the EEA in the market test (#461) * fix(wash-sale): keep short covers, same-ISIN TC rows and statement-only 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. * docs(antichurning): stop calling NYSE and Nasdaq a deviation, they are 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. * fix(wash-sale): count the shares an intraday short-to-long flip keeps 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). * docs(antichurning): name the EEA and only the US, Australia and Hong 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.
Problem
#455 shipped in v0.66.6 before CodeRabbit finished. Its late review found cases where a pending anti-churning loss came back too early, too late or never. It also found wording that promised more than the engine does.
Fix
Warnings
No file can show a repurchase made after the uploaded data ends. A sale whose window runs past the data now gets a warning, and no amount is held back.
Wording
AEAT, Manual práctico de Renta 2025: «Este nuevo sistema de rectificación se configura como el procedimiento general de modificación de declaraciones de IRPF desde el período impositivo 2024».
https://sede.agenciatributaria.gob.es/Sede/ayuda/manuales-videos-folletos/manuales-practicos/irpf-2025/c18-cuota-liquida-resultante-autoliquidacion/regularizacion-situaciones-tributarias/general.html
What users see
Left on purpose
Follow-up to #455, from the CodeRabbit review of its exact diff on the fork mirror.
Summary by CodeRabbit