I want to keep track of the full price I've payed for investments on ledger, to know the weighted average price.

So given the following register taked from the documentation:

2004/05/01 Stock purchase
    Assets:Broker                     50 AAPL @ $30.00
    Expenses:Broker:Commissions        $19.95
    Assets:Broker                  $-1,519.95  ; note_1

I can use an automated transaction to know how many AAPL I have using something like:

= expr ( commodity == 'AAPL' and /^Assets:/)
    (Allocation:Equities)             1.000

This way I can now how much AAPL I currently have, but I cannot know how much I have invested, specificaly I would like to keep track of all the postings like the one with the note_1 on the first example.

This way I can keep track of the total price I've payed for the investments I have, that can be calculated by:

$-1,519.95 / 50 AAPL

Is there any good way to keep track of that?


2 Answers 2


ledger-cli v3.2.0 (released on May 1, 2020) introduced a new option: --average-lot-prices (reports the average price at which each commodity was purchased in a balance report).


You've clearly gone through the Buying and selling stock section of the manual. After the example you've quoted, the example for the sale shows the actual syntax recognized by Ledger. That is, each stock purchase creates a Lot. The same information you should be able to see at your broker's interface.

Each Lot contains information on the base stock price paid and the date paid for every batch of stocks purchased (or sold). This gives you detailed information about your holdings. In your case, running ledger balance broker --lots would show

50 AAPL {$30.00} [2004/05/01]   Assets:Broker

This is just to expand on the answer provided by @tbm, which should be enough if you are only looking for the average stock price for the complete stock holding.

You can also be more specific in naming your transaction, i.e. use "AAPL Purchase" and then you can get those transaction by searching for a @Payee and see the fees paid, total cash used, etc. The lots will give you all the information about the stock holdings.

I would also suggest separating stock holdings into separate accounts, i.e. Assets:Broker:AAPL but that's a personal choice.

Another thing you may be looking for is Unrealized Gains/Losses report, which will automatically calculate the unrealized gains or losses for you based on the last-known market price of the asset.

ledger bal assets and xyz --unrealized -X AUD
        1,098.30 AUD  Assets:Investments:Broker:Shares:XYZ
        3,912.04 AUD  Equity:Unrealized Losses

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .