9.7. Vendere le azioni

Entering an investment you are selling is done in the same way as buying one (see Sezione 9.5.2, «Acquistare nuove quote») except the total cost of the transaction is entered in the Sell column and the Shares column is entered as a negative amount. The net proceeds from the sale should be transferred from the stock account to your bank or brokerage account.

La registrazione corretta della vendita delle azioni DEVE avvenire utilizzando una transazione suddivisa. In essa occorre contabilizzare il profitto (o la perdita) come entrata derivante da un conto Entrate:Guadagni in capitale (o Uscite:Perdita in capitale). Per bilanciare questa entrata, è necessario inserire nella suddivisione, per due volte, l’attività derivante dalle azioni: una per registrare la vendita (utilizzando il numero corretto di azioni e del prezzo unitario) e una volta per bilanciare il profitto ottenuto (impostando il numero di azioni a 0 e il prezzo unitario anch’esso a 0).

Nota

In order to get GnuCash to commit this zero-share, zero-price split to the transaction, you *must* Tab out of the split. If you use the Enter key, GnuCash will convert the split into shares of the commodity.

Nello schema con transazione suddivisa presentato di seguito, il simbolo NUM_AZIONI rappresenta il numero di azioni che si desidera vendere, PREZZO_VENDITA è il prezzo con il quale vengono vendute le azioni, VENDITA_LORDA è il totale ottenuto dalla vendita delle azioni ed è pari a NUM_AZIONI x PREZZO_VENDITA; UTILE è l’importo di denaro ricavato dalla vendita; COMMISSIONI sono le spese di mediazione sostenute e infine VENDITA_NETTA è l’importo netto di denaro guadagnato con la vendita e pari a VENDITA_LORDA - COMMISSIONI.

Tabella 9.1. Vendere azioni utilizzando lo schema della transazione suddivisa

Conto Numero di quote Prezzo quota Acquisto totale Vendita totale
Attività:Banca ABC    VENDITA_NETTA  
Attività:Azioni:SIMBOLO 0 0 UTILE (Perdita)
Uscite:Commissioni    COMMISSIONI  
Attività:Azioni:SIMBOLO -NUM_AZIONI PREZZO_VENDITA   VENDITA_LORDA
Entrate:Guadagni in capitale    (Perdita) UTILE

Se la vendita delle azioni verrà registrata come un guadagno in conto capitale, consultare Capitolo 11, Guadagni in conto capitale e Capitolo 16, Deprezzamento per ricevere ulteriori informazioni sull’argomento.

9.7.1. Esempio - Vendita delle azioni in guadagno

As an example we will use the AMZN account created in the previous section. So you bought 100 shares of AMZN for $20 per share, then later sell them all for $36 per share with a commission of $75. In the split transaction scheme above, PRICEBUY is $20 (the original buying price), NUM_SHARES is 100, TOTALBUY is $2000 (the original buying cost), GROSS_SALE is $3600, and finally PROFIT is $1525 (GROSS_SALE-TOTALBUY-COMMISSION).

Tabella 9.2. Schema a transazione suddivisa per la vendita delle azioni

Conto Quote Prezzo Compra Vendi
Attività:Banca ABC    3525,00  
Attività:Conto di brokeraggio:Azioni:AMZN 0 0 1600,00  
Uscite:Commissioni    75,00  
Attività:Conto di brokeraggio:Azioni:AMZN -100 36,00   3600,00
Entrate:Guadagni in capitale (lungo):AMZN     1600,00

Esempio di vendita delle azioni

Un esempio di vendita delle azioni in guadagno. Sono state acquistate 100 azioni di AMZN per €20 ad azione e vendute a €36.

Esempio di vendita delle azioni

Immagine della struttura dei conti dopo l’esempio di vendita dell’azione per il guadagno.

9.7.2. Esempio - Vendere le azioni in perdita

As an example we will use the IBM account created in the previous section. You then have bought 51.7598 shares of IBM for $96.6001 per share, then later sell them all for $90 per share. In the split transaction scheme below, PRICEBUY is $96.6001 (the original buying price), NUM_SHARES is 51.7598, TOTAL_BUY is $5,000 (the original buying price), (Loss) is $341.62, and finally GROSS_SALE is $4658.38. Assume the commission was $100.00.

Tabella 9.3. Vendita delle azioni in perdita utilizzando lo schema a transazione suddivisa

Conto Quote Prezzo Compra Vendi
Attività:Banca ABC    4558,38  
Attività:Conto di brokeraggio:Azioni:IBM 0 0   341,62
Uscite:Commissioni    100  
Attività:Conto di brokeraggio:Azioni:IBM -51,7598 90,00   4658,38
Entrate:Guadagni in capitale (lungo):IBM    341,62 0

Nota

É possibile anche inserire la perdita come un numero positivo nella colonna «Compra» o come un numero negativo nella colonna «Vendi»; GnuCash sposterà automaticamente il «profitto negativo» nell’altra colonna.

Esempio di vendita delle azioni in perdita

Sopra è riportata un’immagine dell’esempio di vendita della azioni. Sono stati acquistati €5000 in azioni IBM a €96,6001 cadauna e vendute per €90.

Esempio di vendita delle azioni in perdita

Un’immagine della struttura dei conti derivata dall’esempio di vendita delle azioni in perdita.

9.7.3. Automatic Calculation of Capital Gain or Loss Using Lots

9.7.3.1. Introduzione

Wikipedia includes the following definition of a lot:

«a set of goods for sale together in an auction; or a quantity of a financial instrument».

GnuCash has a built-in lot management facility that can be used to keep track of capital gains or losses resulting from security sales. Buy and sell transactions are put into lots for the purpose of calculating the cost of the sale. More specifically, a lot is used to link particular buy and sell transaction splits. Lots can be automatically or manually created and linked. Capital gain or loss can be automatically calculated and transaction(s) created for the difference between the sale value and the cost of the securities sold. GnuCash refers to this process as scrubbing.

The term scrub is used because security accounts need to be cleaned after sales to ensure the difference between the cost paid for securities, and value received from selling them, is accounted for as capital gain or loss. If the capital gain/loss is not correct, the Trial Balance ( ReportsIncome & ExpenseTrial Balance ) bottom line total debits will not balance to total credits.

Nota

If you make an error, you can delete the capital gain/loss transaction(s) and lot(s) and retry.

If you are not familiar with FIFO, LIFO or Average costing, please see Wikipedia FIFO and LIFO accounting and Average cost method.

If you are not familiar with the difference between GnuCash transactions and splits, please see Sezione 4.3, «Simple vs. Split Transactions».

The GnuCash lot management facility can be a useful feature, reducing manual calculation, especially if dividends have been reinvested over years and there are many different costs involved. It can automatically link buy transactions to sell transactions using FIFO cost method and one can manually link specific buy transactions to sell transactions in order to use LIFO. Advanced Portfolio Report basis costs and gains/losses will agree with the costs and gain/loss transactions created by scrubbing if either the FIFO or LIFO cost methods are used.

9.7.3.2. Lots in Account Window

The Lots in Account SSSS window, where SSSS is a security account, is used to manually or automatically link security transaction splits to lots and create capital gain/loss transactions to account for the difference between the costs of buying a security and the value received by selling it.

To open the Lots in Account window, open the security account register, then select ActionsView Lots .

Figura 9.1. Selling Shares - Capital Gains - Lots in Account window

Example of Lots in Account window

An image of the Lots in Account window.


Refer to the Help Manual, Chapter 8 Tools & Assistants, Lots in Account for details of the Lots in Account screen elements.

9.7.3.3. Procedure Summary

Using the lot management facility for the automatic calculation of capital gain or loss typically follows these steps:

9.7.3.4. Manual Lot Creation and Linking

Before using this feature, ensure you have read Sezione 9.7.3.8, «Considerations».

This functionality allows the manual linking of specfic buy and sell transactions. It may be used in the case where a user wishes to use a different cost method than the automatic linking method (FIFO). Effectively, if one wishes the cost basis and capital gains in the Advanced Portfolio Report to be consistent with the capital gains transactions created by scrubbing, manual lot creation only needs to be used when using LIFO or «sale of designated lots» (the same thing for securities as far as US personal tax law is concerned). This is because the scrub function can automatically do FIFO linking so there is no need to do it manually and scrubbing cannot be used for average costing.

