BittyTax / BittyTax

Crypto-currency tax calculator with support for all popular wallets, exchanges, explorers and migration from other crypto tax platforms
GNU Affero General Public License v3.0
424 stars 114 forks source link

Crypto Futures - tax calculation of capital gains #22

Closed Visema closed 4 months ago

Visema commented 4 years ago

Hi nanonano, I know the current version of the software does not deal specifically with futures but just wanted to double check with you to make sure my understanding is correct.

Due to foreign exchange effect, CGT calculations might be inaccurate if the transaction records file includes futures.

Example:

With current code Capital Gains =GBP 3.75601
calculation -> [(400 / 1.28 - 400/1.30) / 1.28 ]

Capital Gains should be = GBP 0 calculation -> (400-400)/1.28 = 0

thx Vi

nanonano commented 4 years ago

That is correct BittyTax does not currently handle futures trades, only spot trades.

As it works today, the buy trade is given a GBP valuation at the time of purchase which is used as the acquisition cost for the section 104 holding of that asset (i.e. ETH).

When the ETH is sold (a disposal) another valuation is made in GBP which gives the proceeds required for the GCT calculation, buy/sell fees are also taken into consideration.

I need to read up on the tax laws for futures, but assume each asset/currency pair would need to be held in a separate pool (not section 104) to calculate the gain/loss correctly?

Visema commented 4 years ago

CAVEAT: I am not a tax expert or an accountant

this is my understanding of how it should work: Assume same day trade BUY 3 ETH-USD 25-DEC-2020 FUTURES at 360.00 Commission USD 2.0 Sell 3 ETH-USD 25-DEC-2020 FUTURES at 370.00 Commission USD 2.0

Calculation = (3 370) - 2 – (3 360) – 2 = PROFIT of USD 26 which once converted into GBP at the relevant exchange rate, say GBPUSD=1.30, equals GBP 20

I believe Same Day, 30d B&B and 104-S rules would still apply

Visema commented 3 years ago

hi just wondering if there is any update on this issue . tks

nanonano commented 3 years ago

I've been reading up on the taxation rules for futures, the consensus is that crypto futures trading is liable for income tax not capital gains. The quote below is taken from here https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56004.

Profits from transactions in commodity and financial futures dealt in on a futures exchange which is not recognised will be liable to tax as income if the transactions do not amount to trading.

The list of recognised futures exchanges is given here: https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56120. As you can guess, no crypto trading exchanges are included, maybe that will change in the future.

I'm working on a parser for Deribit which will include a new income type Futures, once that's implemented you can enter your futures profit/loss manually for other exchanges, or additional parsers can be added, out of interest which exchange did you use for your futures trading?

Visema commented 3 years ago

Hi and thank you for your reply I use Binance and Deribit to trade options and futures and will be looking at Coinflex soon as they are the only one that have physical delivery ( the others have vash settlement) will look into the hmrc link carefully and revert back thank you

On 29 Dec 2020, at 14:16, Scott Green notifications@github.com wrote:



I've been reading up on the taxation rules for futures, the consensus is that crypto futures trading is liable for income tax not capital gains. The quote below is taken from here https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56004.

Profits from transactions in commodity and financial futures dealt in on a futures exchange which is not recognised will be liable to tax as income if the transactions do not amount to trading.

The list of recognised futures exchanges is given here: https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56120. As you can guess, no crypto trading exchanges are included, maybe that will change in the future.

I'm working on a parser for Deribit which will include a new income type Futures, once that's implemented you can enter your futures profit/loss manually for other exchanges, or additional parsers can be added, out of interest which exchange did you use for your futures trading?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/BittyTax/BittyTax/issues/22#issuecomment-752091295, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQ3CO2RWYWJMBMWD3BG7V5DSXHQDXANCNFSM4QX3Y4CA.

cantcodeatall commented 3 years ago

I am reading the HMRC link. It says in the very beginning:

Specific legislation provides that certain disposals which would have been dealt with under the capital gains rules are instead to give rise to income profits or losses. This applies:

