Ir para o conteúdo principal

Visão Geral

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. Notas do livro-razão

Posição financeira

Patrimônio líquido e as contas que o compõem

Patrimônio Líquido
Ativos mais passivos nos últimos 12 meses
67.999,23 USD
0,00 USDdesde o mês anterior

Custo de aquisição 62.104,35 USD · Não realizado +5.894,88 USD

Contas
Saldos atuais das contas de ativos e passivos

Movimentação de dinheiro

Receitas e despesas mensais por categoria de conta

maio de 2026
Entradas
maio de 2026
—
Principais fontes
Não houve movimentação de dinheiro neste período.
Média de até 3 períodos anteriores
+695,67 USD
Ver tudo
Saídas
maio de 2026
-139,95 USD
Maiores despesas
Média de até 3 períodos anteriores
-3,30 USD
Ver tudo

Atividade recente

Atividade do diário considerando os lançamentos

Transações
Transações mais recentes segundo os filtros atuais

Renda vs Despesas

Renda vs Despesas
Gráfico de barras comparando renda total e despesas para cada intervalo no período selecionado.
Dados por período
PeríodoRendaDespesasLucro Líquido
2024-01-310,00 USD0,00 USD0,00 USD
2024-02-290,00 USD4,95 USD-4,95 USD
2024-03-310,00 USD4,95 USD-4,95 USD
2024-04-300,00 USD0,00 USD0,00 USD
2024-05-310,00 USD0,00 USD0,00 USD
2024-06-300,00 USD4,95 USD-4,95 USD
2024-07-310,00 USD0,00 USD0,00 USD
2024-08-310,00 USD0,00 USD0,00 USD
2024-09-300,00 USD0,00 USD0,00 USD
2024-10-310,00 USD0,00 USD0,00 USD
2024-11-300,00 USD0,00 USD0,00 USD
2024-12-310,00 USD0,00 USD0,00 USD
2025-01-310,00 USD0,00 USD0,00 USD
2025-02-280,00 USD0,00 USD0,00 USD
2025-03-3163,00 USD0,00 USD63,00 USD
2025-04-300,00 USD0,00 USD0,00 USD
2025-05-310,00 USD0,00 USD0,00 USD
2025-06-30124,00 USD0,00 USD124,00 USD
2025-07-310,00 USD0,00 USD0,00 USD
2025-08-310,00 USD0,00 USD0,00 USD
2025-09-300,00 USD4,95 USD-4,95 USD
2025-10-310,00 USD0,00 USD0,00 USD
2025-11-300,00 USD0,00 USD0,00 USD
2025-12-310,00 USD0,00 USD0,00 USD
2026-01-310,00 USD0,00 USD0,00 USD
2026-02-281.686,00 USD4,95 USD1.681,05 USD
2026-03-31115,00 USD0,00 USD115,00 USD
2026-04-30286,00 USD4,95 USD281,05 USD
2026-05-310,00 USD139,95 USD-139,95 USD

Balanço Patrimonial

Distribuição de Ativos
Representação visual da composição de Stock & ETF Cost-Basis Example — beancount.io ativos
Detalhamento
ContaValorParticipação no total
Assets:Brokerage:NWRB4.199,00 USD6,05%
Assets:Brokerage:Cash18.295,35 USD26,38%
Assets:Brokerage:BMKT22.288,44 USD32,14%
Assets:Brokerage:ACME14.565,00 USD21%
Assets:Bank:Checking10.000,00 USD14,42%
Distribuição de Passivos
Representação visual da composição dos Stock & ETF Cost-Basis Example — beancount.io passivos
Nenhum Dado Disponível

Fluxo de caixa

Fluxo de caixa
Fluxo de dinheiro de fontes de receita para despesas e investimentos

Carregando as funções das contas…

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