I could not find the detailed information about lot tracking in ledger and would appreciate if someone took the time to make it explicit.

If I have two purchase transactions for a fund, at 100 units each, and then I sell 150 in a single transaction, how would the ledger entries look like?

In this simplified example I'd like to learn the basics of lot tracking, which would then apply to more complex scenarios.

Having an automatic FIFO principle applied would help. If not, I'm wondering how to identify which lots are to be sold when there are dozens of transactions in the account.


  • 2
    If "ledger" is a common noun, then it requires a determiner, and if it's a proper noun, proper nouns in English are generally denoted by capitalization. Commented Apr 15, 2019 at 21:44
  • 1
    @Acccumulation: Even if it's a proper noun, it needs disambiguation. There could be a thousand accounting software programs with a module named "Ledger".
    – Ben Voigt
    Commented Apr 15, 2019 at 22:34

2 Answers 2


I believe the Ledger manual's 4.5.2 Buying and Selling Stock has the answer: you can specify the exact lot you mean to sell by writing its purchase price and/or date. If using both, I think it would be like this:

2005/08/01 Stock sale
    Assets:Broker                    -50 AAPL {$30.00} [2004/05/01] @ $50.00
    Expenses:Broker:Commissions        $19.95
    Income:Capital Gains           $-1,000.00
    Assets:Broker                   $2,480.05

In the US, you can designate to your broker which shares are to be sold. If the lots are not designated at the time of sale, the basis of the stock sold is FIFO. For mutual funds and certain DRIPS, and average cost per share can be used to determine gain P&L but you can't flip flop back and forth once averaging is chosen.

In your example, there are two purchases of 100 shares each and a sale of 200 shares. There is no designation since all shares are being sold in one transaction, FIFO applies. This doesn't change if there are dozens of trades in the account (buy multiple lots and then sell all at once) and then repeat the same sequence again.

When there are dozens of transactions in the account and one is scaling a position up and down (+100, +100, + 300, -400, etc.) then designation must occur at the time of sale. In this example, with designation, the 100 shares not sold could be from any of the 3 purchases. You cannot mix and match these, after the fact. If no designation had been made, 100 shares of the third purchase would be owned after the sale of 400 shares (FIFO).

  • Thanks, Bob. Just to confirm, you are referring to how ledger cli handles the purchase? And yes, that's exactly what I was asking, except that I wanted to keep it short since I'm writing on a tablet. But it turned out almost irrelevant as everything is being sold. If I sold 100 or 150, it would be a better example. Commented Apr 16, 2019 at 5:16
  • I was referring to how tax law (US) specifies the handling of sales. Commented Apr 16, 2019 at 12:25
  • 1
    OK, sorry for the confusion. I was unable to add "ledger-cli" tag on creation. I've adjusted the question and the title by referring to ledger-cli. I'm interested in a concrete example of ledger's syntax for this scenario. Commented Apr 16, 2019 at 15:19
  • No problem. I didn't realize from the initial question that you were referring to specific software. Commented Apr 16, 2019 at 15:33

You must log in to answer this question.

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