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


πŸ“ 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} \]

  • πŸ’° Taxation β€” Capital gains, matching methods, loss carry-forward
  • πŸ“ˆ Returns β€” Measuring investment performance