GNOME Bugzilla – Bug 454827
Reports: Incorrect share value of stocks in foreign currency
Last modified: 2018-06-29 21:42:04 UTC
Please describe the problem: I have one stock with USD value. When I create a Investment Portfolio report and use USD as report currency, the value is calculated correctly. However, when I change the report currency to EUR, the value is incorrect. Steps to reproduce: 1. Buy 31.00 stocks with some starting price 2. Open the Price Editor, set the last price of the stock to 40.66 USD 3. In the Price Editor, set the last price of USD currency to 0.728600 EUR 4. Open the Investment Portfolio report Actual results: Investment portfolio displays 918.51 EUR as the value of stocks. Expected results: Investment portfolio displays 918.37 EUR as the value of stocks (31 * 40.66 * 0.7286 = 918.371156 ≈ 918.37) Does this happen every time? Yes Other information: I'm using GnuCash 2.0.5 installed via MacPorts 1.442 on Mac OS X 10.4.10 on Intel Mac. Example datafile which shows this bug can be downloaded from http://zhuk.fi/gnucash/GnuCash-Datafile.gnucash
Created attachment 91424 [details] GnuCash data file which shows the incorrect stock value in Investment Portfolio Attaching the data file to this bug report so you don't have to download it from my site.
Actually this isn't limited to the Investment Portfolio report. The same total value is displayed in the Total (EUR) column of the Accounts tab. Changing the summary and component of this bug report.
Got the same results in GnuCash 2.2.0 (installed from MacPorts).
A similar thing happens to me with asset report. In these reports the price of the shares is shown according to the last price I have purchased a share, not the price in "Price Editor". Moreover the calculations for foreign shares are as if they are denominated in the local currency. My local currency is BGN and if I have shares denominated in EUR (1 EUR = 1.95 BGN), their value is roughly halfed (because GnuCash calculates shares for 1000 EUR as if they are 1000 BGN). If I change the price of the share in "Price Editor" this changes nothing in the report. However if I buy 0.00001 share for double price (i.e. in the transaction I am entering the price in BGN even though GnuCash thinks this is EUR), then the report becomes correct. I must add that the calculations are wrong only in the reports. In the main screen everything in EUR is being transformed correctly to BGN according to the values in "Price Editor".
Re comment 4: Anton, is the immediate parent account of the stock account denominated in EUR or in BGN? It should be EUR. (See bug 495137.) So you need to have something like "Assets:Investments:EUR Investments" which is denominated in EUR, with a subaccount to hold the stock that is priced in EUR.
Nikita: Make sure that when you buy a stock, the parent of the stock account is denominated in the currency that the stock is priced in. In your attached example, you are buying a stock in USD but the parent account is EUR. This means that the price of "10" entered on the buy transaction is 10 EUR, not 10 USD. See bug 495137. However, this doesn't fix the bug that you reported. I can reproduce your bug with the latest code and I'm working on a patch. Confirming this bug.
(In reply to comment #6) > Nikita: Make sure that when you buy a stock, the parent of the stock account is > denominated in the currency that the stock is priced in. Thanks for this recommendation. I will add this additional node to my stock account tree.
OK, good news: My fix works and I will commit the changes soon. (The server is down at the moment.) With the attached example I now see 918.37 in the Investment Portfolio report and in the account tab.
Fix committed as r17409. Requesting backport for 2.2.
Applied to branches/2.2 as r17510 for inclusion in GnuCash 2.2.7. Thanks a lot!
Also see bug 592569 - might happen again.
I loaded the attached data file with GnuCash 2.5.0 on Ubuntu 12.04 and followed the steps in Comment 1. The EUR amount is calculated to 918.37 -> as expected.
The single transaction in the attached file is rather strange. The transaction currency is EUR and it has two splits: Split 1 31 AT&T 310 EUR Split 2 0 USD -310 EUR I don't know how you created a transaction like this, but if you turned on trading accounts it wouldn't be balanced. It also implies an infinite exchange rate between USD and EUR. Nevertheless, the Advanced Portfolio report handles this more or less correctly, mainly because it only looks at split 1 and largely ignores split 2. The bug that causes the value to be €918.51 when it should be €918.37 is a rounding bug in the C code that handles exchanges. If it had to go through an intermediate currency to get to the target currency (in this case first convert AT&T to USD and then USD to EUR) it was rounding the intermediate result when it shouldn't have been. Oddly the code that handled "latest" conversions worked, but the code that handled "nearest" didn't, so your example worked ok if you switched to "latest" prices. I've fixed this and it will be in the next build.
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=454827. Please update any external references or bookmarks.