Skip to content

Buy & Sell

The most fundamental transaction types: buying increases your holdings and decreases cash; selling does the reverse and realizes a profit or loss.


๐Ÿ”‘ Key Properties

Property Buy Sell
Code BUY SELL
Cash effect โฌ‡๏ธ Decreases โฌ†๏ธ Increases
Asset effect โฌ†๏ธ Increases holdings โฌ‡๏ธ Decreases holdings
Tax event No Yes (realizes gain/loss)

๐Ÿ“Š How It Works

๐Ÿ›’ Buy

When you buy an asset, a lot is created with:

  • Date: When the purchase occurred
  • Quantity: Number of shares/units bought
  • Unit price: Price per share at the time of purchase
  • Fees: Any transaction fees (commission, spread, etc.)
  • Total cost: quantity ร— unit_price + fees

๐Ÿ’ฐ Sell

When you sell, LibreFolio matches the sale against existing lots using FIFO (First In, First Out) to determine:

\[ \text{Capital Gain} = (P_{sell} \times Q) - (P_{buy} \times Q) - \text{Fees} \]

FIFO Matching

LibreFolio computes lot matching at runtime โ€” it's not persisted in the database. This allows for flexible what-if analysis and potential future support for other matching methods (LIFO, specific identification).


  • ๐Ÿ“Š Weighted Average Cost (WAC) โ€” Average cost per unit across multiple buys
  • ๐Ÿ”ฌ FIFO Lot Analysis โ€” Per-lot drill-down into the FIFO matching introduced above
  • ๐Ÿ’ฐ Taxation โ€” Capital gains, matching methods, loss carry-forward
  • ๐Ÿ“ˆ Returns โ€” Measuring investment performance