After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 733522 - gnucash --add-price-quotes fails to update currency price if exchange rate returned by Finance::Quote is in exponential form
gnucash --add-price-quotes fails to update currency price if exchange rate re...
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Currency and Commodity
2.6.3
Other Linux
: Normal normal
: ---
Assigned To: gnucash-core-maint
gnucash-core-maint
: 756889 758748 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-07-21 21:00 UTC by Eduard Valiauka
Modified: 2018-06-29 23:32 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Eduard Valiauka 2014-07-21 21:00:41 UTC
GnuCash fails to load exchange rate BYR to USD(Currently 1 EUR = 13900 BYR).
The inverse rate is 7.19424460431655e-05 and it seems like GnuCash is not able to handle exchange rates in exponential form.
I did solve my problem by replacing the following line in Quote.pm:
277:  return ($exchange_rate * $amount);
with 
277: return sprintf("%.8f",$exchange_rate * $amount);

Now it returns 0.00007194 and currency price is being updated correct, but I still believe that GnuCash should handle such situation properly, because 7.19424460431655e-05 is absolutely valid number presentation.
Comment 1 John Ralls 2014-07-21 21:51:19 UTC
Yes, it is, but GnuCash's parser isn't smart enough to read it. This will be addressed in the new numeric system for 2.8.
Comment 2 Frank H. Ellenberger 2015-02-27 16:48:27 UTC
Perhaps, if can be fixed easily in Quote.pm, you should submit your patch to https://rt.cpan.org/Public/Dist/Display.html?Status=Active&Name=Finance-Quote and we could close it here.

But I am not shure about information loss in case the format is to small.
@jralls: Could gnucash import it as rationale?
Comment 3 John Ralls 2015-02-27 17:54:53 UTC
Frank, sure, it should be able to. gnc-fq-helper (which is perl, BTW) returns:
$ aeolus:r-git/build/gnucash-git> gnc-fq-helper
(currency "BYR" "USD")
(("BYR" (symbol . "BYR") (last . 6.757e-05) (currency . "USD")))

The number is passed to double-to-gnc-numeric in src/scm/price-quotes.scm, which should be a scheme wrapper for double_to_gnc_numeric. It ought to return 6757/100000000.

This is clearly a GnuCash problem, it shouldn't be sent upstream; if it turns out to be a Guile shortcoming we can fix it in gnc-fq-helper.
Comment 4 John Ralls 2015-03-14 08:21:03 UTC
I just tested a USD->BYR transaction including retrieving the exchange rate with F::Q, and the resulting rate was 225/3397252, which Python reports as 6.623000001177423e-05; the input to double_to_gnc_numeric() from Scheme was 0.000066229999999999994, with 9 significant figures. The actual string from F::Q was 6.623e-05. That turned $67.50 into BYR 1,019,175.60, which appears to me to be correct.


I see no problem here. OP, what exactly did you do and what went wrong?
Comment 5 Eduard Valiauka 2015-03-15 15:37:01 UTC
I update gnucash's price database with "gnucash --add-price-quotes" command every day.

In fact, I have a script that switches default currency from BYR to USD then does "gnucash --add-price-quotes" to load exchange rate. Then it switches default currency back to BYR  and does "gnucash --add-price-quotes" again to load reverse exchange rate. Doing this way I have both BYR-to-USD and USD-to-BYR exchange rates. To see the loaded rates I use Tools -> Price Editor.


I tried to reproduce this issue.
I reverted the aforementioned line in Quote.pm to its original value and ran my script. Only USD-to-BYR was loaded (its value is 15100 today). And that's the issue. Then I changed that line in Quote.pm to 

return sprintf("%.8f",$exchange_rate * $amount);

again and ran the script once more. It loaded both exchange rates including BYR-to-USD (its value is 0.00006623 today).
Comment 6 John Ralls 2015-03-16 08:46:18 UTC
OK. I can reproduce this with the 2.6.5 release, but not with the current maint branch, though I don't understand why. If you're able to build from source, please try that. If not, 2.6.6 will be out in a couple of weeks.
Comment 7 Eduard Valiauka 2015-03-16 10:07:19 UTC
You are right. I see no issue with the latest maint code neither.
Comment 8 John Ralls 2015-03-16 11:55:52 UTC
OK. I'll mark it fixed pending the release. Once you get the 2.6.6 release installed check it again and reopen this bug if it doesn't work.
Comment 9 Eduard Valiauka 2015-03-16 19:11:54 UTC
Ok. Thank you for your time.
Comment 10 Eduard Valiauka 2015-10-15 20:02:33 UTC
After update to 2.6.8 the issue is reproducible again. Same behaviour with 2.6.9.

The difference from 2.6.5 is that the fix in Quote.pm does not help.
Comment 11 John Ralls 2015-10-15 20:16:21 UTC
Are you sure? Since 2.6.8 GnuCash tries to save exchange rates in the direction that the value is > 1, precisely to avoid the problem of dealing with very small fractions. Your quotes should be in CURRENCY>USD>BYR.
Comment 12 Eduard Valiauka 2015-10-16 10:10:57 UTC
Thanks.

I see. In fact the exchange rate USD-EUR also stopped loading although it is not so small.

So, now gnucash never uses BYR-USD exchange rate for reports in USD or BYR, but instead always uses USD-BYR. Am I right?
Comment 13 John Ralls 2015-10-16 14:32:14 UTC
Not exactly. GC will only retrieve USD-BYR. EUR-USD might flip to USD-EUR if the Euro depreciates a bit more against the Dollar. It's set up so that it will preserve the direction on any particular day to maintain the one-quote rule and on the premise that a single-day move won't produce a small enough fraction to cause trouble. BYR->USD on the other hand is always small enough to cause trouble because of the 1000000 maximum denominator.

Wm mentioned on the user list that I might have missed something in reports retrieving prices from the pricedb, though. I'll look into that today and make sure that reports get the right price according to the policy option regardless of the direction in the pricedb.
Comment 14 Eduard Valiauka 2015-10-16 18:43:53 UTC
I just checked the asset piechart with "Most Recent" price source.
Some of my accounts are in BYR, some in USD. Till 29.09.2015 there are both exchange rates BYR-TO-USD and USD-TO-BYR.  Starting from 30.09.2015 there is only USD-TO-BYR.

If the reports currency is BYR, the most recent USD-TO-BYR exchange rate(today's value, fine) is used. If the reports currency is USD - the most recent BYR-TO-USD exchange rate is used - a value from 29.09.2015 (bad).
Comment 15 John Ralls 2015-10-29 22:18:44 UTC
*** Bug 756889 has been marked as a duplicate of this bug. ***
Comment 16 John Ralls 2015-10-29 22:24:33 UTC
This is fixed in opposite directions in maint and master. In maint (so for the next stable release in December) the automatic inversion of prices has been reverted so that that part will return to the pre-2.6.8 behavior. The price db will still store only one price per day and will still prefer Finance::Quote prices over those originating from handling transactions.

In master, for the next major release at the end of 2017, the automatic price inversion is retained and all lookups are made to check both directions for the latest price.
Comment 17 John Ralls 2015-11-27 18:22:41 UTC
*** Bug 758748 has been marked as a duplicate of this bug. ***
Comment 18 John Ralls 2018-06-29 23:32:17 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=733522. Please update any external references or bookmarks.