It can occasionally happen, in the current code for jGnash 1.x, that the "market value" of an investment account, as shown in the investment register, will not agree with the total market value as shown in the Portfolio Report.
The attached file,
demonstrates this problem. It is a variant on the standard test file, "mini.jgnash.xml", as stored in the repository (and last updated in the commit which created revision 2134, which was part of the implementation of Feature Request number 3,005,411, 'Add support for retrieving "share balance" from a script').
In the new "security-value-rounding-problem" test data file, there is one investment account, whose name is "brokerage account". It has a "Cash Balance" of zero, so its "Market Value" should be equal to its "Balance" (both as shown at the top of the investment register; the "Balance" shown there is actually the total value of the account).
And these two figures in the investment register are indeed equal, at $23,212.30. This is also, as expected, the value of the account as shown in the jGnash "Account list", when "Accounts" is selected in the jGnash main window.
But if you run a Portfolio on this same account, the figure shown as "Value", under "Summary", is one cent less: $23,212.29.
I have a real-life data file in which, one month, there was the same discrepancy (for one investment account) between the value as shown in the register, and in the "Account list", on the one hand, and that shown in the Portfolio Report, on the other hand. The value shown in the Portfolio Report was the one which agreed with my brokerage statement for that month. In practical terms, I think this means that this should be called the "correct" value: the value shown in the investment register, and in the "Account list", should be the same.
jGnash uses BigDecimal objects as internal representations of amounts of money, so its calculations with such amounts should be exact: we can't blame this small discrepancy on the inherent rounding errors seen with floating-point numbers.
I have not yet dived into the code in order to track down the cause of the discrepancy. However, the results are at least consistent with the following hypothesis:
1. When you do an exact multiplication of the current "quantity" (number of shares held) for a security in an account, and the latest price of that security, the result will often be a number with extra decimal places: not an integral number of dollars and cents, or whatever is the standard representation for the applicable currency.
2. You get the result shown in the investment register, and in the "Account list", if you do an exact additions of all these multiplication results, and *only then* round the total to the nearest cent.
3. You get the result shown in the Portfolio Report, and in the broker's statement, if you first round the result of each multiplication to the nearest penny, and then add up these rounded results.
So the hypothesis is that this is the difference between what the two calculations are actually doing.
If this is correct, then, in my opinion, the calculation of the "Market Value", as shown in the investment register, should be changed so as to be consistent with the calculation done in preparing the Portfolio Report.
Log in to post a comment.