Skip to content

Commit

Permalink
Reenable LIFO and FIFO (see discussion at #79)
Browse files Browse the repository at this point in the history
  • Loading branch information
eprbell committed Mar 18, 2024
1 parent c54c2e3 commit 1add78d
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ run: $(VENV)/bin/activate
$(VENV)/bin/rp2_us -o output/ -p test_data_ config/test_data.ini input/test_data.ods
$(VENV)/bin/rp2_us -o output/ -p test_many_year_data_ config/test_data.ini input/test_data.ods
$(VENV)/bin/rp2_us -o output/ -p crypto_example_ config/crypto_example.ini input/crypto_example.ods
# Temporarily removed lifo and hifo due to https://github.com/eprbell/rp2/issues/79
# $(VENV)/bin/rp2_us -m lifo -o output/ -p test_data_ config/test_data.ini input/test_data.ods
# $(VENV)/bin/rp2_us -m lifo -o output/ -p test_many_year_data_ config/test_data.ini input/test_data.ods
# $(VENV)/bin/rp2_us -m lifo -o output/ -p crypto_example_ config/crypto_example.ini input/crypto_example.ods

This comment has been minimized.

Copy link
@jayr0d

jayr0d Mar 18, 2024

Contributor

Should uncomment the -m lifo lines, not delete them?

This comment has been minimized.

Copy link
@eprbell

eprbell Mar 18, 2024

Author Owner

No need: it's just a make target that was almost never used. The execution of both lifo and hifo tests occurs via the tests (which have been updated).


check: $(VENV)/bin/activate
$(VENV)/bin/pytest --tb=native --verbose
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ Another unique advantage of RP2 is [transparent computation](https://github.com/
* verify step-by-step how RP2 reaches the final result;
* track down every lot fraction and its accounting details, in case of an audit.

RP2 currently supports the [FIFO](https://www.investopedia.com/terms/f/fifo.asp) accounting method for US and Spanish taxes and the Total Average Method for Japanese taxes.

This comment has been minimized.

Copy link
@jayr0d

jayr0d Mar 18, 2024

Contributor

Might want to restore LIFO and HIFO as examples in README.dev.md that was previously removed.

This comment has been minimized.

Copy link
@eprbell

eprbell Mar 18, 2024

Author Owner

Not sure which examples you're referring to: can you point to the history?

This comment has been minimized.

This comment has been minimized.

Copy link
@eprbell

eprbell Mar 22, 2024

Author Owner

Thanks for the pointer: done.

RP2 currently supports the following accounting methods:
* US: [FIFO](https://www.investopedia.com/terms/f/fifo.asp), [LIFO](https://www.investopedia.com/terms/f/lifo.asp) and [HIFO](https://www.investopedia.com/terms/f/hifo.asp). Note that these methods use universal application (not per-wallet application), as explained here: https://www.forbes.com/sites/shehanchandrasekera/2020/09/17/what-crypto-taxpayers-need-to-know-about-fifo-lifo-hifo-specific-id/;
* Spain: FIFO;
* Japan: Total Average Method.

RP2 reads a configuration file and an input spreadsheet containing crypto transactions. These [input files](https://github.com/eprbell/rp2/blob/main/docs/input_files.md) can be generated either manually or automatically using [DaLI](https://github.com/eprbell/dali-rp2), a RP2 data loader and input generator (which is also privacy-focused, free, non-commercial, open-source and community-driven). After parsing the input, RP2 uses high-precision math to calculate long/short term capital gains, cost bases, balances, average price, in/out lot relationships/fractions, and finally it generates [output files](https://github.com/eprbell/rp2/blob/main/docs/output_files.md).

Expand All @@ -76,9 +79,9 @@ RP2 has extensive [unit test](https://github.com/eprbell/rp2/tree/main/tests/) c
### How RP2 Operates
RP2 has been designed to have expressive primitives that can be used as building blocks for most tax scenarios: complex tax events can be described with patterns, built on top of these primitives (see the [FAQ list](https://github.com/eprbell/rp2/blob/main/docs/user_faq.md#tax-scenarios) for examples).

RP2 treats virtual currency as property for tax purposes, as per [IRS Virtual Currency Guidance](https://www.irs.gov/newsroom/irs-reminds-taxpayers-to-report-virtual-currency-transactions).
For the US case, RP2 treats virtual currency as property for tax purposes, as per [IRS Virtual Currency Guidance](https://www.irs.gov/newsroom/irs-reminds-taxpayers-to-report-virtual-currency-transactions).

RP2 supports the FIFO accounting method: however, in and out lots typically don't have matching amounts, so RP2 fractions them, maps in/out lot fractions and computes the resulting cost basis and capital gains for each lot fraction.
RP2 supports various accounting methods (e.g. FIFO, LIFO, HIFO): however, in and out lots typically don't have matching amounts, so RP2 fractions them, maps in/out lot fractions and computes the resulting cost basis and capital gains for each lot fraction.

RP2 groups lot fractions into the following taxable event categories, each of which has a [specific tax treatment](https://github.com/eprbell/rp2/blob/main/docs/user_faq.md#which-crypto-tax-forms-to-file):
* [AIRDROP](https://github.com/eprbell/rp2/blob/main/docs/user_faq.md#how-to-handle-airdrops): gains from airdrops;
Expand Down Expand Up @@ -170,11 +173,11 @@ The RP2 executable is country-dependent: `rp2_<country_code>`, where country cod
To generate US tax output for the example files open a terminal window (or PowerShell if on Windows) and enter the following commands:
```
cd <download_directory>
rp2_us -o output -p crypto_example_ crypto_example.ini crypto_example.ods
rp2_us -m fifo -o output -p crypto_example_ crypto_example.ini crypto_example.ods
```
Results are generated in the `output` directory and logs are stored in the `log` directory.

<!--- The `-m` option is particularly important, because is selects the accounting method: `rp2_us` supports FIFO, LIFO and HIFO (if `-m` is not specified it defaults to FIFO). --->
The `-m` option is particularly important, because is selects the accounting method: `rp2_us` supports FIFO, LIFO and HIFO (if `-m` is not specified it defaults to FIFO).

To print full command usage information for the `rp2_us` command:
```
Expand Down
14 changes: 11 additions & 3 deletions docs/user_faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@ In some cases exchange reports miss spot price information. In such situations y
The user adds the tokens to the `assets` field of the [config file](input_files.md#the-config-file): RP2 accepts as valid all the tokens present in this field. See also the question on [writing a config file from scratch](#can-i-avoid-writing-a-config-file-from-scratch).

### What Accounting Methods Are Supported?
Currently only the [FIFO](https://www.investopedia.com/terms/f/fifo.asp) accounting method is supported for US and Spanish taxes. Only the Total Average Method is supported for Japanese taxes.
RP2 currently supports the following accounting methods:
* US: [FIFO](https://www.investopedia.com/terms/f/fifo.asp), [LIFO](https://www.investopedia.com/terms/f/lifo.asp) and [HIFO](https://www.investopedia.com/terms/f/hifo.asp). Note that these methods use universal application (not per-wallet application), as explained here: https://www.forbes.com/sites/shehanchandrasekera/2020/09/17/what-crypto-taxpayers-need-to-know-about-fifo-lifo-hifo-specific-id/;
* Spain: FIFO;
* Japan: Total Average Method.

### Can I Change Accounting Method?
No, currently RP2 only supports FIFO for US and Spanish taxes and the Total Average Method for Japanese taxes.
Yes, for countries that support more than one accounting method, you can select which one to use via the `-m` command line option.

### What Countries Are Supported?
Currently the US, Japan and Spain are supported, but more countries are being added. As new countries are added this FAQ will be updated.
Currently the following countries are supported:
* US;
* Japan;
* Spain.

However more countries are being added. As new countries are added this FAQ will be updated.

### How to Switch from Another Tax Software to RP2?
In other words, how does RP2 handle transactions that were managed by other software in previous years? In this case the user can just leave out from the RP2 input spreadsheet the transactions/lots that were already sold in previous years.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = rp2
version = 1.5.0
description = Privacy-focused, free, non-commercial, open-source, community-driven cryptocurrency tax calculator: it handles multiple coins/exchanges and computes long/short-term capital gains, cost bases, in/out lot relationships/fractioning, and account balances. It supports the FIFO accounting method, it features transparent computation for easy result verification, and it generates reports that tax accountants can understand, even if they are not cryptocurrency experts (e.g. form 8949).
description = Privacy-focused, free, non-commercial, open-source, community-driven cryptocurrency tax calculator: it handles multiple coins/exchanges and computes long/short-term capital gains, cost bases, in/out lot relationships/fractioning, and account balances. It supports the FIFO, LIFO and HIFO accounting methods, it features transparent computation for easy result verification, and it generates reports that tax accountants can understand, even if they are not cryptocurrency experts (e.g. form 8949).

long_description_content_type = text/markdown
long_description = file: README.md, CHANGELOG.md
Expand Down
4 changes: 3 additions & 1 deletion src/rp2/plugin/accounting_method/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from rp2.rp2_decimal import ZERO, RP2Decimal


# FIFO plugin. See https://www.investopedia.com/terms/l/fifo.asp.
# FIFO plugin. See https://www.investopedia.com/terms/l/fifo.asp. This plugin uses universal application, not per-wallet application:
# this means there is one queue for each coin across every wallet and exchange and the accounting method is applied to each such queue.
# More on this at https://www.forbes.com/sites/shehanchandrasekera/2020/09/17/what-crypto-taxpayers-need-to-know-about-fifo-lifo-hifo-specific-id/
class AccountingMethod(AbstractAccountingMethod):
def seek_non_exhausted_acquired_lot(
self,
Expand Down
4 changes: 3 additions & 1 deletion src/rp2/plugin/accounting_method/hifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from rp2.rp2_decimal import ZERO, RP2Decimal


# HIFO plugin. See https://www.investopedia.com/terms/h/hifo.asp
# HIFO plugin. See https://www.investopedia.com/terms/h/hifo.asp. This plugin uses universal application, not per-wallet application:
# this means there is one queue for each coin across every wallet and exchange and the accounting method is applied to each such queue.
# More on this at https://www.forbes.com/sites/shehanchandrasekera/2020/09/17/what-crypto-taxpayers-need-to-know-about-fifo-lifo-hifo-specific-id/
class AccountingMethod(AbstractAccountingMethod):
def seek_non_exhausted_acquired_lot(
self,
Expand Down
6 changes: 4 additions & 2 deletions src/rp2/plugin/accounting_method/lifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
from rp2.rp2_decimal import ZERO, RP2Decimal


# LIFO plugin. See https://www.investopedia.com/terms/l/lifo.asp. Note that under LIFO the date acquired must still be before or on the date sold:
# see this discussion for details,
# LIFO plugin. See https://www.investopedia.com/terms/l/lifo.asp. This plugin uses universal application, not per-wallet application:
# this means there is one queue for each coin across every wallet and exchange and the accounting method is applied to each such queue.
# More on this at https://www.forbes.com/sites/shehanchandrasekera/2020/09/17/what-crypto-taxpayers-need-to-know-about-fifo-lifo-hifo-specific-id/
# Note that under LIFO the date acquired must still be before or on the date sold: for details see
# https://ttlc.intuit.com/community/investments-and-rental-properties/discussion/using-lifo-method-for-cryptocurrency-or-even-stock-cost-basis/00/1433542
class AccountingMethod(AbstractAccountingMethod):
def seek_non_exhausted_acquired_lot(
Expand Down
3 changes: 1 addition & 2 deletions src/rp2/plugin/country/us.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def get_default_accounting_method(self) -> str:

# Set of accounting methods accepted in the country
def get_accounting_methods(self) -> Set[str]:
# Temporarily removed lifo and hifo due to https://github.com/eprbell/rp2/issues/79
return {"fifo"}
return {"fifo", "lifo", "hifo"}

# Default set of generators to use if the user doesn't specify them on the command line
def get_report_generators(self) -> Set[str]:
Expand Down
2 changes: 1 addition & 1 deletion tests/abstract_test_ods_output_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OutputPlugins(Enum):

class AbstractTestODSOutputDiff(unittest.TestCase):
# Temporarily removed lifo and hifo due to https://github.com/eprbell/rp2/issues/79
METHODS: List[str] = ["fifo"]
METHODS: List[str] = ["fifo", "lifo", "hifo"]

def setUp(self) -> None:
self.maxDiff = None # pylint: disable=invalid-name
Expand Down

3 comments on commit 1add78d

@jayr0d
Copy link
Contributor

@jayr0d jayr0d commented on 1add78d Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does test_configuration.py also need updating?

@eprbell
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary: most of the accounting method functionality is covered by the test_ods_output_diff tests.

@eprbell
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there was a commented-out line referencing hifo and lifo in test_configuration.py: I uncommented it.

Please sign in to comment.