eprbell / rp2

Privacy-focused, free, open-source cryptocurrency tax calculator for multiple countries: it handles multiple coins/exchanges and computes long/short-term capital gains, cost bases, in/out lot relationships/fractioning, and account balances. It supports FIFO, LIFO, HIFO and it outputs in form 8949 format. It has a programmable plugin architecture
https://pypi.org/project/rp2/
Apache License 2.0
286 stars 45 forks source link

Add Support for Canada #52

Open eprbell opened 2 years ago

eprbell commented 2 years ago

RP2 and DaLI have a programmable plugin architecture for countries, accounting methods, report generators and more. Adding support for a new country is a high-impact activity because it allows many new potential users to get access to RP2 and DaLI.

Here's how to add support for a new country:

  1. add a new country plugin to RP2;
  2. if the country requires accounting methods that aren't already supported in RP2, add the necessary accounting method plugins;
  3. ensure any newly added accounting methods are reflected in the country plugin's get_default_accounting_method() and get_accounting_methods() methods;
  4. optionally, new country-specific report generators can be added. The built-in report generators (i.e. rp2_full_report and open_positions) are automatically supported;
  5. only for non-English speaking countries: translations for the built-in report generators and for any new report generator can be added;
  6. ensure any newly added report generators are reflected in the country plugin's get_report_generators() method;
  7. add the same country plugin to DaLI. The implementation on the DaLI side is trivial: it's just an entry point instantiating the RP2 country plugin and passing it to the main function;
  8. update the documentation of RP2 and DaLI to reflect the new country, accounting methods (if any) and report generators (if any).

If you notice the country-specific infrastructure is missing a feature that is required to express taxes for the new country, open an issue to let the RP2 community know.

brazenCoding commented 1 year ago

I don't know the first thing about coding in python, but I've shared this on a few canadian crypto reddits in the hopes of finding someone who does. It seems like you've built an incredible tool here and I hope to be able to use it. It stinks that the services that exist charge so much just for number of transactions. I have 1k+ but its all small potatoes transactions. I much prefer having a free, privacy focused solution!

eprbell commented 1 year ago

Thanks for the kind words! I'd love to see a Canadian plugin get added to RP2. Thanks also for spreading the word on social networks: you may want to post on https://www.reddit.com/r/CryptoTax/ as well. Finally, if you want to help the projects consider adding a Github star to RP2 and DaLI.

brazenCoding commented 1 year ago

Thanks for the kind words! I'd love to see Canadian plugin get added to RP2. Thanks also for spreading the word on Reddit: you may want to add post on https://www.reddit.com/r/CryptoTax/ as well. Finally, if you want to help the projects consider adding a Github star to RP2 and DaLI.

Done and Done and Done! GL! (Make sure to upvote the reddit post to get the traction started :P)

macanudo527 commented 1 year ago

@brazenCoding something else you can do is the preliminary research on how crypto taxes are done in Canada. Maybe you can explain some of the details of how different transactions are considered and if any reports will need updated or changed. For example, will the US report basically work with some modifications? Does Canada consider crypto an asset or security? What is the main form you need to file? etc...

That would speed up the process and make it easier for someone to just jump in and code it. You might even get someone who isn't living in Canada to help you out if you do all the foot work.

brazenCoding commented 1 year ago

good idea @macanudo527 The government has not created new documentation separate from existing reporting structures. They have outlined how each kind of crypto transaction is taxed:

The details are HERE, but in summary:

Any transaction that results in realizing a change in value of a cryptocurrency is considered a capital gain/loss, calculated using the difference between the ACB of the coin sold and its market value at the time of the transaction, then multiplied by 50% to determine the taxable amount. Examples include:

Any transaction that results in receiving new coin, except purchased with fiat currency, is considered income and must be reported for 100% of the amount received. Examples include:

Some transactions are tax exempt for income purposes. Examples:

Koinly also has good public articles on both these tax rules and how to calculate ACB and average cost basis

juil commented 1 year ago