for Corporation Tax purposes only, where the futures fall within the legislation in Part 7 CTA09 (Derivative Contracts). (Or previously, within the legislation in FA02 (Derivative Contracts), or FA94 (Financial Instruments)). See CFM50000+. or in cases where schemes or arrangements involving the use of futures or/and options are designed to give a guaranteed return, see Chapter 12 Part 4 ITTOIA05 and CG56200. (Or previously ICTA88/Sch5AA, which applied also for Corporation Tax until such options and futures were brought within the FA02 rules for derivative contracts.)

Individuals trading in crypto futures fall in neither of the two cases mentioned, so tax treatment should be CGT, not income.

cantcodeatall commented 3 years ago

Also, the freshly released manual gives a bit (pun intended) more clarity: https://www.gov.uk/hmrc-internal-manuals/cryptoassets-manual/crypto20050

In the vast majority of cases, individuals hold cryptoassets as a personal investment, usually for capital appreciation or to make particular purchases. They will be liable to pay Capital Gains Tax when they dispose of their cryptoassets.

Individuals will be liable to pay Income Tax and National Insurance contributions on cryptoassets which they receive from:

their employer as a form of non-cash payment (see CRYPTO21100) mining, transaction confirmation or airdrops (see CRYPTO21150, CRYPTO21200 and CRYPTO21250) As set out in CRYPTO20250 there may be cases where the individual is running a business which is carrying on a financial trade in cryptoassets and they will therefore have taxable trading profits. This is likely to be unusual, but in such cases Income Tax rules would take priority over the Capital Gains Tax rules.

cantcodeatall commented 3 years ago

One more comment on this: @nanonano mentioned the list of recognised futures exchanges here: https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56120 While this list doesn't include any crypto exchange, it also doesn't include any retail CFD provider either. It only lists professional commodity and financial exchanges primarily aimed at institutions. CFDs on the other hand are mentioned earlier in the same manual and are closer to what crypto futures, primarily aimed at retail clients, are: https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56100

Retail contracts for differences are financial futures, and, unless the profits are taxable as trading income, in almost every case TCGA92/S143 charges the outcomes under the capital gains regime (CG56000+). SP03/02 gives guidance on when profits or losses are to be regarded as trading income.

All debits and credits to the account, including commission and sums equivalent to interest and dividends, are brought within the computation of the net chargeable gain or allowable loss when the contract is closed out.

njwedwards commented 3 years ago

From what I have read pooling does not apply to CFDs/Futures contracts. The following talking about CFDs (which are essentially the same) was helpful. https://community.ig.com/forums/topic/17087-cfd-and-capital-gains-calculations/

nanonano commented 9 months ago

Hi All, I've added a new branch which supports futures/margin trading. Currently for Binance, Kraken and Deribit, see https://github.com/BittyTax/BittyTax/tree/features/margin-trading, please give it a test.

blodgetAng commented 8 months ago

Hi nanonano, Thanks for your project. I have tried the parser for deribit and kraken futures. I guess all futures gains/losses are going under Capital Gains tax, is this accurate?

I believe the Deribit parser needs a "withdrawal", other than that small fix, it looks good

I could not work the futures trading for Kraken, with a Kraken futures ledger csv

nanonano commented 8 months ago

Hi @blodgetAng, thanks for testing!

Yes I would expect futures to be capital gains tax for most people.

I believe the Deribit parser needs a "withdrawal", other than that small fix, it looks good

Are you able to share a Deribit withdrawal, I didn't have an example to code from?

I could not work the futures trading for Kraken, with a Kraken futures ledger csv

I didn't add a parser for the Kraken futures trades export as hopefully everything is available from the Kraken ledgers export, so not required.

blodgetAng commented 8 months ago

@nanonano Here's a Deribit "withdrawal" example deribitWithdrawalExample

regarding Kraken. Unfortunately the spot ledger and futures ledger are separate and differ quite a bit, because anything else would be too easy !

nanonano commented 8 months ago

Hi @blodgetAng, thanks for the withdrawal example. It looks like the headers have changed from below?

[
    "ID",
    "UserSeq",
    "Date",
    "Instrument",
    "Type",
    "Side",
    "Size",
    "Position",
    "Price",
    "Mark Price",
    "Cash Flow",
    "Funding",
    "Fee Rate",
    "Fee Paid",
    "Fee Balance",
    "Change",
    "Balance",
    "Equity",
    "Trade ID",
    "Order ID",
    "Info",
],

