compute_taxable_pnls_detailed

coin2086.compute_taxable_pnls_detailed(trades, initial_portfolio=None, initial_purchase_price=0.0)

Computes your taxable PnL for each sale in the trades DataFrame

In the french tax law (CGI art. 150 VH), taxable events are sales of crypto-currencies for official (fiat) currencies such as Euro. The PnL (profit and loss) arising from each sale must be reported in the form 2086 (Formulaire n°2086).

This function computes the PnL to be reported for each sale on form 2086, and other information that also needs to be reported on form 2086. It returns a DataFrame such as:

             datetime trade_side cryptocurrency  quantity    amount       fee
2 2020-09-05 16:50:00       SELL            BTC       0.5   4361.35  21.80675
3 2020-09-08 12:40:00       SELL            ETH       5.0   1425.35   7.12675
6 2020-12-21 09:30:00       SELL            BTC       1.0  19531.69  97.65845

    amount_net  portfolio_value  portfolio_purchase_price
2   4339.54325        10226.900                11286.4716
3   1418.22325         5679.970                11286.4716
6  19434.03155        31934.785                22507.6584

purchase_price_fraction  purchase_price_fraction_sum
2              4813.213477                     0.000000
3              1624.420281                  4813.213477
6              9828.616024                  6437.633759

   portfolio_purchase_price_net          pnl
2                  11286.471600  -473.670227
3                   6473.258123  -206.197031
6                  16070.024641  9605.415526

The meaning of each column is as follows:

datetime

The date and time of your trade, copied from the input trades DataFrame.

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

trade_side

The side (BUY or SELL) of your trade, copied from the input trades DataFrame

cryptocurrency

The crypto currency you sold, copied from the input trades DataFrame

quantity

The quantity of crypto-currency you sold, copied from the input trades DataFrame

amount

The amount in euro you received in exchange for you sale of crypto-currencies, copied from the input trades DataFrame.

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

fee

The fees in euro you paid for your trade, copied from the input trades DataFrame.

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

amount_net

The amount, net of fees, your received in exchange for your sale of crypto-currencies. This is amount - fee.

portfolio_value

The total value of your portfolio of crypto-currencies before the sale, as computed by coin2086.valuate_portfolio()

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

portfolio_purchase_price

The total purchase price of your porfolio, net of fees, but not accouting for sales.

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

purchase_price_fraction

The fraction of the purchase price that was sold (Fractions de capital initial, see Notice du formulaire n°2086). For instance, if : (1) your portfolio is worth 10226.90 Euros, (2) you receive 4339.54 Euros for a crypto-currency sale and (3) the total purchase price for your portfolio was 11286.4716, it will be considered that of have sold 4339.54 / 10226.90 = 42.6458% of your portfolio. The purchase price for these 42.43% of your porfolio (purchase_price_fraction) is 42.6458% of 11286.4716 = 4813.213477.

purchase_price_fraction_sum

The cumulative sum of the purchase_price_fraction column

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

portfolio_purchase_price_net

The total purchase price of your porfolio, net of fees, and net of the cumulative sum of the purchase price fractions. This is portfolio_purchase_price - purchase_price_fraction_sum.

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

pnl

The PnL (profit and loss) for this sale. You will pay 30% of the sum() of this column as taxes, only if this is a positive number (no taxes if this is a negative number)

[!] This information has to be reported on form 2086 (see coin2086.compute_taxable_pnls() to known in which cell).

Note

Note that the indexes of this DataFrame are the indexes of the sales (trades with trade_side = SELL) of your trades DataFrame.

The input trades DataFrame must have one line per trade, as follows:

             datetime trade_side cryptocurrency  quantity     price
0 2020-07-28 10:20:00        BUY            BTC       1.0   9262.42
1 2020-09-01 12:20:00        BUY            ETH       5.0    393.58
2 2020-09-05 16:50:00       SELL            BTC       0.5   8722.70
3 2020-09-08 12:40:00       SELL            ETH       5.0    285.07
4 2020-09-16 17:10:00        BUY            BTC       1.0   9247.51
5 2020-11-07 15:40:00        BUY            ETH       5.0    383.57
6 2020-12-21 09:30:00       SELL            BTC       1.0  19531.69

base_currency    amount       fee
0           EUR   9262.42  46.31210
1           EUR   1967.90   9.83950
2           EUR   4361.35  21.80675
3           EUR   1425.35   7.12675
4           EUR   9247.51  46.23755
5           EUR   1917.85   9.58925
6           EUR  19531.69  97.65845

Warning

The trades must be sorted by increasing datetime, this can be achieved as follows trades.sort_values('datetime').reset_index(drop=True).

The columns must follow the following specification:

datetime

The date and time of your trades in the UTC timezone. If the time is not in the UTC timezone, the computed valuation of your portfolio will be wrong.

trade_side

The side of your trade, either BUY or SELL (uppercase)

cryptocurrency

The crypto-currency you bought or sold

quantity

The quantity of crypto-currency you bought or sold

price

The price at which you bought or sold the crypto-currency

base_currency

The base currency you bought or sold the crypto-currency for. For now, it must be EUR (uppercase)

amount

The amount of base_currency you received or spent, respectively for selling or buying a crypto-currency.

fee

The exchange fee for the trade. Must be expressed in base_currency.

Parameters
  • trades (pandas.DataFrame) – A normalized DataFrame of trades (see paragraph above). It must include all your buy and sell trades since you bought your first crypto-currency. If this is not the case, you will have to determine your initial portfolio (see initial_portfolio argument), and the purchase price of your initial porfolio.

  • initial_portfolio (dict) –

    A dictionary representing your portfolio of crypto-currencies as it was before the first trade in the trades DataFrame (see trades argument). The keys of the initial_portfolio dictionary are the crypto-currencies, and the values are the quantities. For example:

    {
        'BTC': 2,
        'ETH': 50,
        'LTC': 100
    }
    

  • initial_purchase_price (float) – The purchase price of the initial_portfolio

Returns

The DataFrame containing the information to be reported on form 2086 for each sale in the trades DataFrame.

Return type

pandas.DataFrame