Skip to content

Use adjusted basis which is fiat_in_with_fee divided by crypto_in for LOFO and HIFO#151

Open
jayr0d wants to merge 1 commit into
eprbell:mainfrom
jayr0d:bugfix/150-HIFO-LOFO-fiat_in_with_fee-lot-selection
Open

Use adjusted basis which is fiat_in_with_fee divided by crypto_in for LOFO and HIFO#151
jayr0d wants to merge 1 commit into
eprbell:mainfrom
jayr0d:bugfix/150-HIFO-LOFO-fiat_in_with_fee-lot-selection

Conversation

@jayr0d

@jayr0d jayr0d commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Update golden files for lofo (lowest in, first out) and hifo (highest in, first out) accounting methods to use adjusted basis which is fiat_in_with_fee divided by crypto_in. Reformat code via black src tests

See #150

… in, first out) accounting methods to use adjusted basis which is fiat_in_with_fee divided by crypto_in. Reformat code via black src tests
@jayr0d

jayr0d commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@macanudo527 do you mind reviewing this? Claude is helping some others identify the same problem (see mentions in #150)

@macanudo527 macanudo527 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great fix — I reviewed the IRS authority chain and the implementation looks correct. I also wrote unit tests covering several fringe cases for this change that you may want to include. They're on a public branch and can be cherry-picked cleanly (no source changes, no golden files):

git remote add macanudo527 https://github.com/macanudo527/rp2.git
git fetch macanudo527 fix/hifo-lofo-adjusted-basis
git cherry-pick b941067

The commit adds 7 new subtests to test_with_fixed_lot_candidates in tests/test_accounting_method.py, covering:

  1. Fee flips HIFO/LOFO ranking — a lot with a lower spot price but a large fee has a higher adjusted basis, so HIFO sells it first (the core case from issue #150)
  2. Mined lot mixed with a fee-bearing purchase — verifies earn-type transactions (no fee, basis = fair market value at receipt) rank correctly alongside purchased lots with fees
  3. Equal adjusted-basis tiebreaker — when two lots have identical cost per unit, the older one is used first
  4. Partial lot consumption — confirms adjusted-basis ranking is preserved correctly when a lot is split across two taxable events

Each test includes a comment with the governing IRS FAQ question and a direct link to the source. I tried to write them in plain language without jargon — could you take a quick look and let me know if the wording in the test comments makes sense to you, or if anything should be phrased differently?

@jayr0d

jayr0d commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @macanudo527. Looks good to me. I needed a tutorial on writing unit tests specific to rp2 and this is very informative.

I will get this merged in and update the pull request when I have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants