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).
π Cost Basis
The cost basis of your holdings is the total amount you've paid, including fees:
\[
\text{Cost Basis} = \sum_{i} (Q_i \times P_i + F_i)
\]
This is used to compute unrealized P&L at any point:
\[
\text{Unrealized P\\&L} = \text{Current Value} - \text{Cost Basis}
\]