-
Notifications
You must be signed in to change notification settings - Fork 21
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
Preserve costs during tax adjustment #83
Preserve costs during tax adjustment #83
Conversation
Previously, tax adjustment discarded the cost of positions, causing beancount.core.convert.convert_position to miss some conversion paths via the cost currency. This necessitated a fallback to operating currencies for finding viable transitive conversions. With this patch, tax adjustment preserves the cost of positions. Therefore, the cost currency is still available for automatic detection of transitive conversions when computing the asset allocation. One important assumption is that tax adjustment only ever encounters costs after realization, as having a cost spec for the total cost would change the cost per unit. This assumption is checked via assert and has been manually tested without error on the multicurrency example. The patch leaves the fallback logic for conversion via operating currencies in place as an alternative when conversion via cost currency fails.
Unfortunately, I was unable to get the test suite running on my system, so I was unable to test automatically. I compared the output on both the huge and multicurrency examples, which was unchanged before and after the change. If desired, I can also amend this patch or add another patch to show both options, conversion via cost currency and operating currency, in the multicurrency example. |
Nice patch, and looks good to me! I tested it with a couple of rudimentary cases, and and it works fine. Couple things:
BTW, I simply run Thanks again! |
Yes, we could remove the line you linked. However, it could still be a useful fallback behaviour for some edge cases. For example, consider a case where neither a direct conversion between the position and the base currency nor between the cost currency and the base currency exist, but an indirect path via another operating currency exists. For instance, this small modification of the multicurrency example, highlights the behaviour:
I'm not sure how useful it would be in practice, but leaving the fallback in place would ensure backwards compatibility. That said, I can add a patch removing the fallback if you'd prefer. |
When I run |
I can squash the commits before you merge if you prefer. Just let me know. |
Makes sense, thanks for the explanation and the case where the fallback is needed. Nice find and patch, great documentation, thanks again, merged! |
Previously, tax adjustment discarded the cost of positions, causing
beancount.core.convert.convert_position
to miss some conversion paths via the cost currency. This necessitated a fallback to operating currencies for finding viable transitive conversions.With this patch, tax adjustment preserves the cost of positions. Therefore, the cost currency is still available for automatic detection of transitive conversions when computing the asset allocation.
One important assumption is that tax adjustment only ever encounters costs after realization, as having a cost spec for the total cost would change the cost per unit. This assumption is checked via assert and has been manually tested without error on the multicurrency example.
The patch leaves the fallback logic for conversion via operating currencies in place as an alternative when conversion via cost currency fails.
Fixes #82