跳到主要内容

概览

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. 账本备注

财务状况

净资产及其组成账户

净值
过去 12 个月的资产与负债之和
67,999.23 USD
0.00 USD较上月

成本 62,104.35 USD · 浮动盈亏 +5,894.88 USD

账户
当前资产和负债账户余额

资金流动

按账户类别显示每月收入和支出

2026年5月
资金流入
2026年5月
—
主要来源
此期间没有资金流动。
最多前 3 个期间的平均值
+695.67 USD
查看全部
资金流出
2026年5月
-139.95 USD
主要支出
最多前 3 个期间的平均值
-3.30 USD
查看全部

近期活动

考虑分录的账本活动

交易记录
符合当前筛选条件的最新交易

收入与支出

收入与支出
在选定时期内每个区间的总收入和支出对比的柱状图。
各期间数据
期间收入开支净利润
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

资产负债表

资产分布
Stock & ETF Cost-Basis Example — beancount.io资产构成的可视化表示
明细
账户金额总额占比
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%
负债分布
Stock & ETF Cost-Basis Example — beancount.io负债构成的可视化表示
无可用数据

现金流

现金流
资金从收入来源流向支出和投资

正在加载账户角色…

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