How One Developer Built Brazilian Capital Gains Tax Logic Into a Django Service
A solo developer building Balance, a portfolio rebalancing app, created a Django service called IRReportService to automate Brazilian stock investment tax calculations. The system handles three asset types — common stocks, REITs, and stock ETFs — each with different tax rates and exemption rules, including a R$20,000 monthly sales exemption that applies only to common stocks. To accurately compute taxable profit, the service replays all transactions in chronological order rather than relying on stored values, ensuring average acquisition cost is correctly maintained across buys and sells. Separate loss pools are tracked for stocks versus REITs and ETFs, as Brazilian tax law does not allow losses to be offset across these categories. The service ultimately generates a formatted XLSX report covering monthly tax summaries, year-end positions, and exempt income, intended to simplify the annual tax filing process for Brazilian investors.
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