Use adjusted basis which is fiat_in_with_fee divided by crypto_in for LOFO and HIFO#151
Conversation
… 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
|
@macanudo527 do you mind reviewing this? Claude is helping some others identify the same problem (see mentions in #150) |
macanudo527
left a comment
There was a problem hiding this comment.
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 b941067The commit adds 7 new subtests to test_with_fixed_lot_candidates in tests/test_accounting_method.py, covering:
- 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)
- 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
- Equal adjusted-basis tiebreaker — when two lots have identical cost per unit, the older one is used first
- 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?
|
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. |
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