compute_taxable_pnls¶
- coin2086.compute_taxable_pnls(trades, year, 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:
Description Date de la cession [datetime] 2 SELL 0.50 BTC 2020-09-05 16:50:00 3 SELL 5.00 ETH 2020-09-08 12:40:00 6 SELL 1.00 BTC 2020-12-21 09:30:00 Valeur globale portefeuille [portfolio_value] Prix de cession [amount] 2 10226.900 4361.35 3 5679.970 1425.35 6 31934.785 19531.69 Frais de cession [fee] Prix de cession net des frais [amount_net] 2 21.80675 4339.54325 3 7.12675 1418.22325 6 97.65845 19434.03155 Prix total d'acquistion [portfolio_purchase_price] 2 11286.4716 3 11286.4716 6 22507.6584 Fractions de capital initial [purchase_price_fraction_sum] 2 0.000000 3 4813.213477 6 6437.633759 Prix total d'acquistion net [portfolio_purchase_price_net] 2 11286.471600 3 6473.258123 6 16070.024641 Plus-values et moins-values [pnl] 2 -473.670227 3 -206.197031 6 9605.415526
You may copy directly the value of each cell (Date de la cession, Valeur globale portefeuille etc.) direcly in the form 2086 (Formulaire n°2086). Internally, this
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 followstrades.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.year (int) – The year to report your trades for. Usually, this is the last year.
initial_portfolio (dict) –
A dictionary representing your portfolio of crypto-currencies as it was before the first trade in the
trades
DataFrame (seetrades
argument). The keys of theinitial_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, with the sum of the PnLs (Plus et moins values)- Return type
(pandas.DataFrame, float)