Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schwab_equity_award_json.py parser: avoid unnecessary quantity recalculation. #575

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

m01
Copy link
Contributor

@m01 m01 commented Dec 14, 2024

This can introduce rounding errors.

This fixes #574.

Basically, there's some code in cgt_calc/parsers/schwab_equity_award_json.py, which tries to work around some issues in data exported from Schwab:

            # Schwab's data export sometimes lacks decimals on Sales
            # quantities, in which case we infer it from number of shares in
            # sub-transactions, or failing that from the amount and salePrice.

This codepath is triggered unconditionally when an integer number of shares is sold - even when there isn't an issue with the exported data. This change makes that codepath conditional on there actually being an issue with the exported data.

Without the change in cgt_calc/parsers/schwab_equity_award_json.py, the test triggers the following error:

FAILED tests/test_schwab_equity_award_json.py::test_schwab_transaction_v2_rounding - AssertionError: assert Decimal('91.00001463507441935342241215') == Decimal('91')

The test data is fictional and purely there to reproduce the error, but it is plausible based on data I've seen and I have seen the rounding errors happen in real data.

Note that because quantities matter for S104 pool calculations this may introduce deltas in outputs between
calculations before and after this change. However, without this change you may run into asserts, depending
on what kinds of trades/gifts you make.

This contribution has been developed in my spare time. Disclaimer: I'm not a financial advisor/accountant.

…ulation.

This can introduce rounding errors.

This fixes KapJI#574.

This contribution has been developed in my spare time.
@KapJI
Copy link
Owner

KapJI commented Dec 16, 2024

Looks good to me, thanks for adding tests!

@KapJI KapJI merged commit 5ad2d52 into KapJI:main Dec 16, 2024
3 checks passed
@m01 m01 deleted the issue-574 branch December 16, 2024 18:49
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.

schwab_equity_award_json parser can introduce rounding errors in share quantity
2 participants