Gitcoin might be a good place to post a bounty.

ydkdy commented 1 year ago

I have thoughts on Canadian taxation which I will contrast against USA taxes.

It's ACB, rather than per lot or FIFO or LIFO or anything like that.

Canadian taxes do not have the concept of short term vs. long term gains. The closest thing they have to this is a "judgement" of how active the tax payer is in the process of acquiring the gains. My understanding is if a person was a day trader, then the gains are considered taxable income and is reported differently than capital gain income. I don't think this affects RP2 though. I'm not 100% sure, but I imagine that RP2 could generate a single set of reports to cover both cases, and then it's up to the taxpayer to report it accordingly.

The Canadian equivalent of a 1040 is a T1. The Canadian equivalent of a Form 8949 is T1 Schedule 3 or also called 5000-S3. The format of the Schedule 3 is slightly different than Form 8949. Form 8949 has the following columns:

Description Date Acquired Date Sold Proceeds Cost or other basis adjustments (two fields) Gain or Loss

The Schedule 3 has two main differences, it's ACB based which changes the concept of Acquired and Sold. And they want the disposition expenses broken out rather than being rolled up into the Proceeds. The columns are:

Year of Acquisition Proceeds Adjusted Cost Base Outlays and Expenses (from dispositions) Gain or loss

link to Schedule 3 https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/5000-s3/5000-s3-22e.pdf

The design of the Canadian Schedule 3 is to allow one entry for each kind of capital gain, and then if you need more room one is instructed to attach a separate sheet. For this reason, I think the Form 8949 "look & feel" would be sufficient as the "attached separate sheet", but with the Schedule 3 columns on it. Lets call that new document "RP2 Schedule 3 attachment" for now.

I'm thinking the "RP2 Schedule 3 attachment" calculates the numbers much like the 8949 and summarizes them without accounting for the 50% capital gains tax rate. Then the tax payer can copy those numbers to their T1 Schedule 3, and then the Schedule 3 takes into account the 50% capital gains tax rate, and RP2 doesn't have to.

Also, if the taxpayer really should be paying the income tax rate rather than the capital gain tax rate, I imagine the "RP2 Schedule 3 attachment" would have sufficient information for this case as well.

Honestly, I haven't looked at the RP2 reports in a while. So I don't know how close it is. But I'm thinking Canadian tax support amounts to (at least):

1) use ACB 2) different columns on the gain/loss detail

eprbell commented 1 year ago

Solid thread, everyone!

btraas commented 1 year ago

Quick note - you can record mining revenues as a hobby or a business.

Mining as a Hobby: Can't deduct costs, taxed as capital gains (50% of revenue added to your annual income) with an ACB of zero.

Mining as a Business: Can deduct electricity costs, hardware depreciation etc, taxed like a regular Canadian business

Staking: No official word from the CRA but services like Coinly reccomend filing as if it's mining

macanudo527 commented 1 year ago

Japan uses ACB and already has reports per asset, and a yearly summary. Japan doesn't have rules against wash sales though, so that logic would need to be added in.

We have talked about allowing users to disable the accounting engine, which handles lots for FIFO, HIFO etc... We might want to implement some kind of ACB accounting method, but the engine isn't really setup for that at the moment. What are your thoughts @eprbell ?

eprbell commented 1 year ago

I don't think we need a new accounting method plugin for ACB: AFAICT ACB is fairly easy to implement on top of the RP2 FIFO plugin. The main thing that is missing is computation of the average, but that can be done directly in the plugin with a few lines of Python (in fact, @macanudo527, can you point to the where you do that in the Japan plugin?). I suggest to implement the Canadian plugin and then we can look at both Japan and Canada and see if we can factor some common functionality into RP2 core (average calculation and maybe something else).

macanudo527 commented 1 year ago

@eprbell sorry, I guess for the JP plugin most of the calculation is handled in the spreadsheet, which is a mock-up of what the NTA (Japanese tax agency) provides. The python code just inputs the values and the formulas for ACB are provided by the NTA.

