Part of a series on building Balance, a portfolio rebalancing app, as a solo developer.
Code here is simplified from the real service.
Computing Brazilian stock-investment tax looks simple until you try to automate it. Three rules, each with a gotcha, and a transaction history that has to be replayed in exactly the right order. That's what became Balance's IRReportService.
(Brazil-specific, but the patterns — derived-not-stored cost basis, separate loss pools, modeling concepts instead of ifs — transfer to any tax engine.)
The rules that trip everyone up








