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).
๐ Related
- ๐ 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