# Beancount cheat sheet: syntax and directives

## Account Structure

### Account Types and Signs

```text
Type          Sign    Example
------------------------------------------------
Assets        (+)     Assets:US:BofA:Checking
Liabilities   (-)     Liabilities:Credit:Amex
Income        (-)     Income:Salary:Gross
Expenses      (+)     Expenses:Food:Restaurant
Equity        (-)     Equity:Opening-Balances
```

### Commodity Format

Commodities are uppercase symbols — currencies, tickers, and custom units. These are naming examples, not directives:

```text
Currencies:       USD, EUR, CAD, AUD
Investments:      GOOG, AAPL, VTI
Cryptocurrencies: BTC, ETH
Custom units:     HOURS, AIRMILES, HOME_MAYST
```

## Directive Syntax

### Account Management

```bean
; Opening accounts
2024-01-01 open Assets:Checking             ; Simple
2024-01-01 open Assets:Investing USD,GOOG   ; With constraints

; Closing accounts
2024-12-31 close Assets:Old:Account
```

### Commodity Declaration

```bean
2024-01-01 commodity VTSAX
    name: "Vanguard Total Stock Market Index"
    asset-class: "equity"
```

### Transaction Recording

```bean
; Basic transaction
2024-01-15 * "Grocery Store" "Weekly shopping"
    Assets:Checking     -100.00 USD
    Expenses:Food:Groceries

; With metadata and tags (#work is a tag, ^invoice-123 is a link)
2024-01-15 * "Restaurant" "Business dinner" #work ^invoice-123
    id: "T-1234"
    receipt: "path/to/receipt.pdf"
    Expenses:Meals      80.00 USD
    Liabilities:Credit
```

### Posting Specifications

These are posting lines — each sits inside a transaction, indented under its date line:

```bean
; Basic amount
Assets:Cash              100.00 USD

; Cost basis tracking
Assets:Invest:VTSAX      10 VTSAX {100.00 USD}        ; Per-unit cost
Assets:Invest:VTSAX      10 VTSAX {{1000.00 USD}}     ; Total cost
Assets:Invest:VTSAX      10 VTSAX {100.00 # 9.95 USD} ; Per-unit plus total fee

; Price specifications
Assets:Forex            1000.00 USD @ 0.85 EUR        ; Per-unit
Assets:Forex            1000.00 USD @@ 850.00 EUR     ; Total price

; Dated lots
Assets:Invest:VTSAX      10 VTSAX {100.00 USD, 2024-01-15}
```

### Balance Verification

```bean
; Balance padding: fills Assets:Checking up to Equity:Opening-Balances
2024-01-01 pad Assets:Checking Equity:Opening-Balances

; Balance assertion: checked at the start of its date, so date it after the pad
2024-02-01 balance Assets:Checking  1000.00 USD
```

### Metadata Tracking

```bean
; Note attachment
2024-01-15 note Assets:Checking "Called bank about fee"

; Document linking
2024-01-15 document Assets:Checking "path/to/statement.pdf"

; Price recording
2024-01-15 price VTSAX  100.00 USD
```

For hosted ledgers, [Live Prices](https://beancount.io/docs/live-prices) can supply dated valuation prices automatically. Choose supported asset pairs in the picker, then copy the includes into your ledger. Keep transaction prices and cost basis explicit.

### Event Recording

```bean
; Location tracking
2024-01-15 event "location" "New York, USA"

; Property changes
2024-01-15 event "address" "123 Main Street"
```

### Tag Management

```bean
; Tag scope control: #vacation applies to every transaction between the pushtag and poptag
pushtag #vacation
2024-01-15 * "Hotel"
    Expenses:Travel:Lodging   200.00 USD
    Assets:Credit
poptag #vacation
```

### Configuration Options

```bean
; Basic settings
option "title" "Personal Finance Ledger"
option "operating_currency" "USD"

; Account naming
option "name_assets" "Assets"
option "name_liabilities" "Liabilities"
option "name_income" "Income"
option "name_expenses" "Expenses"
option "name_equity" "Equity"

; Document handling
option "documents" "/path/to/docs"
```

## Comments and Organization

```bean
; Single line comment

* Section Header
** Subsection
; Transaction block follows...

; Account grouping
; Assets
2024-01-15 ...

; Expenses
2024-01-16 ...
```

This reference provides a complete overview of Beancount's [syntax elements](https://beancount.io/docs/Basics/syntax) with practical examples.