I can't really ascertain what you are supposed to do for wash sales in Canada. As I understand it, to claim a loss you have to not repurchase the asset for 30 days? is that how it works?

brazenCoding commented 1 year ago

@eprbell sorry, I guess for the JP plugin most of the calculation is handled in the spreadsheet, which is a mock-up of what the NTA (Japanese tax agency) provides. The python code just inputs the values and the formulas for ACB are provided by the NTA.

I can't really ascertain what you are supposed to do for wash sales in Canada. As I understand it, to claim a loss you have to not repurchase the asset for 30 days? is that how it works?

That's right. For example, say you bought stock XYZ inc. for $20/share and sold it at a loss near the end of a tax year for $15/share and then bought the same stock two days later for $15/share because you're certain the stock is going to $25/share in a few months. The sale would not count as a capital loss, nor affect an ACB calculation if you still held some of the stock at the time of the re-purchase. (Declaring the loss and lowering your ACB by buying back at the lower price wouldn't be allowed) At least that's how I understand the government's explanation on the website.

These rules apply to crypto as well, and is especially important given that crypto fluctuates so much.

macanudo527 commented 1 year ago

Okay, so this is what ChatGPT has to say about it. Do these sound correct to you?

Can you give me a clear example of the superficial loss rule in Canada's crypto taxes?

Yes, I can provide you with a clear example of the superficial loss rule in Canada's crypto taxes.

Let's say you bought 1 Bitcoin on January 1st for $50,000, and then the price of Bitcoin drops to $40,000 on January 15th. You decide to sell your Bitcoin at a loss of $10,000.

Now, let's say you buy another Bitcoin on January 20th for $42,000, and then sell it for $45,000 on February 1st, making a profit of $3,000.

Even though you made a profit on the second Bitcoin, the superficial loss rule applies because you bought a similar asset (Bitcoin) within 30 days of selling the first Bitcoin at a loss. As a result, you are not able to claim the $10,000 loss on your taxes for the first Bitcoin sale.

Instead, the $10,000 loss is added to the adjusted cost base (ACB) of the second Bitcoin purchase, which means that your new ACB for the second Bitcoin is $52,000 ($42,000 + $10,000). This will impact your future capital gains or losses when you sell the second Bitcoin.

It's important to note that the superficial loss rule only applies when you repurchase a similar asset within 30 days of selling at a loss. If you wait longer than 30 days to repurchase the asset, you can claim the loss on your taxes as usual.

In Canada, if I buy 1 BTC for $50,000 on January 1st, then sell 0.5 BTC for $40,000 on January 15th, and then buy 0.5 BTC on February 10th for $40,000, can I claim $5000 as a loss?

No, in this scenario, you cannot claim a loss of $5,000 on your taxes because of the superficial loss rule in Canada.

When you sold 0.5 BTC on January 15th for $40,000, you realized a loss of $5,000 (the half of the cost of the Bitcoin you originally purchased for $50,000). Since you repurchased a similar asset (Bitcoin) within 30 days of selling at a loss, the superficial loss rule would apply if you were to sell any additional Bitcoin at a loss within 30 days.

However, in this scenario, you repurchased 0.5 BTC on February 10th, which is before the 30-day window from the sale on January 15th. As a result, you can claim the $5,000 loss on your taxes as a capital loss.

When you repurchased 0.5 BTC on February 10th for $40,000, the adjusted cost base for this repurchased 0.5 BTC would be $45,000 ($50,000 - $5,000) due to the inclusion of the loss you claimed. If you were to sell this repurchased 0.5 BTC in the future, the capital gain or loss would be based on this adjusted cost base.

So in this scenario, you can claim a $5,000 loss on the sale of the first 0.5 BTC as a capital loss on your taxes, which can be used to offset any capital gains you may have realized during the year or carried forward to future years. However, the adjusted cost base for the repurchased 0.5 BTC would be $45,000.

In Canada, if I buy 1 BTC for $50,000 on January 1st, then sell 0.5 BTC for $40,000 on January 15th and then sell 0.5 BTC on March 20th for $40,000, can I claim $10000 as a loss?

Yes, in this scenario, you would be able to claim a loss of $10,000 on your taxes because you waited more than 30 days before selling the second 0.5 BTC.

When you sold 0.5 BTC on January 15th for $40,000, you realized a loss of $5,000 (the half of the cost of the Bitcoin you originally purchased for $50,000). However, since you waited more than 30 days before selling the remaining 0.5 BTC on March 20th for $40,000, the superficial loss rule would not apply. Therefore, you can claim the $5,000 loss on the sale of the first 0.5 BTC as a capital loss on your taxes.

When you sold the remaining 0.5 BTC on March 20th for $40,000, you did so more than 30 days after realizing a loss on the sale of the first 0.5 BTC. As a result, you can claim any gain or loss on the sale of the second 0.5 BTC as a separate transaction. Since you sold the second 0.5 BTC for the same price you bought it ($40,000), there is no gain or loss to report on this transaction.

So in this scenario, you would be able to claim a $5,000 loss on the sale of the first 0.5 BTC as a capital loss on your taxes, which can be used to offset any capital gains you may have realized during the year or carried forward to future years.

ydkdy commented 1 year ago

The ChatGPT summary looks good to me.

While I was verifying some of that, I came across this:

In certain situations, when you dispose of capital property, the loss may not be considered a superficial loss. Some of the more common situations include the following:

You are considered to have sold the capital property because you became or ceased to be a resident of Canada You are considered to have sold the property because you changed its use You disposed of the property and within 30 calendar days after the disposition, you became or ceased to be exempt from income tax The property is considered to have been sold because the owner died The disposition results from the expiry of an option The property is appropriated by a shareholder on the winding-up of a corporation Non-depreciable capital property is disposed of by a corporation, partnership, or trust. In this situation, although the loss is not added to the adjusted cost base of the transferred property, it is not claimed immediately but its recognition is deferred pending the occurrence of certain events. For more information, call 1-800-959-8281

from: https://www.canada.ca/en/revenue-agency/services/forms-publications/publications/t4037/capital-gains.html#P3498_137482

It raises the question whether one should be able to remove any superficial loss determinations on specific transactions. For example, if someone has a superficial loss on July 15, and then move from Canada to the USA on July 30, then that transaction is not considered a superficial loss.

Also found this link which I'm attaching for reference:

https://www.canada.ca/en/revenue-agency/programs/about-canada-revenue-agency-cra/compliance/digital-currency/cryptocurrency-guide.html

adampurkis commented 10 months ago

Unfortunately not much of a programmer, but if there is anything I can do to get interest in expanding this to Canada let me know!

brazenCoding commented 10 months ago

Okay, so this is what ChatGPT has to say about it. Do these sound correct to you?

Can you give me a clear example of the superficial loss rule in Canada's crypto taxes?

Yes, I can provide you with a clear example of the superficial loss rule in Canada's crypto taxes.

Let's say you bought 1 Bitcoin on January 1st for $50,000, and then the price of Bitcoin drops to $40,000 on January 15th. You decide to sell your Bitcoin at a loss of $10,000.

Now, let's say you buy another Bitcoin on January 20th for $42,000, and then sell it for $45,000 on February 1st, making a profit of $3,000.

Even though you made a profit on the second Bitcoin, the superficial loss rule applies because you bought a similar asset (Bitcoin) within 30 days of selling the first Bitcoin at a loss. As a result, you are not able to claim the $10,000 loss on your taxes for the first Bitcoin sale.

Instead, the $10,000 loss is added to the adjusted cost base (ACB) of the second Bitcoin purchase, which means that your new ACB for the second Bitcoin is $52,000 ($42,000 + $10,000). This will impact your future capital gains or losses when you sell the second Bitcoin.

It's important to note that the superficial loss rule only applies when you repurchase a similar asset within 30 days of selling at a loss. If you wait longer than 30 days to repurchase the asset, you can claim the loss on your taxes as usual.

In Canada, if I buy 1 BTC for $50,000 on January 1st, then sell 0.5 BTC for $40,000 on January 15th, and then buy 0.5 BTC on February 10th for $40,000, can I claim $5000 as a loss?

No, in this scenario, you cannot claim a loss of $5,000 on your taxes because of the superficial loss rule in Canada.

When you sold 0.5 BTC on January 15th for $40,000, you realized a loss of $5,000 (the half of the cost of the Bitcoin you originally purchased for $50,000). Since you repurchased a similar asset (Bitcoin) within 30 days of selling at a loss, the superficial loss rule would apply if you were to sell any additional Bitcoin at a loss within 30 days.

However, in this scenario, you repurchased 0.5 BTC on February 10th, which is before the 30-day window from the sale on January 15th. As a result, you can claim the $5,000 loss on your taxes as a capital loss.

When you repurchased 0.5 BTC on February 10th for $40,000, the adjusted cost base for this repurchased 0.5 BTC would be $45,000 ($50,000 - $5,000) due to the inclusion of the loss you claimed. If you were to sell this repurchased 0.5 BTC in the future, the capital gain or loss would be based on this adjusted cost base.

So in this scenario, you can claim a $5,000 loss on the sale of the first 0.5 BTC as a capital loss on your taxes, which can be used to offset any capital gains you may have realized during the year or carried forward to future years. However, the adjusted cost base for the repurchased 0.5 BTC would be $45,000.

In Canada, if I buy 1 BTC for $50,000 on January 1st, then sell 0.5 BTC for $40,000 on January 15th and then sell 0.5 BTC on March 20th for $40,000, can I claim $10000 as a loss?

Yes, in this scenario, you would be able to claim a loss of $10,000 on your taxes because you waited more than 30 days before selling the second 0.5 BTC.

When you sold 0.5 BTC on January 15th for $40,000, you realized a loss of $5,000 (the half of the cost of the Bitcoin you originally purchased for $50,000). However, since you waited more than 30 days before selling the remaining 0.5 BTC on March 20th for $40,000, the superficial loss rule would not apply. Therefore, you can claim the $5,000 loss on the sale of the first 0.5 BTC as a capital loss on your taxes.

When you sold the remaining 0.5 BTC on March 20th for $40,000, you did so more than 30 days after realizing a loss on the sale of the first 0.5 BTC. As a result, you can claim any gain or loss on the sale of the second 0.5 BTC as a separate transaction. Since you sold the second 0.5 BTC for the same price you bought it ($40,000), there is no gain or loss to report on this transaction.

So in this scenario, you would be able to claim a $5,000 loss on the sale of the first 0.5 BTC as a capital loss on your taxes, which can be used to offset any capital gains you may have realized during the year or carried forward to future years.

Upon re-reading, this chatgpt comment made a lot of errors of consistency here. For example, in the third scenario it seems to have forgotten that you sold 0.5 BTC both times, instead talking as of you'd bought once at 40k. Also it seems to forget that it said earlier you can claim a 10k loss but later it says 5k.

It captures the gist, but fumbles the real numbers.

In brief, Scenario 1, buy 1 BTC at 50k on Jan 1, sell 0.5 at 45k on Jan 15, and buy 0.5 at 40k on Jan 30. No loss claimable, new ACB is 45k.

Scenario 2, buy 1 BTC at 50k on Jan 1, sell 0.5 at 45k on Jan 15, and buy 0.5 at 40k on Feb 28. 2.5k loss claimable, new ACB is 45k.

Scenario 3, buy 1 BTC at 50k on Jan 1, sell 0.5 at 45k on Jan 15, and buy 0.5 at 42k on Feb 28. 2.5k loss claimable, new ACB is 46k.

Scenario 4, buy 1 BTC at 50k on Jan 1, sell 0.5 at 40k on Jan 15, and sell 0.5 at 40k on Jan 28. 10k loss claimable.