Bug 357784 - Buying investments not always displaying correct investment sum
Summary: Buying investments not always displaying correct investment sum
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 4.7.1
Platform: Microsoft Windows Microsoft Windows
: NOR minor
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL: https://picload.org/image/wrpgill/inv...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-10 11:02 UTC by T.B.
Modified: 2021-12-28 00:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.0.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description T.B. 2016-01-10 11:02:07 UTC
The displayed sum of investments being bought or saled may be subject to a rounding error depending on the fraction setup of the investment.

The sum of money involved is rounded according to the fraction setting of the investment, which is wrong. While investments may be subject to fractions, the price for the investment needs financial rounding according to the currency of the price, what are usually 2 digits to display Cent values.

Reproducible: Always

Steps to Reproduce:
1. Create or edit any investment. Let it have a fraction value of 1 / 1
2. In your stocks account, buy 11 pieces of that investment having a price of 12,34 € (currency does not matter).
3. review the sum price of the investment

Actual Results:  
The sum is being reported as 136 € without any digits. 

Expected Results:  
The correct sum would be 135,74 €

If the behaviour is as desired, at least the german help information is wrong. It qotes "Stückelung: Die Genauigkeit, mit der Ihr Aktienbesitz gemessen wird.  [...]  Aktien werden oft nur in ganzen Einheiten gerechnet. Für eine solche Aktie muss der Wert „1“ eingegeben werden." 
The suggested fraction for stocks is 1 and there is no mention of an impact of the displayed investment sum. Once stored, the investment sum is displayed correctly, it is an annoying effect during entering the transaction.
Comment 1 NSLW 2017-04-01 06:19:11 UTC
Git commit c6e31c96a03ad5a7ec5e3695bbfa8336181ab81c by Łukasz Wojniłowicz.
Committed on 01/04/2017 at 06:16.
Pushed by wojnilowicz into branch 'master'.

Fix rounding problem with investments

Patch introduces rounding rules per security for fixing bug #372163. It
seems that this broker always rounds amounts down while my broker rounds
amounts depending on the outlying digit, so it couldn't work for both of
us without rules.

Rounding is done in InvestTransactionEditor because it has all needed
informations at hand.

No rounding of shares is done in InvestTransactionEditor::setupPrice.
Transaction from bug #372163 looks as follows:
brokerage:
shares = 1,009 ; value = 1,009
investment:
shares = -1 ; value = 1,009

InvestTransactionEditor::setupPrice causes brokerage to look as follows:
shares = 1,01 ; value = 1,009
As we can see shares and value diverge, which is unacceptable here.

Patch makes assumption that transaction has only single split of
stock/mutual fund/bond.
Related: bug 345655, bug 365177, bug 372163
FIXED-IN:5.0

Differential Revision: https://phabricator.kde.org/D5187

Signed-off-by: Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>

M  +32   -15   kmymoney/dialogs/investtransactioneditor.cpp
M  +31   -0    kmymoney/kmymoneyutils.cpp
M  +22   -0    kmymoney/kmymoneyutils.h
M  +39   -0    kmymoney/mymoney/mymoneysecurity.cpp
M  +27   -8    kmymoney/mymoney/mymoneysecurity.h
M  +1    -0    kmymoney/mymoney/storage/mymoneydbdef.cpp
M  +3    -0    kmymoney/mymoney/storage/mymoneystoragesql.cpp
M  +4    -3    kmymoney/widgets/transaction.cpp
M  +11   -0    kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpage.cpp
M  +104  -90   kmymoney/wizards/newinvestmentwizard/kinvestmentdetailswizardpagedecl.ui
M  +2    -0    kmymoney/wizards/newinvestmentwizard/knewinvestmentwizard.cpp

https://commits.kde.org/kmymoney/c6e31c96a03ad5a7ec5e3695bbfa8336181ab81c