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 373584 - Rounding error in QIF import of commodity transactions
Rounding error in QIF import of commodity transactions
Status: VERIFIED FIXED
Product: GnuCash
Classification: Other
Component: Import - QIF
2.2.x
Other All
: Normal normal
: ---
Assigned To: Derek Atkins
Derek Atkins
Depends on:
Blocks: backport
 
 
Reported: 2006-11-10 22:15 UTC by Derek Brader
Modified: 2018-06-29 21:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
QIF showing rounding error w/ and w/o commission (267 bytes, text/plain)
2008-01-10 04:43 UTC, Charles Day
  Details
Proposed patch (1.92 KB, patch)
2008-01-10 11:55 UTC, Charles Day
committed Details | Review

Description Derek Brader 2006-11-10 22:15:53 UTC
Please describe the problem:
When importing a QIF involving commodity transactions (such as stocks or mutual funds), GnuCash seems to calculate the debit column from the number of shares and the commodity value rather than taking the debit value provided by the QIF.  This can lead to rounding problems since the smallest accountable fraction of a commodity may not be so small.  

Steps to reproduce:
1. Import QIF File containing certain commodity transactions
2. Pick bogus commodity info for the fund account that will be created
3. go look at the new transaction: it should contain a split to "Imbalance-USD" of $0.11.  

Actual results:
The transaction that is created is not balanced: it contains a split to "Imbalance-USD"

Expected results:
The transactions created should be balanced because the debit and credit values supplied by the QIF should be used.  The price supplied by the QIF should be ignored, as it is not necessarily accurate.  What really matters is the debit column, the credit column, and the number of shares.  GnuCash should calculate the price on its own.

Does this happen every time?
Yes.

Other information:
Below is a sample QIF file (starting with "!Type" and ending with "^").  Note that $87.45 * 0.180 = 15.741, while the listed debit amount is $15.85.  The proper (non-rounded) share price should be $15.85/0.180 = 88.05.  This is not the actual commodity value, but since the smallest tradable value is 0.001*$87.45 = $0.08745, the number of shares transferred (and hence the effective commodity price) changes due to rounding. 

!Type:Invst
D10/02/2006
NBuy
YMUTUAL FUND
I87.45000
Q0.180
U15.85
T15.85
MContribution
^
Comment 1 Charles Day 2008-01-10 00:37:04 UTC
Be careful... The QIF file does not provide the total amount paid for the shares. What appears in the "T" line is the price paid for the shares *plus* commission ("O" line, if any).

If the importer is to ignore the price per share given in the "I" line, it would have to do the following:
    total without commission = "T" line - "O" line (if any)
    price per share = total without commission / "Q" line
Comment 2 Charles Day 2008-01-10 04:43:31 UTC
Created attachment 102502 [details]
QIF showing rounding error w/ and w/o commission

There are two transactions is this QIF that cause a rounding error; the second also involves a commission.
Comment 3 Charles Day 2008-01-10 11:55:37 UTC
Created attachment 102512 [details] [review]
Proposed patch

I have tested this patch with small files and with a very large file of personal data with a variety of investment transactions.
Comment 4 Derek Atkins 2008-01-20 17:53:41 UTC
Applied to trunk in r16874.
Awaiting backport
Comment 5 Derek Brader 2008-01-20 20:55:22 UTC
For what it's worth, I tested out this patch on 2.2.2, and it resolves the issues i was previously seeing.  Thanks muchly!  

~DB
Comment 6 Andreas Köhler 2008-01-30 20:29:21 UTC
Applied to branches/2.2 in r16894 for GnuCash 2.2.4.
Thanks a lot!
Comment 7 John Ralls 2018-06-29 21:15:41 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=373584. Please update any external references or bookmarks.