Investments: cost basis, market value and gains
General educational material, not professional advice. This page explains how investments are recorded, not what to invest in or how gains are taxed. See Not professional advice.
Buying investments at cost (cost basis)
When you buy shares, a fund, a coin or any other asset priced in something other than your currency, you record two things: the quantity you got and what you paid. What you paid is the cost basis. It is what gains and losses are measured against later.
hledger writes the quantity as its own commodity and the cost after @ (per unit) or @@ (in total):
2026-01-05 Fund the brokerage account
assets:brokerage:cash $5,000.00
assets:bank:checking $-5,000.00
2026-01-10 Buy 10 shares of VTI
assets:brokerage:VTI 10 VTI @ $200.00
assets:brokerage:cash $-2,000.00
10 VTI @@ $2,000.00 means the same thing. Brokerage fees can be included in the cost, which raises the basis, or posted to expenses:fees. The first matches how cost basis is usually reported for tax in many places.
hledger balance shows the account holding 10 VTI. hledger balance -B (--cost) shows it at cost, $2,000.00.
Market value and price directives (P)
The market value of a holding is its quantity times the current price. Prices go in the journal as P directives, each with a date, a commodity and its price in another commodity.
2026-01-05 Fund the brokerage account
assets:brokerage:cash $5,000.00
assets:bank:checking $-5,000.00
2026-01-10 Buy 10 shares of VTI
assets:brokerage:VTI 10 VTI @ $200.00
assets:brokerage:cash $-2,000.00
P 2026-06-30 VTI $230.00
hledger balance -V -e 2026-07-01 values the holding with the latest price on or before the report’s end, here $2,300.00. Without a price, hledger can only show the share count.
Ledgeline can write P directives for you from Yahoo Finance. See Prices and valuation. That page also explains why the balance sheet and the Holdings tab can use slightly different prices.
Cost vs market value (which one your reports show)
The same holdings can be reported two ways:
- At cost: what you paid. Stable and objective, but out of date as prices move.
- At market value: what they would fetch today. Current, but it moves with every price change.
Formal accounting standards decide this per kind of asset, and the rules differ between GAAP, IFRS and tax law. For personal net worth, market value is what most people want. For tax records, cost basis is what matters.
In hledger, plain balance shows quantities, -B shows cost, and -V shows market value. Ledgeline’s balance sheet and net worth reports let you choose, and Holdings shows cost and market value side by side.
Unrealized gains (paper gains on holdings you still own)
An unrealized gain (or loss) is the difference between a holding’s market value and its cost basis while you still own it. In the example above, 10 shares that cost $2,000 and are worth $2,300 carry a $300 unrealized gain.
It is unrealized because you haven’t sold, and the price could fall before you do. Most personal and small-business books don’t record unrealized gains as transactions. They show up in reports when you value at market. hledger balance --gain shows market value minus cost, and the Valuation adjustment line on Ledgeline’s balance sheet holds the difference that keeps the sheet balanced.
Realized gains (selling an investment)
A realized gain (or loss) happens when you sell. It is the sale proceeds minus the cost basis of the units sold. It is real income, and it is usually what gets taxed.
The common hledger pattern takes the units out of the account at their cost, records the cash you received, and posts the difference to a gains account:
2026-01-05 Fund the brokerage account
assets:brokerage:cash $5,000.00
assets:bank:checking $-5,000.00
2026-01-10 Buy 10 shares of VTI
assets:brokerage:VTI 10 VTI @ $200.00
assets:brokerage:cash $-2,000.00
2026-09-01 Sell 4 shares of VTI at $250
assets:brokerage:cash $1,000.00
assets:brokerage:VTI -4 VTI @ $200.00
revenue:capital gains $-200.00
The 4 shares cost $800 and sold for $1,000, so $200 is a realized gain. Writing the sale at cost (@ $200.00) keeps the remaining 6 shares at their true cost of $1,200 in -B reports. A loss works the same way with a positive amount to the gains account, or to a separate expenses:capital losses.
Lots, FIFO and average cost for investments
If you bought the same investment several times at different prices, each purchase is a lot with its own cost. A sale then needs a rule for which lots it uses, such as first in, first out (FIFO), specific lots you choose, or the average cost of all of them. The rule you may use for tax depends on your country and, sometimes, on the kind of investment.
Ledgeline’s Holdings tab shows average-cost basis. For tax reporting, follow your broker’s cost-basis statements, which apply the rules for your jurisdiction.
Dividends and interest from investments
Dividends and interest are income when they are paid, separate from any change in price.
2026-03-20 VTI dividend
assets:brokerage:cash $16.40
revenue:dividends $-16.40
A reinvested dividend is two steps in one, the dividend as income and then a purchase of more units at cost. Ledgeline’s holdings performance doesn’t count dividends yet. See Holdings.
Other assets that change value
Houses, cars, collectibles and crypto follow the same ideas. Record the purchase at cost, add P prices or valuations as you get them, and decide whether a decline is a market price change or wear and tear that you depreciate. See The holdings and valuation tags and Crypto.