Please can you provide the new headers by running the conv tool with debug.

Also, can you confirm the futures ledger export has the headers below?

['uid', 'dateTime', 'account', 'type', 'symbol', 'change', 'new balance', 'new average entry price', 'trade price', 'mark price', 'funding rate', 'realized pnl', 'fee', 'realized funding', 'collateral’]

If so I've got an example one, and I'll add a parser for it.

blodgetAng commented 8 months ago

@nanonano yes the Deribit headers are slightly different. deribitScreenshot from 2024-03-09 16-34-03

Kraken Futures Ledger export headers are: KrakenFuturesLedgerScreenshot from 2024-03-09 16-36-27

I can provide a sample one if you would like.

blodgetAng commented 8 months ago

@nanonano here's a kraken futures ledger export krakenfutures_sample.csv

nanonano commented 8 months ago

Hi @blodgetAng, thanks for the example kraken futures file, I'll take a look.

Re: Deribit withdrawal, are you able to confirm that the withdrawal fee is in the "Fee Paid" field in the old export, whereas now it's in the "Fee Charged" field?

blodgetAng commented 8 months ago

@nanonano yes deribit withdrawal fee is in "Fee Charged" thanks!

cantcodeatall commented 8 months ago

Hello, thanks for this. I tested it with Deribit, it parses the file with no errors, but I don't think it uses the correct methodology for calculating the gains. First of all it seems to use the pooling rules for spot trading, including B&B rules, but for futures/CFDs the B&B rules shouldn't apply (it should be one pool for the whole position including margin/financing costs). Secondly the gains should be calculated only when the position is closed, not at every daily settlement which is effectively mark to market of the position, as described in the link posted above.

nanonano commented 8 months ago

Hi @cantcodeatall, thanks for testing.

Margin trading/futures are handled completely separately from the spot trading rules (pooling, etc). The gain/loss is not calculated by BittyTax, instead there are 2 new transactions types Margin-Gain and Margin-Loss which are used to report these from the figures provided by the Deribit exported data file.

These Margin-Gain/Losses are totalled up along with any Margin-Fee's paid and appear in a new section in the tax report for that year.

If crypto is used to receive a margin gain or to pay a margin a loss or fee, then these will amounts are pooled, etc for capital gains as per normal.

nanonano commented 8 months ago

Hi @blodgetAng, I've added the Deribit "withdrawal" type, see https://github.com/BittyTax/BittyTax/commit/31db78c7a68bc12bc8a9fee54fd56f015b857135.

At the moment this is for the legacy export format, if you are able to test it works okay? Then I'll add the new export format you provided also.

cantcodeatall commented 8 months ago

@nanonano what constitutes receiving a margin gain or paying a margin loss though? As it's done at the moment, the daily settlements (mark to market) are included, which I believe shouldn't. Upon closing the position they should. This is not a crypto matter btw, it works exactly the same with futures in traditional markets where the settlement currency is USD, there's daily settlement with debiting or crediting USD, these are not acquisitions/disposals, only position closing is considered a disposal.

nanonano commented 8 months ago

@cantcodeatall, how do we identify when the position is closed from the Deribit export? Are you able to make changes to the parser, or describe the logic for how this should be calculated correctly?

cantcodeatall commented 8 months ago

The position size is shown at every line. If it goes to zero, the position is closed (or if it crosses zero, as you can go from long to short in one transaction, in which case the software can break it down to two transactions, one closing the position and one initiating another one in the opposite direction). Also, when a position is reduced, the "side" column is either "close buy" or "close sell".

blodgetAng commented 8 months ago

@nanonano here is an example deribit ledger so you can see what @cantcodeatall is describing so the margin gain/loss should exclude "settlement" in the header named "Type" transaction_log-deribitExample.csv

AnthonyFJGarner commented 5 months ago

Agree that P&L on futures trading (and perpetuals) should only be accounted for tax purposes on exit/reversal/unwinding. Day to day marked to market adjustments should be ignored. Only just coming to test this.

Equally, opening a futures position does not amount to a trade ab initio. No coin changes hands at this stage. The trade only takes place at the closing of the position. But doubtless the code has taken care of all this by now.

AnthonyFJGarner commented 5 months ago

OK, here is a question on the Kucoin parser.

# Futures Orders_Realized PNL (Bundle) DataParser( ParserType.EXCHANGE, "KuCoin Bundle Futures Orders Realized PNL", [ "UID", "Account Type", "Symbol", "Close Type", "Realized PNL", "Total Realized PNL", "Total Funding Fees", "Total Trading Fees", lambda c: re.match(r"(^Position Opening Time\((UTC[-+]\d{2}:\d{2})\))", c), lambda c: re.match(r"(^Position Closing Time\((UTC[-+]\d{2}:\d{2})\))", c), ], worksheet_name="Kucoin F", all_handler=parse_kucoin_futures,

Note the item "Total Funding Fees" Funding fees accrue in small amounts each day. While it is far more convenient to account for it all in one go at the end of the trade, will this suffice for the ghastly HMRC?

I sent you an email with a Deribit transaction log and I will post the details below so that others can see. You will note that Deribit gives each day's funding payment separately in the log.

cantcodeatall commented 5 months ago

Note the item "Total Funding Fees" Funding fees accrue in small amounts each day. While it is far more convenient to account for it all in one go at the end of the trade, will this suffice for the ghastly HMRC?

Yes, it will.

From the horse's mouth here:

[https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56100]

"All debits and credits to the account, including commission and sums equivalent to interest and dividends, are brought within the computation of the net chargeable gain or allowable loss when the contract is closed out."

AnthonyFJGarner commented 5 months ago

`<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

ID | UserSeq | Date | Instrument | Type | Side | Base Amount | Position | Price | Mark Price | Index Price | Cash Flow | Funding | Fee Rate | Fee Charged | Fee Balance | Change | Balance | Equity | Trade ID | Order ID | Info -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- 3.E+08 | 173451230 | ######## | ETH-PERPETUAL | settlement | short | -4810 | -4810 | 3507.11 | 3507.11 | 3506.94 | 0.007929 | 4.35E-05 | - | 0 | 0 | 0.007929 | 1.399186 | 1.399226 |   |   |  

` Above is one line of a Deribit trade log for futures - in this case the entry is for a perpetual swap not a dated future. The difference being that a perpetual entry entails a funding fee (positive or negative) while a traditional future does not.

Take a look at Column E "Type" and Column M "Funding".

Where Type == Settlement, include Funding in Bittytax_conv spreadsheets. It's that simple. Note that funding can be positive (income) or negative (a charge).

Funding is the interest payment mechanism by which Perpetual Swaps remain close to the relevant index. Which of course is not necessary for traditional futures with an expiry date.

Ignore Column L "Cashflow" which includes both the funding payment and the marked to market (unrealised P&L) payment in or out of the account.

Ignore BOTH Column M and Column L for dated futures with an expiry date.

As you can see trades are very clearly marked in Column E - Type. There will only be a taxable gain when the position is closed - "Close Buy", "Close Sell" but of course each close will need to be linked to the appropriate "Open Buy" or "Open Sell" to make the closing calculation of P&L.

Hope this helps. See email sent to hello@bitty.tax

### Important amendment: Note cantcodeatall's comments on Kucoin: it seems the daily funding fee can be rolled up and accounted for in the final P&L when the trade is closed.

AnthonyFJGarner commented 5 months ago

Note the item "Total Funding Fees" Funding fees accrue in small amounts each day. While it is far more convenient to account for it all in one go at the end of the trade, will this suffice for the ghastly HMRC?

Yes, it will.

From the horse's mouth here:

[https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg56100]

"All debits and credits to the account, including commission and sums equivalent to interest and dividends, are brought within the computation of the net chargeable gain or allowable loss when the contract is closed out."

Thank god for that! Scott please note this for Deribit - the daily Funding Fee will need to be aggregated and accounted for together with the final P&L when the position is closed. By the look of it.

nanonano commented 4 months ago

I've now merged the features/margin-trading branch into master, see https://github.com/BittyTax/BittyTax/commit/8d2e377b6edb1ba494ff50ecc292db6f7506a08c so will close down this issue.

There are still some related open issues, see https://github.com/BittyTax/BittyTax/issues/378, https://github.com/BittyTax/BittyTax/issues/374 and https://github.com/BittyTax/BittyTax/issues/371.