[GNC] gnucash_user: rounding errors and significant digits

Jim DeLaHunt list+gnucash at jdlh.com
Thu Sep 14 20:43:29 EDT 2023


Bruce:

On 2023-09-14 14:51, Bruce McCoy via gnucash-user wrote:
> ...Whatare some of the options available to GnuCash programmers today toimprove precision? Here is one group....
> [Long list of arithmetic libraries elided]
Wait, you skipped a step. You have still not demonstrated that the 
current implementation is wrong. I believe that for securities 
transaction, GnuCash gives a result which is both correct (satisfies the 
equation relating price, quantity, and amount) and precisely accurate 
(gives the require numbers with zero difference from the true result).  
Any other arithmetic library dropped into GnuCash would give exactly the 
same result.
> Whatcan we do while awaiting a, say, decimal arithmetic or arbitraryprecision arithmetic software or some other excellent solution? Ifthe GnuCash community would like to have Gnucash software match thestatements from the investment firms calculating their holdings orthe members' own records, ...

This would be a great opportunity for you to answer the question I 
repeated to you last message:

On 2023-09-09 13:05, Jim DeLaHunt wrote:

> 1. if your brokerage reports a transaction in terms of price, currency 
> received and paid, and shares received and issued, which are logically 
> inconsistent, how should you interpret that information? This is a 
> step you have to take before entering the transaction into your 
> bookkeeping.

But I see you skipped over it again.

> Currently,given the cost of the transaction and the number of shares traded,GnuCash calculates the price per share. On occasion, the Gnucashcalculation results are unexpected. In our example at hand, ... if we could allow the user to enter $15.00, we wouldhave a solution, albeit a manual one.

Ah, maybe now we are getting somewhere.

GnuCash does allow you to enter the exact value of $15.00 for the 
transaction amount. You do not need to enter a price. Have you tried 
this in the GnuCash UI?

When you try to enter the example transaction at hand (broker sells 
2.396 of shares to pay a fee of $15.00), you are probably using the 
stock transaction register. The Tutorial and Guide[1], section 9.7. 
Selling Shares [2], explains this UI. Specifically, see Figure 9.21. 
"Selling Shares for Gain Where the Sale and Gain are Recorded in 
Separate Transactions, in Transaction Journal View"[3].

(These numbers in square brackets are footnootes to URLs. I put the full 
URLs at the bottom of the message to make this part easier to read.)

The second transaction if Figure 9.21 is similar to what you would enter.
1. The line with account "Assets:Bank ABC" has 0 in the Buy column, or 
you leave it out entirely. The example transaction at hand does not 
touch the cash account associated with this brokerage.
2. The line with account "Expenses:Commission:AMZN" would instead have 
the expense account you use to track the fee which your brokerage is 
charging, and has the value 15.00 in the Buy column.
3. The line with account "Assets:Brokerage Account:Stock:AMZN" is the 
one with the UI which matters here. When you enter the transaction, type 
"-2.396" in the Shares column, leave the Price column empty, and type 
"15.00" in the Sell column.

When you save the transaction, GnuCash will fill in the price for you. 
What I see it fill in is, "6 + 156/599". This is equal to the rational 
number 3750/599. We saw this number before, as the price which exactly 
relates 2.396 shares to the $15.00 transaction amount.

This UI is also explained in the Tutorial and Guide, section 9.5 Buying 
Shares[4]. It says there,

> …On the first split line, enter *|100|* in *Shares*, delete the (unit) 
> *Price* (it will be calculated when you *Tab* out of the split) and 
> enter *|2000|* in the *Buy* column.
>
> 	Note
>
> It is also possible to use *|GnuCash|* to calculate *Shares* or *Buy* 
> from the other 2 columns. But to avoid rounding errors, it is better 
> to automatically calculate *Price*.
>
Have you tried entering this stock transaction without entering the 
price, and letting GnuCash calculate it for you?

> ...GnuCashcalculates $value = $price/share * #shares....
Well, GnuCash will calculate whichever single value of these three that 
you do not enter, as long as you provide the other two. The recommended 
way to do it is to enter #shares and $value, and let GnuCash calculate 
$price/share .
> ...A screen showing thosethree results in data-entry fields instead of read-only fields wouldallow the user to change the aberrant result, which could be saved....

The stock transaction register provides exactly these data-entry fields. 
They are not read-only. Do you see, in your copy of GnuCash, something 
similar to the UI depicted in Figure 9.21?

Also, have you read through all of Section 9 of the Tutorial and 
Concepts Guide?  Have you made a simple book for learning purposes, with 
made-up data, and followed along with the examples in the Guide?  If 
not, I highly recommend it to you. It is an excellent way to learn 
GnuCash. (I myself just opened my test book to try the stock transaction 
register as show in Figure 9.21.)

Footnotes:
[1] <https://gnucash.org/viewdoc.phtml?rev=5&lang=C&doc=guide>
[2] <https://www.gnucash.org/docs/v5/C/gnucash-guide/invest-sell1.html>
[3] 
<https://www.gnucash.org/docs/v5/C/gnucash-guide/figures/invest_sellstockManProfSep.png>
[4] <https://www.gnucash.org/docs/v5/C/gnucash-guide/invest-buy-stock1.html>

Best regards,
     —Jim DeLaHunt



More information about the gnucash-user mailing list