GNOME Bugzilla – Bug 373584
Rounding error in QIF import of commodity transactions
Last modified: 2018-06-29 21:15:41 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 ^
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
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.
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.
Applied to trunk in r16874. Awaiting backport
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
Applied to branches/2.2 in r16894 for GnuCash 2.2.4. Thanks a lot!
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.