Developer builds Django service to automate Brazil's complex variable income tax rules
A developer building Balance, a portfolio rebalancing app, created a Django service called IRReportService to automate Brazil's variable income tax calculations for stocks, FIIs, and ETFs. The system applies different tax rates — 15% for stocks and equity ETFs, 20% for FIIs — while handling the R$20,000 monthly exemption that applies only to common stocks, a rule many investors misunderstand. To identify always-taxable assets like FIIs and ETFs, the service uses a B3 ticker convention heuristic, flagging tickers ending in '11'. Average acquisition cost is recalculated by reprocessing all transactions chronologically, since sales reduce quantity but do not alter the average cost — a subtle point that causes errors in naive implementations. The final report aggregates monthly gains, loss carryovers, and year-end positions into a formatted Excel file intended to assist with Brazil's annual income tax declaration.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in