Adaptive price base#2299
Open
upsuper wants to merge 3 commits into
Open
Conversation
upsuper
commented
Jun 19, 2026
|
|
||
| def price_base(value: Decimal) -> Decimal: | ||
| """Return a scaled base amount for displaying a price.""" | ||
| exponent = max(0, round(-value.log10())) if value > ZERO else 0 |
Contributor
Author
There was a problem hiding this comment.
Using round here means that the result would be consistent if the number is floating around power of 10, e.g. we can have both 1 EUR = 1.18 USD and 1 EUR = 0.97 USD, rather than 10 EUR = 9.70 USD. The latter is what it would be if it's floor here. But in fact it just pushes the boundary towards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When there is a commodity conversion, in the price column it always shows the per unit price of the target commodity, e.g. if I sell 1 VOO for 695 USD, the price would show 695 USD. This is usually okay for shares where the counterpart commodity is the denominated currency, so the price is usually quite recognizable. However, it may not work well when both sides are fiat currencies and they have very different scale of value. As an example, when converting from USD to JPY or AUD to JPY, the price just shows as
0.01 USDor0.01 AUD, which is not very useful to know the actual exchange rate involved.This PR changes how price is displayed. It chooses an adaptive price base according to the difference between the pair of commodities. For example, in the case of USD to JPY and AUD to JPY, it would show something like
100 JPY = 0.66 USDand100 JPY = 0.91 AUD, which is much more useful than above.Disclosure: the implementation is mostly done by AI, but I reviewed the code and think it is a reasonable implementation.