GNOME Bugzilla – Bug 131623
Unrealized Gains of Balance Sheet are wrong
Last modified: 2018-06-29 20:40:25 UTC
I do not believe that the Unrealized Gains line of the Balance Sheet report functions correctly. It gives incomprehensible values. Simplest is to see an example (I did not know to join the file differently). In this report, instead of finding 0 with Unrealized Gains line, I find value XPF 1 999 332,00. For your information : my currency report is XPF and the price source is nearest in time. Thanks. The test file : <?xml version="1.0"?><gnc-v2><gnc:count-data cd:type="book">1</gnc:count-data><gnc:book version="2.0.0"><book:id type="guid">111e7eb5992d460ce6c15cb1d4183449</book:id><gnc:count-data cd:type="commodity">2</gnc:count-data><gnc:count-data cd:type="account">18</gnc:count-data><gnc:count-data cd:type="transaction">2</gnc:count-data><gnc:commodity version="2.0.0"> <cmdty:space>FUND</cmdty:space> <cmdty:id>FEB</cmdty:id> <cmdty:name>Fidelity Europe Bond</cmdty:name> <cmdty:fraction>100</cmdty:fraction></gnc:commodity><gnc:commodity version="2.0.0"> <cmdty:space>FUND</cmdty:space> <cmdty:id>FIB</cmdty:id> <cmdty:name>Fidelity Int Bond</cmdty:name> <cmdty:xcode>123456</cmdty:xcode> <cmdty:fraction>100</cmdty:fraction></gnc:commodity><gnc:pricedb version="1"> <price> <price:id type="guid">98e39d74e6cff3a22f7b79572c788e1d</price:id> <price:commodity> <cmdty:space>FUND</cmdty:space> <cmdty:id>FEB</cmdty:id> </price:commodity> <price:currency> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>USD</cmdty:id> </price:currency> <price:time> <ts:date>2004-01-01 00:00:00 +1100</ts:date> </price:time> <price:source>user:xfer-dialog</price:source> <price:type>last</price:type> <price:value>1000000/1000000</price:value> </price> <price> <price:id type="guid">6660d93ca0167dc81404e745806604fc</price:id> <price:commodity> <cmdty:space>FUND</cmdty:space> <cmdty:id>FIB</cmdty:id> </price:commodity> <price:currency> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>EUR</cmdty:id> </price:currency> <price:time> <ts:date>2004-01-01 00:00:00 +1100</ts:date> </price:time> <price:source>user:xfer-dialog</price:source> <price:type>last</price:type> <price:value>10000000/1000000</price:value> </price> <price> <price:id type="guid">b6bed669d0053818bf8dfc0c04382ca3</price:id> <price:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>EUR</cmdty:id> </price:commodity> <price:currency> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </price:currency> <price:time> <ts:date>2004-01-01 00:00:00 +1100</ts:date> </price:time> <price:source>user:price-editor</price:source> <price:type>last</price:type> <price:value>119332000/1000000</price:value> </price> <price> <price:id type="guid">bcbf3557d705876512248921b77be660</price:id> <price:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>USD</cmdty:id> </price:commodity> <price:currency> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </price:currency> <price:time> <ts:date>2004-01-01 00:00:00 +1100</ts:date> </price:time> <price:source>user:price-editor</price:source> <price:type>last</price:type> <price:value>95000000/1000000</price:value> </price></gnc:pricedb><gnc:account version="2.0.0"> <act:name>Actif</act:name> <act:id type="guid">1ea4397e17d0cdda07bf32da245d6044</act:id> <act:type>ASSET</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Avoir</act:description></gnc:account><gnc:account version="2.0.0"> <act:name>Investissements</act:name> <act:id type="guid">3100fea612bde1083d89e84baae9ccd4</act:id> <act:type>ASSET</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Investissements</act:description> <act:parent type="guid">1ea4397e17d0cdda07bf32da245d6044</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Compte de bourse/titre</act:name> <act:id type="guid">1c2212629e94ee1940e3bf28a7932042</act:id> <act:type>BANK</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Compte de bourse/titres</act:description> <act:parent type="guid">3100fea612bde1083d89e84baae9ccd4</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>FEB</act:name> <act:id type="guid">f3bdb07015fb5b6ab7318948ba306107</act:id> <act:type>STOCK</act:type> <act:commodity> <cmdty:space>FUND</cmdty:space> <cmdty:id>FEB</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:slots> <slot> <slot:key>placeholder</slot:key> <slot:value type="string">false</slot:value> </slot> <slot> <slot:key>notes</slot:key> <slot:value type="string"></slot:value> </slot> </act:slots> <act:parent type="guid">1c2212629e94ee1940e3bf28a7932042</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>FIB</act:name> <act:id type="guid">8cde8b72af2883b8e09c92266d6b38c5</act:id> <act:type>STOCK</act:type> <act:commodity> <cmdty:space>FUND</cmdty:space> <cmdty:id>FIB</cmdty:id> </act:commodity> <act:commodity-scu>10000</act:commodity-scu> <act:non-standard-scu/> <act:description>Action</act:description> <act:slots> <slot> <slot:key>placeholder</slot:key> <slot:value type="string">false</slot:value> </slot> <slot> <slot:key>notes</slot:key> <slot:value type="string"></slot:value> </slot> </act:slots> <act:parent type="guid">1c2212629e94ee1940e3bf28a7932042</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Obligation</act:name> <act:id type="guid">7985e929ee668e5296428d8160b88a05</act:id> <act:type>STOCK</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Obligation</act:description> <act:parent type="guid">1c2212629e94ee1940e3bf28a7932042</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Fond commun</act:name> <act:id type="guid">a8679f4b2dd05cb447ea6955c51a309b</act:id> <act:type>MUTUAL</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Fond commun</act:description> <act:parent type="guid">1c2212629e94ee1940e3bf28a7932042</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Marché d'indice</act:name> <act:id type="guid">294d987f9474c0159b038c04c1c11211</act:id> <act:type>MUTUAL</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Marché d'indice</act:description> <act:parent type="guid">1c2212629e94ee1940e3bf28a7932042</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Revenus</act:name> <act:id type="guid">4c242d63101ff6ee3027f319b81dd97b</act:id> <act:type>INCOME</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Revenus</act:description></gnc:account><gnc:account version="2.0.0"> <act:name>Revenu d'intérêts</act:name> <act:id type="guid">4204220fa8270791cbcc84b8f45c196a</act:id> <act:type>INCOME</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Revenu d'intérets</act:description> <act:parent type="guid">4c242d63101ff6ee3027f319b81dd97b</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Intérêts d'obligation</act:name> <act:id type="guid">fb8323dd74a346281ca5a436e28465e4</act:id> <act:type>INCOME</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Intérêts d'obligation</act:description> <act:parent type="guid">4204220fa8270791cbcc84b8f45c196a</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Revenu de dividende</act:name> <act:id type="guid">f7b0fb41cc0c73c967f06c25f468dd7c</act:id> <act:type>INCOME</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Revenu de dividende</act:description> <act:parent type="guid">4c242d63101ff6ee3027f319b81dd97b</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Dépenses</act:name> <act:id type="guid">8ddb5ef7394175d8132e939a51af3828</act:id> <act:type>EXPENSE</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Dépenses</act:description></gnc:account><gnc:account version="2.0.0"> <act:name>Commissions</act:name> <act:id type="guid">274af65e11c43f9e6afb1ceaa289cb40</act:id> <act:type>EXPENSE</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:description>Commissions</act:description> <act:parent type="guid">8ddb5ef7394175d8132e939a51af3828</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Init</act:name> <act:id type="guid">3601de0d6ad86cb3a54aa6833874210b</act:id> <act:type>EQUITY</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:slots> <slot> <slot:key>placeholder</slot:key> <slot:value type="string">false</slot:value> </slot> <slot> <slot:key>notes</slot:key> <slot:value type="string"></slot:value> </slot> </act:slots></gnc:account><gnc:account version="2.0.0"> <act:name>Init Euro</act:name> <act:id type="guid">1289405d15d1e7e05bfb6ca4ddb4af49</act:id> <act:type>EQUITY</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>EUR</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:slots> <slot> <slot:key>placeholder</slot:key> <slot:value type="string">false</slot:value> </slot> <slot> <slot:key>notes</slot:key> <slot:value type="string"></slot:value> </slot> </act:slots> <act:parent type="guid">3601de0d6ad86cb3a54aa6833874210b</act:parent></gnc:account><gnc:account version="2.0.0"> <act:name>Init USD</act:name> <act:id type="guid">3ff2fc680797782ffb69a4a07651f169</act:id> <act:type>EQUITY</act:type> <act:commodity> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>USD</cmdty:id> </act:commodity> <act:commodity-scu>100</act:commodity-scu> <act:slots> <slot> <slot:key>placeholder</slot:key> <slot:value type="string">false</slot:value> </slot> <slot> <slot:key>notes</slot:key> <slot:value type="string"></slot:value> </slot> </act:slots> <act:parent type="guid">3601de0d6ad86cb3a54aa6833874210b</act:parent></gnc:account><gnc:transaction version="2.0.0"> <trn:id type="guid">04d78326b2f6ad2309299855a10cd28f</trn:id> <trn:currency> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>XPF</cmdty:id> </trn:currency> <trn:date-posted> <ts:date>2004-01-01 00:00:00 +1100</ts:date> </trn:date-posted> <trn:date-entered> <ts:date>2004-01-13 20:36:02 +1100</ts:date> </trn:date-entered> <trn:description></trn:description> <trn:splits> <trn:split> <split:id type="guid">93fbb2b75909bbc417bf3b50a3f3d0b9</split:id> <split:action>Acheter</split:action> <split:reconciled-state>n</split:reconciled-state> <split:value>2000000/100</split:value> <split:quantity>2000000/100</split:quantity> <split:accounttype="guid">f3bdb07015fb5b6ab7318948ba306107</split:account> </trn:split> <trn:split> <split:id type="guid">0b04cbb5733cf1aa32939078fddb849f</split:id> <split:reconciled-state>n</split:reconciled-state> <split:value>-2000000/100</split:value> <split:quantity>-2000000/100</split:quantity> <split:accounttype="guid">3ff2fc680797782ffb69a4a07651f169</split:account> </trn:split> </trn:splits></gnc:transaction><gnc:transaction version="2.0.0"> <trn:id type="guid">8fa22b9ba12cfcb2e2d7ba4149f1d182</trn:id> <trn:currency> <cmdty:space>ISO4217</cmdty:space> <cmdty:id>EUR</cmdty:id> </trn:currency> <trn:date-posted> <ts:date>2004-01-01 00:00:00 +1100</ts:date> </trn:date-posted> <trn:date-entered> <ts:date>2004-01-13 19:43:33 +1100</ts:date> </trn:date-entered> <trn:description></trn:description> <trn:splits> <trn:split> <split:id type="guid">775b75dd6ad1fc033e01a72a3b541b74</split:id> <split:action>Acheter</split:action> <split:reconciled-state>n</split:reconciled-state> <split:value>100000/100</split:value> <split:quantity>1000000/10000</split:quantity> <split:accounttype="guid">8cde8b72af2883b8e09c92266d6b38c5</split:account> </trn:split> <trn:split> <split:id type="guid">829c31f1f21ebc9fa3d0d05fd68e6b22</split:id> <split:reconciled-state>n</split:reconciled-state> <split:value>-100000/100</split:value> <split:quantity>-100000/100</split:quantity> <split:accounttype="guid">1289405d15d1e7e05bfb6ca4ddb4af49</split:account> </trn:split> </trn:splits></gnc:transaction></gnc:book></gnc-v2><!-- Local variables: --><!-- mode: xml --><!-- End: -->
*** Bug 131626 has been marked as a duplicate of this bug. ***
*SIGH* Can you please **ATTACH** the xml file... I specifically asked you to attach it. I guess I was not explicit enough that you should NOT "inline" the file....
Created attachment 23417 [details] gnucash file test
Excuse to me to have put the file test in the post body. It is my first post and the preceding stage doesn't propose to join a file with the post.
I have noticed the same incorrect value calculated for Gains and Losses on the "Advanced Portfolio" report when using GnuCash 1.8.8. If you take the sample file that is attached and create an Advanced Portfolio report the change the Report Currency to XPF you will notice that the "Money In" column in the report lists the amounts in the original currencies instead of the Report Currency, even though the report has labeled the amount as XPF. For example the FEB item has Money In as XPF 20000. The 20000 is clearly the USD price of the stock since there are 20000 shares at 1 USD each. 1 USD converts to 95 XPF's (according to the Price Editor). So Money In should have been 1900000 XPF as well.
Please confirm this bug as of gnucash-20040624-120811-cvs.diff. The example file contains Equity accounts in multiple currencies, which the old Balance Sheet did not consider. The new Balance Sheet code treats an increase in the value of an equity account as an unrealized loss---which I think is the correct behavior.
*** Bug 171801 has been marked as a duplicate of this bug. ***
Is this bug still relevant in SVN/1.9.x/2.0.0 or has the respective problem already been fixed?
*** Bug 334775 has been marked as a duplicate of this bug. ***
(In reply to comment #8) > Is this bug still relevant in SVN/1.9.x/2.0.0 or has the respective problem > already been fixed? I have verified that the problem persists in version 1.9.2. The problem seems to be in the actual calculation of the unrecognized gain. It seems to fail when there are transactions to be accumulated with either zero units or zero balance.
Created attachment 66868 [details] [review] Patch to fix the problem The balance sheet report tried to use the difference between the current price value and the average price value to get the unrealized gains. This makes assumptions about what's in your price DB and is not valid in any case if there are partial sales or transactions where either the amount or the value is zero. This patch changes it to get the basis for each asset by summing the value in transaction currency of each split in the account and subtracting that from the current value at the time of the report. This is the approach that the capital gains calculator in the lot code uses and it seems to work. I will attach another simple test file and a before and after report.
Created attachment 66869 [details] Simple test file This file is a very simple test file which demonstrates the problem. A balance sheet report for the file shows it out of balance by $6467.34 which is exactly twice the value of the last transaction in the Corus account. This transaction is a "return of capital" transaction which changes the basis of the stock without changing the number of shares.
Created attachment 66870 [details] Report before the change This report was made with the version before this patch was applied.
Created attachment 66871 [details] Report after the change This report is from the same file after the patch was applied.
*** Bug 91661 has been marked as a duplicate of this bug. ***
*** Bug 356077 has been marked as a duplicate of this bug. ***
More test cases of this bug are in bug#356077 bug#169946 . Raising severity because of multiple reports.
I have verified that this problem remains in 2.0.2.
Created attachment 86552 [details] [review] New patch that works with the SWIG changes This is a new patch that works after the swigification of GnuCash. It is slightly different from the previous patch since it also adds a new option to the balance sheet report to turn off the calculation of unrealized gains entirely. This change is part of my changes to implement the use of commodity trading accounts. When trading accounts are used, they record unrealized gains and the balance sheet report shouldn't compute them separately. Having this option in the report without trading accounts may be a bit confusing, but won't hurt anything (it defaults to on). I didn't want to try to separate the two changes and perhaps submit a non-working patch. I've tried this patch with the test file attached to this bug (which doesn't have trading accounts, of course) and it works fine.
trunk/@15972. 2.1.1. Thanks.
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=131623. Please update any external references or bookmarks.