See Sezione 9.7.3.9, «Example of Manual Lot Creation and Linking».

9.7.3.5. Automatic Creation of Capital Gain Or Loss Transactions

Nota

Do NOT do this unless you are using FIFO or LIFO to cost sales. See Sezione 9.7.3.8, «Considerations»

GnuCash can automatically calculate and create security sale capital gain/loss transactions. Lots are used to link buy transaction splits with sell transaction splits so the correct cost of the securities sold can be determined. GnuCash will use any existing lots, and create new lots for any buy transaction splits not already linked to a lot. Buy and sell transaction splits are linked to lots using FIFO method.

See:

Sezione 9.7.3.10, «Example 1 of Automatic Creation of Capital Gain Or Loss Transactions»

Sezione 9.7.3.11, «Example 2 of Automatic Creation of Capital Gain Or Loss Transactions - 2 Sales at Once»

Sezione 9.7.3.12, «Example 3 of Automatic Creation of Capital Gain Or Loss Transactions - After a Simple Stock Split»

9.7.3.6. Change Orphaned Gains-CCC to Gain/Loss Account

The capital gain/loss transaction(s) created by scrubbing uses an automatically created generic Orphaned Gains-CCC account (where CCC is the security currency) because GnuCash doesn't know which capital gain or loss account should be used. After scrubbing, the user should edit the Orphaned Gains-CCC transaction split to re-assign the income account to a more meaningful income (or expense) gain or loss account (e.g. Income:Long Term Capital Gain:IBM).

See Sezione 9.7.3.13, «Example of Changing the Orphaned Gains-CCC to Gain/Loss Account».

9.7.3.7. Run a Trial Balance

Running a Trial Balance report ( ReportsIncome & ExpenseTrial Balance ) after creating capital gain/loss transactions, is a basic check that capital gains/losses are correctly accounting for the difference between the cost paid for securities, and value received from selling them. At the end of the report, total debits should equal total credits.

Suggerimento

A Trial Balance may not balance due to some other problem. To determine if the cause of an imbalance is from incorrectly accounting for capital gain/loss:

If necessary, temporarily change the date of the sell transaction and the capital gain/loss transaction, so they are the only transactions for a particular date, then run the Trial Balance as at the day before. If the Trial Balance is still out by the same amount, it is not the capital gain/loss that is causing the problem.

If you find a prior out of balance Trial Balance, keep running the Trial Balance report with different dates until you find the date it starts being out of balance. Temporarily change the transaction dates for each transaction on the problem date to the following day, then change the dates back to the correct date 1 at a time, running the Trial Balance each time, until you identify the problem transaction. When you change the date of a security sell transaction, you also need to change the date of the corresponding capital gain transaction as it is only the sum of these that will balance in the Trial Balance.

9.7.3.8. Considerations

There are some points that should be considered before using the lot management facility.

  1. GnuCash implements only the First In/ First Out (FIFO) cost method when automatically linking buy transactions to sell transactions. I.e. The oldest securities are always sold first. The Last In First Out (LIFO) cost method may be used by manually linking the most recent buy security splits to the sell split before scrubbing.

  2. The Advanced Portfolio Report does not use lot information when calculating costs, just the security transaction splits. It calculates the cost basis and gains or losses using the selected Basis calculation method report option (Average, FIFO or LIFO). If one wishes the Advanced Portfolio Report costs and gains/losses to be consistent with the capital gain/loss transactions created by scrubbing, the same cost model must be used in both places.

  3. Scrubbing does not work correctly if there has been a previous sale where the capital gain splits have been manually entered as part of the sale transaction. Therefore ensure previous sales are recorded as 2 transactions:

    Tabella 9.4. Transaction 1 dealing with value received, reduction of the number of shares and (optionally) commission

    Conto Tot Shares (Unit) Price Buy (Debit) Sell (Credit)
    Brokerage or Bank    Debit  
    Commission (optional)    Debit  
    Titolo -NumSold SaleUnitPrice   SaleValue

    Tabella 9.5. Transaction 2 capital gain/loss (loss in this example)

    Conto Tot Shares (Unit) Price Buy (Debit) Sell (Credit)
    Capital Loss    Debit  
    Titolo 0 0   Credit

  4. The automatic capital gains calculations can handle straightforward buy, sell, and return of capital transactions but any transaction that affect the number of shares, even simple splits, will cause it to produce wrong answers so those cases must be handled manually.

