Skip to main content

Overview

Stock & ETF Cost-Basis Example — beancount.io

A Beancount ledger demonstrating taxable brokerage accounting: one cash brokerage account holding two individual stocks and a broad-market ETF, bought in identifiable lots between 2024 and 2026. Ledger notes

Financial position

Net worth and the accounts that make it up

Net Worth
Assets plus liabilities over the last 12 months
69,347.788 USD
+1,348.563 USDfrom previous month

Cost basis 62,104.35 USD · Unrealized +7,243.438 USD

Accounts
Current asset and liability account balances

Money movement

Monthly income and spending by account category

May 2026
Money in
May 2026
—
Top sources
No money movement for this period.
Average of up to 3 preceding periods
+695.67 USD
View all
Money out
May 2026
-139.95 USD
Top spending
Average of up to 3 preceding periods
-3.3 USD
View all

Recent activity

Posting-aware activity from the journal

Transactions
Newest transactions matching the current dashboard filters

Income vs Expenses

Income vs Expenses
Bar chart comparing total income and expenses for each interval in the selected period.

Balance Sheet

Assets Distribution
Visual representation of Stock & ETF Cost-Basis Example — beancount.io assets composition
Liabilities Distribution
Visual representation of Stock & ETF Cost-Basis Example — beancount.io liabilities composition
No Data Available

Cash Flow

Cash Flow
Money flow from income sources to expenses and investments

Loading account roles…

README.md

Stock & ETF Cost-Basis Example — beancount.io

A Beancount ledger demonstrating taxable brokerage accounting: one cash brokerage account holding two individual stocks and a broad-market ETF, bought in identifiable lots between 2024 and 2026.

The method rests on one idea — a share is not a number, it is a lot: a quantity held at a known cost acquired on a known date. Writing a purchase as 120 NWRB {41.80 USD, 2024-03-12} stores the basis with the position instead of in a spreadsheet beside it, so a later sale can name the exact lot it disposes of and Beancount computes the gain rather than trusting you to.

Everything else here is that one idea applied again. A reinvested dividend is a new lot at the reinvestment price. A share split is a rewrite that must preserve total basis and realize nothing. A year-end balance is a share count you can check against the broker's December statement.

The ledger sets option "booking_method" "STRICT", so a sale that does not identify its lot is an error rather than a guess. That refusal is the point: it is what makes the realized gains in this ledger reproducible.

Every issuer, ticker and price in this ledger is fictional. They are chosen to be plausible, never to describe a real security's market history.

Quick Start

bash
make install   # Install beancount + fava via uv
make check     # Verify the ledger has zero errors
make serve     # Open Fava at http://localhost:4741

File Guide

FileWhat it demonstrates
Makefilemake install / make check / make serve — the three commands above
pyproject.tomlThe pinned beancount + fava toolchain make install resolves
main.beanEntry point — options (including booking_method) and include directives
accounts.beanTicker commodities and the brokerage / dividend / capital-gains chart
prices/2024-2026.beanStatic quarter-end prices — market value only, never cost basis
transactions/opening.beanFunding the taxable brokerage account
transactions/purchases.beanBuying in identifiable lots with explicit {cost, date}
transactions/dividends.beanCash dividends, and DRIP purchases that create new lots
transactions/split.beanA share split that changes the count and preserves total basis
transactions/sales.beanSelling a named lot, and where the gain lands by holding period
transactions/assertions.beanYear-end share-count assertions against the broker statement

Live prices (preview)

The prices in prices/2024-2026.bean are static and checked in. That is what makes this repository reproducible: clone it in two years and make check still produces the report it produces today. They are also unadjusted — the dates before NWRB's 4-for-1 split carry pre-split per-share prices, the dates from the split onward carry post-split ones, and nothing earlier is restated. The two directives straddling the split value the same holding at $7,440.00 on both sides of it.

A hosted beancount.io ledger will also be able to pull a managed price feed, with one line:

beancount
; include "https://beancount.io/prices/ACME-USD"

It ships commented out, and three things are worth knowing before you uncomment it in a ledger of your own:

  1. A URL include resolves only inside a hosted beancount.io ledger. Nothing else reads it.
  2. A local run does not fetch URLs. bean-check and bea check read files from disk, so that line fails locally with a "does not match any files" error — which is why this repository, meant to be cloned and run, ships static prices.
  3. Prices never change quantities, cost basis or realized gains. However they arrive, they move market value and nothing else; every number in transactions/sales.bean is computed from the lots.

And the fact most worth having in advance: your own price directive always wins over a managed one for the same date and commodity pair, whatever the include order. A managed feed is a fallback for dates you have not priced yourself, never an override — so pinning a price you reconciled against a statement is simply a matter of writing it down.

The one thing to copy

A purchase stores its own basis:

beancount
2024-03-12 * "Broker" "Buy 120 NWRB @ $41.80"
  Assets:Brokerage:NWRB                    120 NWRB {41.80 USD, 2024-03-12}
  Expenses:Brokerage:Commissions          4.95 USD
  Assets:Brokerage:Cash               -5,020.95 USD

…and a sale names the lot it sells, so the gain and its holding period both follow from the entry rather than from a spreadsheet:

beancount
2026-02-20 * "Broker" "Sell 60 ACME from the 2024 lot — long-term gain"
  Assets:Brokerage:ACME                    -60 ACME {68.20 USD, 2024-06-18}
  Assets:Brokerage:Cash                  5,778.00 USD
  Expenses:Brokerage:Commissions             4.95 USD
  Assets:Brokerage:Cash                     -4.95 USD
  Income:CapitalGains:LongTerm          -1,686.00 USD

Nothing anywhere else in the ledger has to remember what those shares cost.

What the numbers come to

Running make check validates every year-end share count below, and bea report income-statement reproduces the realized results:

Holdings at the end of 2026150 ACME · 201.25 BMKT · 380 NWRB · $18,295.35 cash
Long-term capital gain$1,686.00 (60 ACME bought 2024-06-18, sold 2026-02-20)
Short-term capital gain$286.00 (40 ACME bought 2025-09-08, sold 2026-04-17)
Long-term capital loss$135.00 (100 post-split NWRB, holding period dating to 2024-03-12)
Dividend income$274.00 qualified · $28.00 ordinary
Brokerage commissions$34.65 across four buys and three sells