Repository navigation
fix(antichurning): apply the 2-month rule as the DGT does, so losses are no longer deducted or blocked wrongly - #465
Conversation
…ugh a rectificativa from 2024 on (#458)
…nths before came with no shares held (#453) DGT V3282-18 and the AEAT Manual Renta 2025 lift the rule on the purchases of the 2 months before a sale when there was a single buy operation in that window and no homogeneous shares at its start. The engine blocked the loss anyway: buy 100, sell 50 at -100, nothing else, blocked 100 the user may deduct. The pre-sale pass of detectWashSales now skips such a window. Purchases after the sale still block (V3282-18 B). Only the 2-month window gets it (the doctrine states it for letter f). The fills of one order on one day are one purchase. The holding at the window start is read from every merged file, the manual opening lots and FIFO's lots; when the upload does not reach back to the window start the exception is withheld and a warning says why. Gain sales with pending losses share the absorption, so the definitive-transmission test of #451 follows it too. No committed fixture changes in any FX method.
…g the loss (art. 33.5.e) Crypto is no «valor o participación» (DGT V0648-24, V0525-25), so letters f and g do not reach it: letter e applies, and it counts only a reacquisition in the year after the sale. The engine gave crypto the unlisted-security window, 12 months before and after, so a coin bought before the sale and still held blocked the loss (issue example: 100 blocked, 0 deductible), and a buy before a later sale kept an older loss pending. For CRYPTO the absorb window now starts at the sale (looksBack). The window end, the past-data warning and the 30 June split are unchanged. No fixture moves with real ECB rates in any of the three FX methods. Docs and the 5 locales say crypto gets only the year after the sale, and that this is a deduction from DGT doctrine (V0525-25, V1613-25), not a holding. casillas.md states the choices: same ticker on any exchange, swap legs count, partial rebuys stay proportional, rewards do not count, and the #451 release test is kept. Closes #457
…prove no shares were held before them (#453) A file's start date proves nothing about shares bought before it. A 2025 Flex with buy 100, sell 50 at -100 and year-end OpenPositions of 250 (200 held since 2023) got the exception and deducted a loss the DGT blocks; so did a second broker selling 20 shares it held before its file, and a file whose earlier shares were simply never sold. The same check also made gain sales definitive by mistake (#451). The exception now needs proof: the upload reaches the window start, no sale takes more shares than the upload shows, and each broker that trades the security lists end-of-period holdings that its trades and the manual opening lots explain (summed over brokers, so a transfer between two uploaded brokers cancels out). Otherwise it is "unverified": not applied, with a warning that says what files would prove it. Lists a parser builds from the file's own trades (Revolut) prove nothing and are ignored, so transactions-only CSVs never get the exception. The position walk now counts held shares only: a short opened and covered long before the window no longer disables the exception for good, silently. No committed fixture changes in any FX method.
…x/i453-single-purchase
…t of crypto so they keep their pre-sale anti-churning block CVX, STX, ADI, BDX and CFG are S&P 500 tickers that are also CoinGecko coin symbols, so a Revolut row in them was typed CRYPTO. With crypto now on the art. 33.5.e window (only the year after the sale), a held buy before a loss sale no longer blocked the loss of these listed shares, which letter f covers (2 months before or after). They join the generator's stock-ticker conflict list and leave the generated set, as META and the others did in #371.
…ct that year, or the loss is never deducted 0.66.13 let a crypto buy before a loss sale block the loss and released it in a later year. The art. 33.5.e engine deducts it in the year of the sale and no later year releases it, so a user who filed that year with the old version and does not correct it never deducts the loss. casillas.md gets a warning box beside the 0.66.5 one, and the FAQ and the Renta Web guide hint (es, en, ca, eu, gl) get the same note: correct that year (2024 on: autoliquidación rectificativa; 2023 and earlier: solicitud de rectificación), and correct a later year too if an old version already released the loss there, so it is not deducted twice. The docs also said the #451 definitive test "never releases early" under letter e. It never releases earlier than the "any later sale" reading, but it can release while the rebought coin is still held, when a later definitive sale sells older lots. casillas.md, CLAUDE.md and the design doc now say so as part of open point A. Both behaviours are pinned through generateTaxReport, and the wording in guide-consistency.test.ts.
…using the next sale's rebuy (#454) detectWashSales took post-sale buys first, then pre-sale buys newest first under one holdingAfter cap that a used buy did not reduce. A sale then took the next sale's rebuy, and a lot FIFO had already sold could still block. V0248-18 released 400 in 2017 (DGT: nothing, fiscal 900); V0754-26 with each rebuy before its sale released 385 in 2025 (DGT: nothing, 2026 -942). The order now follows the purchases the DGT names in V3282-18, V0248-18 and V1760-23: the oldest unused purchase first, so pre-sale before post-sale; a pre-sale purchase counts only for its shares still held after the sale (the newest holdingAfter shares, FIFO); and the rest of the lot the sale transmits comes last, after the post-sale buys. The repurchase dates now match the DGT's on V3282-18 and V1760-23 too. The one-purchase exception (#453) lifts both pre-sale steps. V2481-20 moves from 1,079.44 to 1,751.73 (DGT 1,767). The last 15.27 is 20 shares of the 29/04 sale that the 06/05 purchase cannot cover once the 23/04 sales used 40 of it; the DGT does not count those. It stays an it.fails. No committed fixture changes in any FX method.
… who filed with 0.66.13 to check that year (#454) The design doc gets the derived rule with the consulta passages behind each step and the figures it reproduces; casillas.md describes the order; casillas.md and the FAQ tell users who filed with 0.66.13 or earlier that a year may move and how to correct it; CLAUDE.md gets the Hard Trace.
…nt's own files prove no shares at the window start (#453) The first proof of "no shares at the window start" had six holes, each one letting a user deduct a loss the 2-month rule blocks: - an OpenPositions row with no quantity read as 0 (the parser default); - a holdings list dated before the window still counted when later files had trades only; - one broker's surplus cancelled another broker's deficit; - those differences were summed across a split in mixed share units; - coverage was the earliest file start, so a gap between files hid trades; - one IBKR account's list proved another account's trades. The rule is now one strict check per account (broker and account id) that trades or lists the security: a non-empty holdings list dated on or after the sale, files covering that account without a gap from the window start to that date, every quantity readable, and the list equal to that account's own trades since the window start, split-adjusted to the list date. Nothing is offset between accounts, so a transfer between two uploaded accounts and a manual opening lot inside the window are "unverified" (loss stays blocked, warning). The IBKR parser now keeps each FlexStatement's period per account and marks an unreadable position quantity. The issue example with matching OpenPositions still deducts its loss. The migration note (guide in 5 locales, casillas.md, faq.md) now tells a user who corrects an earlier year to remove the same loss from a later filed year that already deducted it. The FAQ and the guide no longer say every later purchase blocks: a buy that only covers a short is no repurchase. No committed fixture changes in any FX method.
…to fills gives the same year (#454) The held-shares walk marked only one row as the partly held lot the sale transmits. When one purchase came as several rows on the same day (DEGIRO lists one order as one row per fill with one «ID Orden»), the rows FIFO left untouched counted as fully held and were taken before the post-sale buys. Buy 100 on 01/03, sell 50 on 10/03, buy 50 on 15/03, sell 50 on 20/03 gave fiscal -200 as one row and -40 as fills of 60 + 40, and the 10/03 sale got an "unverified" one-purchase mark it should not have. The walk now groups the buys of one day: they share one held count, and a partly held day goes last with all its rows. Both layouts now give -200 with no mark, in all three FX methods. No committed fixture changes.
…x/i454-dgt-pick-order # Conflicts: # CLAUDE.md # docs/casillas.md # docs/faq.md
…ns are sold, not on a sale of other coins Art. 33.5.e integrates the loss «cuando se produzca la posterior transmisión del elemento patrimonial», and the AEAT Manual says when «se transmita el elemento patrimonial adquirido». The first #457 fix kept the share-count «transmisión definitiva» queue for crypto, so a later sale of older coins released the loss while the rebought coin was still held (buy 3 BTC in 2023, sell 1 at -100 on 01/06/2025, rebuy 01/07/2025, buy 01/05/2026, sell a 2023 coin on 15/06/2026: 2026 released 100). A crypto block is now tied to the coins of the rebuy that absorbed it, per buy day, and released when FIFO transmits those coins, in proportion to the quantity. A tied coin sold and rebought in the year after passes the loss to the new coins. A sale of other coins releases nothing and uses up no rebuy, and crypto has no total exit (selling out before the rebuy transmits none of its coins). Securities keep the #451 queue unchanged. The open-at-filing hint said «antes del {{windowEnd}}» although a rebuy on that day counts: it now names the day as included in the 5 locales and report.ts, and the English past-data hint drops «until». No committed fixture moved in any FX method; only that hint's wording.
…al exports reach the D-6, the 720 and the #453 evidence IBKR writes an OpenPosition's held quantity as `position`; `quantity` is the Trades attribute. The parser read only `quantity`, so every row of a real export read "0" (every real export in tests/fixtures has only `position`): the D-6 dropped every IBKR holding as "not long", the 720 tranches got 0 shares, and the #453 one-purchase evidence could never pass. The parser now reads `position`, with `quantity` as the fallback the hand-written fixtures use, and still marks a missing or non-numeric one as unknown. With both the Summary and the Lot options on, IBKR lists a holding as a SUMMARY row plus one LOT row per tax lot; LOT rows that have a SUMMARY row are now dropped so the holding counts once. The tax report (generateTaxReport) does not read Open Positions quantities: byte-identity unchanged in all FX methods. D-6 now lists the IBKR holdings of ibkr-autoconvert.xml (3) and ibkr-multicurrency.xml (4), which it dropped.
…acks an ISIN, a file has no trades or two files share a day (#453) Three more ways the evidence for "no shares at the window start" could pass without proving it, each letting a user deduct a loss the 2-month rule blocks: - an Open Positions row without an ISIN (the field left out of that section while Trades has it) counted as "no row of the security", so a list that showed the shares held read as zero; - a holdings-only Flex (no Trades section, the usual 720 query) counted as coverage of its whole period, hiding a sale of shares held before; - two files covering the same days (the same Flex uploaded twice) doubled the trades, and the doubled trades matched the list. Now a list proves "no row" only when every share row of every uploaded list has an ISIN (options and other exempt categories aside); only a statement with a Trades section (an empty one included) covers its period; and every day from the window start to the list date must be covered exactly once, so overlapping files are unverified (the loss stays blocked, with the warning). The unverified hint (5 locales) now names the Trades section, the ISIN field and "no day twice". The tests switch to IBKR's real `position=` rows and add the issue example in that format, which is applied in all three FX methods. No committed fixture changes in any FX method (byte-identity: 205 runs, 0 diffs).
…x/i453b-evidence # Conflicts: # docs/casillas.md # docs/faq.md # src/i18n/locales/ca.ts # src/i18n/locales/en.ts # src/i18n/locales/es.ts # src/i18n/locales/eu.ts # src/i18n/locales/gl.ts # tests/i18n/guide-consistency.test.ts
…later loss needs, and release on the sale of the rebought coins The first follow-up rolled a sold tied coin's loss onto the next rebuy, and a gain sale of the tied coin took that rebuy to do it. A later loss in the same year then found no rebuy and was deducted: BTC -10 blocked on 02/06/2025, its rebought coin sold at +5 on 01/09, a -1000 loss on 01/10 with a buy on 03/11/2025 -> 2025 deducted the 1000. Letter e defers it, and it integrates a loss «cuando se produzca la posterior transmisión del elemento patrimonial», with no f/g «definitiva» test. So the sale of the tied coins now releases their loss whatever is bought after, and only crypto loss lots take a rebuy. A staking reward received on the rebuy day counted as a held rebought coin, so selling the whole rebought coin released only part of the loss. FIFO books a day's trade coins before its reward coins, so the held ones are the tail and the reward part carries no tie. A crypto release is final, so it no longer raises the past-data warning by itself. A crypto release row now explains itself with art. 33.5.e, not the securities «transmisión definitiva», in the 5 locales, and the hints say the loss is integrated even if the coin is bought again. Fixtures: binance-v2-sample.csv 2025 releases 0.0000012 EUR (0.00 in every box) on the 09/04/2025 ETH sale, whose 25/02 coins carried the 13/01 loss.
… is not removed (#454) A review of #454 read the held-shares walk as crediting sold shares: the sale day's buys are in holdingAfter but the walk skips them, so an older lot stands in for them. It proposed taking the sale-day buys off the count. The DGT counts a sale-day buy as a rebuy (V0571-21), and the stand-in is how the engine reaches that. The subtraction gives 40 instead of the DGT's 90 on the review's own example, V2481-20 1,088.08 instead of 1,751.73 (DGT 1,767) and V0571-21 -1,500 instead of -1,166.67 (DGT -1,166.67). The engine is unchanged. New end-to-end cases through the IBKR and DEGIRO parsers, in all three FX methods, pin the DGT's figures (90, 30, and a definitive test kept pending by a sale-day rebuy). They also pin two real gaps of the stand-in as it.fails on the DGT's figure: it needs an older lot inside the window, and the sale-day shares can be used twice. CLAUDE.md and the design doc now say what the walk does with the sale day and why the fix that closes both gaps waits for a decision: it moves a committed fixture. No committed fixture changes.
…r window, so their losses are no longer deducted early (#452) Up to 0.66.13 every security with an ISIN got the 2-month window of LIRPF 33.5.f. A share admitted to no EEA regulated market and no equivalent third-country market is letter g: 1 year. Buy 01/02/2025 at 100, sell 01/03 at 80, rebuy 01/08 at 85 on the London Stock Exchange deducted -20 that the statute defers. - Read IBKR listingExchange from Trades and Financial Instrument Information. 1 year applies automatically only when every IBKR code of the ISIN is a letter-g market on the sale day: London from 2021, SIX outside 24/12/2017-30/06/2019, OTC Markets, Japannext, Stock Connect and other third countries with no decision. Any other or unknown code keeps 2 months. - Toronto, TSX Venture, Aequitas Neo, Tokyo and Singapore have EMIR equivalence decisions (2016/2273, 2016/2271, 2016/2270). They stay at 2 months with an info message that calls the point open. LSEETF stays at 2 months. - A per-ISIN user value (2 or 12) wins over everything: the results panel «Plazo anti-churning por valor» (localStorage), ReportOptions. windowMonthsByIsin, and --antichurning-1y / --antichurning-2m on convert. - One map feeds detectWashSales (block, definitive test, pick order) and salesWithWindowPastData (past-data and open-at-filing warnings). - New messages: the IBKR 1-year warning with the way back, the open-decision note and the list of windows set by hand. The guide, the past-data hint, the docs and CLAUDE.md no longer list Toronto or Tokyo as 1-year markets. No committed fixture figure moves in any FX method; reports gain capitalGains.antichurningSecurities and the reworded past-data hint.
… so the pending fix is weighed on the full list (#454) A review of 8c6928a found two more ways the sale-day stand-in misses the DGT's figure, both reproduced through the IBKR Flex and DEGIRO CSV parsers in all three FX methods. Gap (a) was described too narrowly. The held count goes to the newest earlier buy day, so an older lot inside the window is not enough: if an earlier sale used that day, nothing stands in. Buy 100 + 100, sell 100 at -100, then sell 100 at -100 and buy 50 the same day: the engine blocks 0 and releases 100 (fiscal -200), the DGT blocks 50 and releases 50 (-100). In the V0571-21 layout without its unused pre-sale buy, a sale rebought the same day still counts as definitive and releases 50 (fiscal 50, DGT 100). Gap (c) is new. The stood-in lot is only partly held, so step 4 puts it after the post-sale buys and the sale takes a later purchase the DGT leaves for the next sale: sell 100 at -100 and buy 50, buy 100, sell 50 at -50 gives fiscal -100 where the DGT gives 0. Each case pins the engine figure in all three methods plus an it.fails on the DGT's figure. The doctrine fix (count a sale-day buy for its own held shares) meets the DGT's figure in all five it.fails. Docs updated. No engine change; every fixture byte-identical.
…plit) into the #457 crypto release fix
…dow, since no equivalence decision covers that market (#452) IBKR's exchange list has BURSAMY as a primary stock market, but it was in neither listing table, so a Malaysia-only share fell back to 2 months and a loss bought back within a year was still deducted early. No MiFID II art. 25(4)(a) or EMIR art. 2a market decision names Malaysia.
…arn on one that is in no file, so a typo cannot silently keep the 1-year block (#452) --antichurning-1y/-2m only checked the ISIN shape. A mistyped last digit in --antichurning-2m exited 0 and left IBKR's 1-year reading in place, with no sign the flag did nothing, though docs/usage.md promised exit code 1. The flags now run the ISO 6166 check digit (isValidIsin), and a valid ISIN that matches no trade or Financial Instrument Information row prints a warning.
… release, 0.66.13 warning split) into the #452 per-ISIN window One window resolver still feeds both detectWashSales and salesWithWindowPastData; detectWashSales now takes #453's per-account statements as its coverage and the #452 window map after it. The guide, FAQ and fiscal-models texts carry both sides: the per-ISIN window wording of #452 and the short-cover clause, crypto release sentence, later-year double-deduction clause and "inclusive" deadline of integration.
…loss sold and rebought the same day stays deferred (#454) The DGT counts a buy on the sale day as a rebuy (V0571-21). The held-shares walk skipped the sale day while holdingAfter counted its buys, so an older lot stood in for them. That stand-in had three gaps: (a) With no unused older lot in the window the rebuy was missed. Buy 100 on 01/12/2024, sell them at -100 on 10/03/2025 and buy 50 the same day: 0 blocked, DGT 50. With the older lot used by an earlier sale, 10/03 blocked 0 and released 100 (DGT 50 and 50), and a sale rebought the same day counted as definitive. (b) The sale-day shares stayed unused, so a later sale used them again. (c) The stood-in lot was only partly held, so it went after the post-sale buys and the sale took a purchase the DGT leaves for the next sale. FIFO sells the oldest shares first, so the shares bought on the sale day are the newest ones held after it. The walk now starts at the sale day, so its buys count for their own held shares and are used up like any purchase. Crypto keeps its forward-only window: its walk stays empty. A sale-day buy is still a second purchase for the one-purchase exception. Every consulta figure is unchanged (V2481-20 1,751.73, V0571-21 -1,166.67, V0248-18 900, V0754-26, V3282-18, V1760-23, V0046-20, V0913-08, V1294-22). V2481-20's trail becomes 20/04 <- 20/04 and 22/04 <- 21/04. The three gap cases now pass on the DGT's figures through the IBKR and DEGIRO parsers in all three FX methods. One fixture moves: degiro-transactions-sample.csv 2021, in all 5 option sets. THETA buy 2 and sell 1 on 14/04 with nothing held before is now one purchase the CSV cannot prove, so the #453 fail-safe blocks 49.02 (24.51 with two owners) and adds antichurning_single_purchase_unverified. A user who filed such a year with 0.66.13 may have deducted a deferred loss: docs/casillas.md says how to correct it. Controls: the walk stopping before the sale day turns 27 tests red plus the 3 fixture tests; dropping the crypto guard turns the crypto same-day test red.
…o, which is released when the rebought coins are sold The «transmisión definitiva» paragraph, release step 5 of the engine steps and the carryover note in modelos-fiscales.md still gave crypto the securities rule. The Kraken test helper now computes its CSV cost with decimal.js.
…ve, and stop the D-6 crash on an empty IBKR position Third review of the #453 evidence rule (CodeRabbit on the fork mirror, geiresx#18). Fail safe: when the files cannot prove the one-purchase exception, it stays unverified and the loss stays blocked. - An Open Positions row with position="" returned quantity "" and the D-6 (and the 720) threw on new Decimal(""). An unreadable quantity is now "0", still flagged quantityUnknown, so the evidence check treats it as missing. - A share trade with no ISIN (a Flex without the Trades ISIN column, a broker that gives none) lands in a symbol-only bucket and can hide a second purchase or a sale. Any such trade, of any account, between the window start and the latest list date used makes the exception unverified. - Each account's own replay from the window start must never end a day below zero: a sale of shares held at the window start, evened out later by a buy and a transfer out, hid behind another account's shares. - A one-account Flex gave a row labeled with another account to its own account. Rows now always go to the account they name; others form the unlisted group, which proves nothing. - A row without an Account ID belongs to its FlexStatement's account. - An empty <OpenPositions /> is a list of nothing (AccountPeriod .hasPositions); no section is still no list. - The Basque guide text lacked "only" (soilik) in the short-cover clause. - docs: reconciliation cannot catch every transfer; the final rule is in docs/casillas.md, the design doc and CLAUDE.md Hard Trace #453. No committed fixture moved in any FX method (byte-identical with fxTrace on).
…who filed with 0.66.6 to 0.66.13 read the same-day note (#454) The same-day, #453 and #454 pick-order notes apply to every version up to 0.66.13, but they sat under a box titled «Si declaraste con la versión 0.66.5 o anterior». A user who filed with 0.66.6 to 0.66.13 would skip it, and that is the group whose year changes. The box is now titled 0.66.13 and each paragraph names its own version (the #451 notes say 0.66.5). A guide test fails when a box names a version newer than its title, or says "Esas versiones" next to an older one.
… per-ISIN window) into the #454 sale-day fix
…rom slipping past the one-purchase evidence Lane review of the fourth #453 evidence fix. Fail safe: when the files cannot prove the one-purchase exception, it stays unverified. - A share lot with no ISIN bought before the window and still held (an older Flex without the Trades ISIN column, any Revolut file) was invisible: its account never trades the ISIN key, and the ISIN-less check only looked inside the window. The exception was applied while those shares may have been the same security. Now any ISIN-less share lot FIFO holds at the window start (scrip lots on a bare symbol too), any ISIN-less key that sells shares never shown bought, or a trade with neither ISIN nor symbol before the window makes it unverified. A holding closed before the window still lets it apply. - A Trade row without an Account ID now belongs to its FlexStatement's account, like an Open Positions row, so a Flex without that column in either section can prove the exception. - An unreadable Open Positions quantity reads "0", so the 720 wrote the holding with 0 shares and the D-6 dropped it with no word. The parser now warns and names those holdings (5 locales). - docs: the Revolut claim in CLAUDE.md was wrong; casillas.md, faq.md, the design doc and the unverified hint now state the holding rule. No committed fixture moved in any FX method (byte-identical with fxTrace on).
…o a share that left NYSE for OTC gets 1 year (#452) Three gaps in the per-ISIN window that CodeRabbit found on #452: - The row list read only the last sale day of the year. SIX gain sales on 01/11/2017 (1 year) and 27/12/2017 (inside the Swiss equivalence, 2 months) lost the row, the 1-year warning and the panel's way back. Every sale day is read now; the row describes the last 1-year day. - Listings had no date. A share that moved from NYSE to OTC Markets kept NYSE, so a sale after the move got 2 months. IBKR's listingExchange is the contract's primary listing, so votes now carry conid and date, and a code drops out on a sale day only when every row of the SAME conid naming it is older than that conid's latest row on or before the sale day. Another conid, a row without conid or date, a code that comes back, and a code first seen after the sale still count, so anything ambiguous stays at 2 months. SecurityInfo rows carry their conid and their statement's toDate. - The fill merge spread the first fill, so a first fill without listingExchange dropped a later LSE. The merge keeps the first non-empty code, and every code (listingExchanges) when the fills disagree. No committed fixture changes in any FX method.
… when the browser refused the write (#452) Save wrote one ISIN at a time and ignored each result, so a full or blocked localStorage still showed the saved message, and a partial failure reran the report with only some choices. Save now builds the whole mapping and writes it once; on failure the panel shows antichurning_window.save_error, keeps the old settings and does not rerun. Clear shows antichurning_window.clear_error the same way. Strings in es, en, ca, eu and gl. The 1-year option said «solo cotiza fuera del EEE», which leaves out shares traded only on an EEA growth market (BME Growth SICAV/SOCIMI), which the AEAT puts in letter g. It now reads «no admitido en un mercado regulado del EEE ni en uno equivalente» in all five locales. The app tests now wait for a new panel and a changed block after Save and after Clear, so they fail if Save stops recalculating.
… how to mark 2 months, so the docs stop promising 2 months to every ISIN (#452) - casillas.md: the listing in force on the sale day (a later row of the same conid replaces a code; everything ambiguous still counts), the SIX 1-year sale that keeps its row, and the two calculation descriptions that still gave 2 months to every ISIN now point at the per-ISIN window, with crypto (33.5.e) and the exempt categories kept apart. - modelos-fiscales.md: SIX is 1 year only outside 24/12/2017-30/06/2019, and a share IBKR shows only in London but also listed in Amsterdam gets 1 year automatically: mark it 2 months in the panel or with --antichurning-2m. - design doc and CLAUDE.md Hard Trace #452: the dated-vote rule, the fill merge, every sale day for the rows, the panel's single write, and the new limit (IBKR rewriting today's listing on old rows hides a change).
…le of the same share reads 1 year (#452) With dated listings, one contract can read 2 months (TSE, open EMIR decision 2016/2273) on a March loss sale and 1 year (PINK) on a September sale. The security row describes the 1-year day only, so it dropped openDecision, the report.antichurning_listing_open message and the panel note, although the March loss was still cut to 2 months on that decision. openDecision now joins the row's day with every loss or release sale day whose reading is open, and openListingExchanges names the codes of those days when they differ from the row's. The open message and the panel note show them. A Toronto gain sale with nothing to release still adds no note. No number changes; no committed fixture changes in any FX method.
…s sold
The parser reads a missing or non-numeric Open Positions quantity as "0"
with quantityUnknown. The D-6 built its held set from quantity > 0, so such
a holding dropped out and, when last year's D-6 had its ISIN, the guide
listed it as a cancellation ("vendida o liquidada") although the broker
still lists it. A quantityUnknown row now counts as held; it stays out of
the positions list, which needs a share count.
The parser test now uses a holding above the 720's 50,000 EUR threshold
and checks its detail record with 0 in «Número de valores» (the old
fixture passed on an empty file). The 720's own cancellation keys on
positionValue and the 721 has no previous-year logic, so neither changes.
…de from proving the one-purchase exception Two gaps let the #453 exception be applied while the files could not prove "no shares at the window start": - FIFO matches ISIN-less shares across accounts (the taxpayer's FIFO), so account B's sale of shares held before its files could take account A's pre-window lot and net the symbol's balance to zero. Neither the lots nor the balance then showed A's shares, still held. The "sold unbought" test now runs per account (manual opening lots belong to no account, so any account may sell them). FIFO matching itself is unchanged. - An IBKR Trade row with no quantity read "0" and the check skipped it, so a buy in the window and its sale, both without a quantity, vanished (quantity="" crashed FIFO). The parser now maps a missing or unreadable quantity to "0" with quantityUnknown and warns (parser.trade_quantity_unknown, 5 locales); an explicit "0" is still a zero. Such a row makes its ISIN unverified, and an ISIN-less one counts as an unidentified trade with no holding to walk. No committed fixture moves in any FX method.
…windows, instead of «Guardado» with nothing saved (#452)
… days, so a Toronto loss and a later OTC sale of one share no longer read as a contradiction (#452)
…odelo 720 does The previous fix counted every quantityUnknown Open Positions row as held, whatever its sign. A holding in last year's D-6 that is now short, with no readable quantity, was then no longer cancelled, while the 720 (isHeldSecurity: a negative positionValue is no holding) wrote its C record. Without a share count the D-6 now reads the sign from positionValue, as the 720 does; an unreadable value keeps the holding held.
…ing the one-purchase exception The previous fix kept IBKR trade rows with no readable quantity as missing evidence, but every other share parser still dropped such a buy or sale with no trade and (outside DEGIRO and eToro) no message. A Trading 212 or Revolut buy before the window with an empty share count therefore vanished, and the #453 exception was applied while the file showed shares bought earlier. Trading 212, Revolut, Freedom24, Lightyear, Scalable, Flatex, Trade Republic, DEGIRO and eToro now keep a buy or sale row whose quantity cell is blank or no number as a trade of unknown quantity (csv-utils quantityUnknownTrade: the row's security, day and direction, quantity "0" with quantityUnknown, every amount "0"). A written 0 is still skipped. parser.trade_quantity_unknown now names the broker (5 locales). The evidence check already reads such a row as "unverified" (with an ISIN) or an unidentified trade (without one). FIFO now skips every quantityUnknown trade: a 0-share lot gave the next sale of the security a 0/0 cost and a NaN total, which keeping these rows would otherwise have brought to the other parsers. No committed fixture changes in any FX method.
…notice fixes) into the #453 evidence follow-up 3
…antity-less fill, and keep quantity-less buys and sales that earlier guards dropped The seventh #453 fix kept trade rows with no readable quantity as missing evidence, but its fork review found five gaps: - An IBKR order with a readable fill and an unreadable one was merged into one flagged trade that FIFO skips, so the readable shares and their cost were never booked. The unreadable fill now stays out of the merge as its own flagged trade; the readable fills merge and book as before. - A flagged crypto trade still counted as a repurchase while FIFO held no lot for it. The repurchase index now skips every quantityUnknown trade. - dropCancelledExecutions parsed raw quantities and prices with new Decimal, so a cancellation without origTransactionID crashed on a row with quantity "abc". It now reads them finite-safe; an unreadable one matches nothing. - Revolut's closed-positions format dropped a quantity-less row silently, a currency-only cell ("€") read as an explicit 0, a Flatex Kauf/Verkauf or DEGIRO row with neither quantity nor price fell to the zero-price skip first, and a Freedom24 transfer with no quantity became an unknown BUY. All four now follow the rule: keep a buy or sale row, skip a written 0, a written zero price and any non-trade row. No committed fixture changes in any FX method (350 runs byte-identical).
…le IBKR cancels by execution id, so a second purchase or a cancelled sale cannot slip through The ninth review of the #453 evidence work found three gaps: - A Flatex Kauf or a DEGIRO buy with a readable quantity but a blank price was still dropped by the zero-price skip with no message, so a second purchase in the window let the one-purchase exception deduct the loss. Trading 212's skip of a buy with no price and a Total in another currency warned but kept no evidence either. All three now keep the row as a trade that books nothing (quantityUnknownTrade); a written zero price, a custody transfer and a row with no buy or sale evidence stay skipped. - An IBKR cancel row with an unreadable quantity and no origTransactionID matched nothing, so its cancelled sale was booked as a real disposal and the warning said the original was outside the file. When either row's quantity or price is unreadable, the pair now ties by the same ibExecID; an unreadable cancel that nothing ties gets its own warning (parser.cancelled_trades_unreadable). - A quantity-less crypto trade got the shares warning, which names the 2-month one-purchase exception that crypto does not have. The shared warning now splits: parser.crypto_quantity_unknown says a crypto loss before such a rebuy may have to wait (art. 33.5.e) and is not blocked. New strings in all 5 locales. No committed fixture changes in any FX method (350 runs byte-identical).
…issing IBKR price pair by execution id, so no false block and no booked cancelled sale
- DEGIRO: a written zero quantity ("0,00") with a blank price is skipped
again instead of kept as unknown-quantity evidence.
- Trading 212: a written zero price with a Total in another currency stays
discarded; only a blank or unreadable price is kept as evidence.
- IBKR cancels: an omitted, empty or blank tradePrice is unreadable, not "0",
so the cancel pairs with its sale by ibExecID and two priceless rows no
longer pair without one; when any of the four values is unreadable only
ibExecID ties the pair; a readable cancel whose in-file candidate is
unreadable gets the unreadable warning, reworded in 5 locales so it no
longer says the cancel itself lacks a number.
- Tests: the DEGIRO fixture quotes its decimal-comma cells (they shifted
every later column), and each case asserts the branch it reaches.
- Docs: scope the zero-price rule and the cancel matcher to what the
parsers do; the CLAUDE.md #453 trace records the tenth review.
…o the report never crashes on a row booked at "abc"
The tenth-review guard only dropped the evidence flag of a DEGIRO row with a
written zero quantity ("0,00"). With a non-blank unreadable price ("abc", "-")
the string zero skip did not catch it, so the row was booked with tradePrice
"abc" and generateTaxReport threw a DecimalError where the base gave the
fail-safe "unverified". Such a row is now skipped outright.
The design doc and the CLAUDE.md #453 trace now say exactly where a written
zero price is skipped: a Flatex Kurs, a DEGIRO "0" or "0,0000" (a DEGIRO
"0,00" is booked as written), and a Trading 212 zero price with the Total in
another currency (with the Total in the instrument currency it is valued from
the Total).
…ng-lots and anti-churning panels stop claiming a save that never happened
|
Caution Review failedThe pull request is closed.
Warning Some tools did not complete. Review the errors below.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #465 +/- ##
==========================================
+ Coverage 94.07% 94.33% +0.25%
==========================================
Files 64 65 +1
Lines 8383 9119 +736
Branches 2904 3203 +299
==========================================
+ Hits 7886 8602 +716
- Misses 409 425 +16
- Partials 88 92 +4
🚀 New features to boost your workflow:
|
The 2-month anti-churning rule was wrong in four ways. Some users deducted losses the law defers, and others had losses blocked that the law allows:
The fix:
--antichurning-1yand--antichurning-2moverride it.position(20c9470), so the D-6 and the 720 list real IBKR holdings.Three choices to push back on:
The new panel, automatic 1 year from the IBKR listing, then 2 months chosen:
Closes #452, closes #453, closes #454, closes #457, closes #458.