9.7.3.9. Example of Manual Lot Creation and Linking

Here is an example of selling part of a security holding using the LIFO method. In this example, the most recent buy transaction (dated 01/07/2016, a reinvested dividend), is linked to a lot, along with the sell transaction, and the GnuCash scrub function is used to calculate capital gain or loss and create the capital gain/loss transaction.

  1. Open the security account's register.

    Figura 9.2. Selling Shares - Capital Gains - Security register before scrubbing a single lot

    Example of security register before lot scrubbing

    An image of the Security Account register in transaction journal view, before lot scrubbing.


  2. Ensure all previous capital gain/loss transactions are separate transactions to the sell transactions which record the reduction in the number of shares and the value received.

  3. Select ActionsView Lots to open the Lots in Account SSSS window where SSSS is the security account.

    Figura 9.3. Selling Shares - Capital Gains - Lots before scrubbing a single lot

    Example of Lots in Account window before lot scrubbing

    An image of the Lots in Account window before lot scrubbing.


  4. Create a new lot using the New Lot button. Initially this lot is not linked to any buy or sell split.

  5. Highlight the new lot in the Lots in This Account panel.

  6. Highlight the buy split (dated 01/07/2016) of the security to be sold in the Splits free panel.

  7. Click the >> button to link the buy split with the highlighted lot. The split moves from the Splits free panel to the Splits in Lot panel.

  8. Repeat the previous 2 steps for any other buy splits that should be included in the lot (in this example, there is only 1 buy split in the sale).

  9. Highlight the sell split in the Splits free panel.

  10. Click the >> button to link the sell split with the highlighted lot.

  11. Check the lot Balance is as expected. I.e. in this example the lot balance should be zero as the number of securities sold in the lot, is matched with the same number of security buys.

    Figura 9.4. Selling Shares - Capital Gains - Lots before scrubbing a single lot, after manual linking

    Example of Lots in Account window before scrubbing a single lot

    An image of the Lots in Account window before scrubbing a single lot.


  12. Click the Scrub button (NOT the Scrub Account button).

    The Lots in Account window has not changed after using the Scrub button so no example screen image is supplied.

  13. Continue to Sezione 9.7.3.6, «Change Orphaned Gains-CCC to Gain/Loss Account»

9.7.3.10. Example 1 of Automatic Creation of Capital Gain Or Loss Transactions

Create the capital gains transaction by following these steps:

  1. Open the security account's register.

  2. Ensure the sell transaction has been entered with no splits for capital gains or losses.

  3. Select ActionsView Lots to open the Lots in Account SSSS window where SSSS is the security account.

  4. If using LIFO, use the above procedure Sezione 9.7.3.4, «Manual Lot Creation and Linking» to create a lot for each sell transaction, link the lot with the sell transaction and each of the buy transactions that make up the sale.

  5. Click the Scrub Account button which:

    • Creates lots for any buy transactions that are not already linked to a lot and links them to sell transactions splits using the FIFO method. As a transaction split can only be linked to 1 lot, if a sell transaction needs to be linked to multiple lots, the sell transaction split is itself split into multiple subsplits. In the case of multiple subsplits, it is possible to have different splits from the same transaction in both the Splits free and Splits in lot panels.

    • Creates a separate transaction per lot for capital gain/loss.

      Nota

      If there are already gain/loss splits as part of a sell transaction, GnuCash scrubbing does not recognize them. So if manually adding gain/loss, separate gain/loss transaction splits from the transaction that reduces the No of Shares) by putting them in a separate transaction if you may use scrubbing in future.

  6. Continue with the instructions in the next section.

