From Unit Price to Total Cost: Getting Fractional-Share Cost Basis Right in Beancount
The Problem of Non-integer Shares Open a modern brokerage account and you own fractional shares almost before you mean to. Dividend reinvestment turns a 53.31 USD payout into 0.079 shares of an ETF; dollar-based recurring buys convert a flat 200 USD into whatever slice of a share that happens to buy today; fractional-share trading lets you order half a share outright. Whole-number lots are increasingly the exception, not the rule. This is a bookkeeping problem, not just a trading one, because a fractional lot is not quite the same thing to record as a whole-share one. In Beancount — and in double-entry systems generally — the natural way to record a purchase is to attach a per-share cost to the shares: ten shares at 200 each. That notation is exact when the share count is a whole number, and every tutorial reaches for it, including one I wrote last year. But the moment the share count carries decimals, that same notation quietly records a cost basis that is wrong — off by a few cents per lot, with no error to warn you, and in a way that eventually shows up as a mis-stated capital gain. This post is about why that happens and how to record fractional lots correctly. The fix itself is small — declare the total cost of the lot rather than its per-share price — but it’s worth walking through the reasoning, because it generalizes beyond stocks: whenever three numbers are bound by a single equation, only two of them carry independent information, and getting your books right comes down to writing the right two down. ...