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 131623 - Unrealized Gains of Balance Sheet are wrong
Unrealized Gains of Balance Sheet are wrong
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Reports
git-master
Other Linux
: High major
: ---
Assigned To: Chris Lyttle
Chris Lyttle
: 91661 131626 171801 334775 356077 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-01-16 01:01 UTC by Bernard FUENTES
Modified: 2018-06-29 20:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gnucash file test (13.53 KB, text/plain)
2004-01-16 02:53 UTC, Bernard FUENTES
  Details
Patch to fix the problem (4.33 KB, patch)
2006-06-07 04:36 UTC, Mike Alexander
rejected Details | Review
Simple test file (19.29 KB, application/xml)
2006-06-07 04:39 UTC, Mike Alexander
  Details
Report before the change (7.06 KB, text/html)
2006-06-07 04:40 UTC, Mike Alexander
  Details
Report after the change (7.06 KB, text/html)
2006-06-07 04:41 UTC, Mike Alexander
  Details
New patch that works with the SWIG changes (5.76 KB, patch)
2007-04-18 05:41 UTC, Mike Alexander
committed Details | Review

Description Bernard FUENTES 2004-01-16 01:01:34 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&#233; 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&#233; 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&#233;r&#234;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&#233;rets</act:description>  <act:parent
type="guid">4c242d63101ff6ee3027f319b81dd97b</act:parent></gnc:account><gnc:account
version="2.0.0">  <act:name>Int&#233;r&#234;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&#233;r&#234;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&#233;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&#233;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:             -->
Comment 1 Derek Atkins 2004-01-16 02:07:21 UTC
*** Bug 131626 has been marked as a duplicate of this bug. ***
Comment 2 Derek Atkins 2004-01-16 02:08:38 UTC
*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....

Comment 3 Bernard FUENTES 2004-01-16 02:53:24 UTC
Created attachment 23417 [details]
gnucash file test
Comment 4 Bernard FUENTES 2004-01-16 02:57:41 UTC
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.
Comment 5 Peter Long 2004-06-25 03:28:51 UTC
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.
Comment 6 Phil T. Rich 2004-06-25 21:57:53 UTC
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.
Comment 7 Michael Perfit 2005-03-29 11:17:17 UTC
*** Bug 171801 has been marked as a duplicate of this bug. ***
Comment 8 Christian Stimming 2006-03-01 14:58:02 UTC
Is this bug still relevant in SVN/1.9.x/2.0.0 or has the respective problem already been fixed?
Comment 9 Christian Stimming 2006-03-17 16:29:21 UTC
*** Bug 334775 has been marked as a duplicate of this bug. ***
Comment 10 Michael Perfit 2006-03-21 15:03:20 UTC
(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.

Comment 11 Mike Alexander 2006-06-07 04:36:18 UTC
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.
Comment 12 Mike Alexander 2006-06-07 04:39:34 UTC
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.
Comment 13 Mike Alexander 2006-06-07 04:40:37 UTC
Created attachment 66870 [details]
Report before the change

This report was made with the version before this patch was applied.
Comment 14 Mike Alexander 2006-06-07 04:41:33 UTC
Created attachment 66871 [details]
Report after the change

This report is from the same file after the patch was applied.
Comment 15 Christian Stimming 2006-09-15 08:57:10 UTC
*** Bug 91661 has been marked as a duplicate of this bug. ***
Comment 16 Christian Stimming 2006-09-15 08:57:29 UTC
*** Bug 356077 has been marked as a duplicate of this bug. ***
Comment 17 Christian Stimming 2006-09-15 08:58:54 UTC
More test cases of this bug are in bug#356077 bug#169946 . Raising severity because of multiple reports.
Comment 18 Michael Perfit 2006-12-17 01:46:47 UTC
I have verified that this problem remains in 2.0.2.  
Comment 19 Mike Alexander 2007-04-18 05:41:47 UTC
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.
Comment 20 Josh Sled 2007-04-21 22:19:56 UTC
trunk/@15972. 2.1.1.  Thanks.
Comment 21 John Ralls 2018-06-29 20:40:25 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=131623. Please update any external references or bookmarks.