9.7.3.11. Example 2 of Automatic Creation of Capital Gain Or Loss Transactions - 2 Sales at Once

Here is an example of FIFO scrubbing without manual lot creation. In this example, the transactions for 2 sales are scrubbed at once but usually scrubbing would be performed after each sale. One reason for scrubbing 2 sales at once, could be because there were multiple sales on the same day.

Figura 9.5. Selling Shares - Capital Gains - Register before Scrub Account

Example of security register before Scrub Account is used.

An image of the Security Account register in transaction journal view, before Scrub Account is used.


  1. Select ActionsView Lots to open the Lots in Account SSSS window where SSSS is the security account.

    Figura 9.6. Selling Shares - Capital Gains - Lots before Scrub Account

    Example of Lots in Account window before Scrub Account is used.

    An image of the Lots in Account window before Scrub Account is used.


  2. Click the Scrub Account button.

    Figura 9.7. Selling Shares - Capital Gains - Lots after Scrub Account

    Example of Lots in Account window after using Scrub Account

    An image of the Lots in Account window after using Scrub Account.


    Nota

    After using the Scrub Account button only the last lot is shown, so the above image is after the Lots in Account window has been closed and reopened so all the lots show.

  3. Close the Lots in Account SSSS window and return to the security account register.

    Figura 9.8. Selling Shares - Capital Gains - Register after Scrub Account

    Example of security register after using Scrub Account

    An image of the security register after using Scrub Account.


    Nota

    The security splits in the sell transactions have been split into subsplits, one subsplit per lot, and a capital gain transaction has been created for each security subsplit of each sell transaction.

  4. Continue to Sezione 9.7.3.6, «Change Orphaned Gains-CCC to Gain/Loss Account»

9.7.3.12. Example 3 of Automatic Creation of Capital Gain Or Loss Transactions - After a Simple Stock Split

Here is an example of FIFO scrubbing without manual lot creation/linking, where the Stock Split Assistant has been used for a simple stock split. In this example, 100 shares of security XYZ were bought for $10.00 each, there was a simple 2 for 1 stock split for zero cost (so the holding was then 200 shares @ $5.00 each), then all 200 shares were sold for $6.00 each.

Figura 9.9. Selling Shares - Capital Gains - Register after Scrub Account

Example of security register after Scrub Account is used.

An image of the Security Account register in transaction journal view, after Scrub Account is used.


Figura 9.10. Selling Shares - Capital Gains - Lot 0 after Scrub Account

Example of security register after Scrub Account is used.

An image of the Security Account register in transaction journal view, after Scrub Account is used.


Figura 9.11. Selling Shares - Capital Gains - Lot 1 after Scrub Account

Example of security register after Scrub Account is used.

An image of the Security Account register in transaction journal view, after Scrub Account is used.


The above screen shots show that scrubbing created:

2 lots. A separate lot for each buy (it essentially treats the stock split as a buy of 100 for no cost)

2 capital gain transactions (one for each lot) on the date of the sale:

  • Lot 0: 1/7/2009 loss $400 (sale $600 - cost $1000)

  • Lot 1: 1/7/2009 gain $600 (sale $600 - cost $0)

Total gain $200 is correct. Whether the gain is a single long-term one or one each of long-term and short-term or whether there's even a distinction depends on the user's tax jurisdiction and the way the split is structured. If the user needs help figuring it out they should consult a professional.

9.7.3.13. Example of Changing the Orphaned Gains-CCC to Gain/Loss Account

  1. Close the Lots in Account SSSS window if open and return to the security account register.

    Figura 9.12. Selling Shares - Capital Gains - Register after scrubbing a single lot

    Example of security register after scrubbing a single lot

    An image of the security register after scrubbing a single lot.


  2. Find each new Realized Gain/Loss transaction in the security account register (they will have the same date as the sell transactions). Edit the Orphaned Gains-CCC transaction split to re-assign the income account to a more meaningful income (or expense) gain or loss account (e.g. Income:Long Term Capital Gain:IBM).

    Suggerimento

    You may like to split the capital gain/loss into taxable and non taxable parts if that is in accord with your tax laws.