Summary: | Investment Performance by Account YTD Return on Investment result different between version 4.8 and 5.01 | ||
---|---|---|---|
Product: | [Applications] kmymoney | Reporter: | Jon <CloudDriver46> |
Component: | reports | Assignee: | KMyMoney Devel Mailing List <kmymoney-devel> |
Status: | RESOLVED FIXED | ||
Severity: | major | CC: | ralf.habacker |
Priority: | NOR | ||
Version: | 5.1.2 | ||
Target Milestone: | --- | ||
Platform: | Mint (Ubuntu based) | ||
OS: | Linux | ||
Latest Commit: | https://invent.kde.org/office/kmymoney/-/commit/10050df47680422bf98dd8311b6e87cc362926f5 | Version Fixed In: | 5.2 |
Sentry Crash Report: | |||
Attachments: |
test file
Screenshot showing the issue (see line B) |
Description
Jon
2018-07-08 02:36:38 UTC
Thank you for reporting this issue in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version? If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you! I am currently using KmyMoney version 5.1.2 running on Linux Mint version 21. The Investment Performance By Account report continues to miscalculate the Return on Investment for those investments that have some or all Dividends Reinvested. The report correctly calculates Return on Investment for all other situations, including when all Dividends are Paid Out. Using the column headings on the report, I believe that Return on Investment should be calculated as follows: (Ending Balance + Dividends Paid Out + Sell Value) – (Starting Balance + Buy Value) = Return The % Return is then calculated by: 100 * Return / (Starting Balance + Buy Value) Dividends Reinvested are not an item included in the return calculation because the value of the shares from the reinvestment is already part of the Ending Balance. I created a KmyMoney file with only 4 transactions as a test. The share price for all transactions is set to $100 so that price changes could be ruled out of the issue. For the Dividends Paid Out situation: Starting Balance transaction – 12/31/21 buy 8 shares at $100/share = $800 Buy Value transaction – 3/22/22 buy 4 shares at $100/share = $400 Dividends Paid Out transaction – 6/30/22 = $150 Sell Value transaction – 12/2/22 sell 10 shares at $100/share = $1,000 Ending Balance = $200 ($200 + $150 + $1,000) - ($800 + $400) = $150 Return $150 / ($800 + $400) = 0.125 * 100 = 12.5% The The Investment Performance By Account report agrees with this result. For the Dividends Reinvested situation: Starting Balance transaction – 12/31/21 buy 8 shares at $100/share = $800 Buy Value transaction – 3/22/22 buy 4 shares at $100/share = $400 Dividends Reinvested transaction – 6/30/22 = 1.5 shares added at $100/share Sell Value transaction – 12/2/22 sell 10 shares at $100/share = $1,000 Ending Balance = $350 ($350 + $0 + $1,000) - ($800 + $400) = $150 Return $150 / ($800 + $400) = 0.125 * 100 = 12.5% For this case the The Investment Performance By Account report shows an incorrect 0% return and strangely, a 15.51% Annualized Return. How can a zero return also have a greater than zero annualized return? I only invest in mutual funds so do not know whether the calculation is different for individual stocks or bonds. When a mutual fund does a dividend reinvestment they simply add the number of shares that match the dividend value at the current price. This is not a Buy transaction. I have not yet looked into your examples in detail, but I think you over-complicate the calculations. Starting and ending balances are irrelevant to return for a single investment. (It would be the same ROI no matter which account it took place in.) Take a look at https://www.investopedia.com/articles/basics/10/guide-to-calculating-roi.asp. (I think mutual funds can use the same calculations as stocks and bonds.) First work through it without any reinvestment transactions, nut I agree that those transactions can be ignored, since they just mean you are selling more shares than you purchased. The critical values are total purchase cost and total sale value. I won't copy/paste the formula from that link, but after you review it, let us know if you still think KMM is making incorrect calculations. Annualized returns can be even more complicated if there is not a single purchase and single sale. Separately, your example shows two purchases of 8 and 4, a dividend reinvestment of 1.5 shares, but a sale of only 10 shares. What happened to the other 3.5 shares? To answer you question, the 3.5 shares not sold are the $350 in the Ending Balance. I reviewed the information on ROI calculation in the Investopedia link you provided. As an investor, I have used this calculation many times. KMyMoney does not have the functionality to correctly make this ROI calculation. KmyMoney Handbook has the following statement about ROI in the Investment section: “Unimplemented Features There are some features that are normally associated with investments which are not yet implemented in KMyMoney. These include, but are not limited to derivatives, options, and futures. In addition, when you sell a security, KMyMoney does not know which specific shares you are selling, i.e., the oldest or the most recently purchased, so it cannot calculate return on investment. Finally, it has no direct knowledge about any country's specific tax reporting requirements, but these can usually be handled by marking as Tax related all the categories you use for transactions which might have tax consequences.” After reading this, I was curious how KMyMoney was able to do the ROI calculation for the Investment Capital Gains reports. I created another KMyMoney file with one investment account and put in several Buy and Sell transactions using made up numbers to see if I could figure out how the program was determining the buy value for each time shares were sold. It appears that the program is using a First In/First Out method (first shares bought are the first shares sold). Lacking the ability to identify the specific shares sold, this a reasonable but not accurate way to estimate capital gains. The gain is accurate only for the situation where the report date range includes all of the transaction dates and also all shares have been sold. The KMyMoney file I created included only Buy transactions for 2021. For 2022 I included one Buy transactions and two Sell transactions that sold all shares. Total Buy value for 2021 was $1295 and another $210 for 2022, for a grand total of $1505. The total Sell value was $1340. The ROI calculation is therefore ($1340 – $1505) / $1505 = a 10.96% loss. The Capital Gains report in KMyMoney matches this result. When I ran the Investment Performance report with a date range of All Dates, I see Beginning Balance $0, Buy Value $1505, Sell Value $1340, Ending Balance $0 and ROI of 10.96% loss, matching the Capital Gains report. However, a different result happens when I use the default report date range of Year to Date. In that case I see Beginning Balance of $1500, Buy Value $210, Sell Value $1340, Ending Balance $0 and ROI of 21.64% loss. Since all shares that were bought were sold, this is obviously an incorrect result. The problem is that the shares bought in 2021 had an increase in share price by the end of the year bringing the ending value of the shares to $1500. The Beginning Balance for 2022 should have been the ending Buy Value for 2021 of $1295, not the Investment Value based on the year end share price. There are two types of investment gains. When shares are sold we have “realized” gains as above. If not all shares are sold we also have “unrealized” gains. Unrealized gains are calculated as the increase or decrease in share value based on the current share price minus the buy value of the shares. Unrealized gains vary from day to day as share prices change due to market activity. Unrealized gains are part of the performance of an investment. The Investment Performance report does not use the unrealized gain value as the Ending Balance. Instead, it uses the full value of the shares at the ending price. This is wrong. The report calculates the ROI by adding the Ending Balance to the Sell Value. The Ending Balance needs to be the unrealized gain amount, not the ending shares value. A better title for Ending Balance would be Unrealized Gain/Loss. Dear Bug Submitter, This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information as soon as possible and set the bug status as REPORTED. Due to regular bug tracker maintenance, if the bug is still in NEEDSINFO status with no change in 30 days the bug will be closed as RESOLVED > WORKSFORME due to lack of needed information. For more information about our bug triaging procedures please read the wiki located here: https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging If you have already provided the requested information, please mark the bug as REPORTED so that the KDE team knows that the bug is ready to be confirmed. Thank you for helping us make KDE software even better for everyone! Thanks for advising that I neglected to mark my previous comment (Comment 4) as “Reported”. Please refer to that comment for other details if necessary. The first issue with the Investment Performance reports is that the Return on Investment is only calculated correctly when the Date Range selected is either All Dates or a Date Range that begins with or earlier than the first Buy transaction. All other Date Ranges calculate an incorrect Return on Investment. The reason for the incorrect result is that the Starting Balance for these other Date Ranges is calculated by KMyMoney as the number of shares held on the report’s beginning date multiplied by the share price on that date. The correct value for the Starting Balance should be the original Buy Value of those shares, not the Buy Value +/- any gain/loss in share price as of the beginning date. The second issue with the Investment Performance reports is that the Dividends Reinvestment value is being calculated as if it were a Buy Value, which results in an incorrect Return on Investment. Buy Value is the amount of cash that an investor uses to purchase new shares. Shares added to the investor’s account by the mutual fund in a Dividend or Capital Gain distribution are not a purchase made by the shareholder. The value of shares added in a reinvestment is correctly accounted for as a part of the total number the shareholder owns. The Dividends Reinvested value should not be used in any additional way in calculating Return on Investment. Dividends Paid Out are cash in the investor’s hand and this value is correctly calculated by KMyMoney as a gain in the Investment Performance reports. (In reply to Jon from comment #4) > To answer you question, the 3.5 shares not sold are the $350 in the Ending > Balance. > > I reviewed the information on ROI calculation in the Investopedia link you > provided. As an investor, I have used this calculation many times. > KMyMoney does not have the functionality to correctly make this ROI > calculation. This issue was fixed with bug 463974 (In reply to Jon from comment #2) > For the Dividends Reinvested situation: ... > $150 / ($800 + $400) = 0.125 * 100 = 12.5% For this case the The Investment > Performance By Account report shows an incorrect 0% return and strangely, a > 15.51% Annualized Return. How can a zero return also have a greater than > zero annualized return? This has also been fixed by the changes to fix bug bug 463974 (In reply to Jon from comment #2) > $150 / ($800 + $400) = 0.125 * 100 = 12.5% For this case the The Investment > Performance By Account report shows an incorrect 0% return This is actual still an issue. > How can a zero return also have a greater than zero annualized return? This has been fixed Created attachment 178052 [details]
test file
The problem can be seen in the line for investment “B” in the “Investment Performance by Account (Customized)” report.
Created attachment 179708 [details] Screenshot showing the issue (see line B) (In reply to Jon from comment #2) > For the Dividends Reinvested situation: > Starting Balance transaction – 12/31/21 buy 8 shares at $100/share = $800 > Buy Value transaction – 3/22/22 buy 4 shares at $100/share = $400 > Dividends Reinvested transaction – 6/30/22 = 1.5 shares added at $100/share > Sell Value transaction – 12/2/22 sell 10 shares at $100/share = $1,000 > Ending Balance = $350 > > ($350 + $0 + $1,000) - ($800 + $400) = $150 Return > > $150 / ($800 + $400) = 0.125 * 100 = 12.5% For this case the The Investment > Performance By Account report shows an incorrect 0% return and strangely, a > 15.51% Annualized Return. How can a zero return also have a greater than > zero annualized return? (In reply to Ralf Habacker from comment #10) > The problem can be seen in the line for investment “B” in the “Investment Performance by Account (Customized)” report. line B isn't zero anymore, but does not match the expected return mentioned in comment 2. A possibly relevant merge request was started @ https://invent.kde.org/office/kmymoney/-/merge_requests/268 Git commit 10050df47680422bf98dd8311b6e87cc362926f5 by Ralf Habacker. Committed on 26/03/2025 at 19:06. Pushed by habacker into branch 'master'. Fix bug when calculating investment performance reports with reinvested dividends The reinvested dividends must not added to the buys as it is already included in the final market value. FIXED-IN:5.2 M +4 -2 kmymoney/plugins/views/reports/core/querytable.cpp M +2 -2 kmymoney/plugins/views/reports/core/tests/querytable-test.cpp https://invent.kde.org/office/kmymoney/-/commit/10050df47680422bf98dd8311b6e87cc362926f5 Git commit ebcb355c41a691bb5dfa01556e03883b4c4180f8 by Ralf Habacker. Committed on 26/03/2025 at 19:06. Pushed by habacker into branch 'master'. Adjust expected values in investment performance report After adding on additional column and fixing the incorrect return values the expected values in the unit tests must be adjusted. M +4 -4 kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Performance-by-Account-_Customized---from-period---one-year--start-later_.csv M +4 -4 kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Performance-by-Account-_Customized---from-period---one-year_.csv M +4 -4 kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Performance-by-Account-_Customized---from-period---three-year_.csv M +4 -4 kmymoney/plugins/views/reports/core/tests/data/test-investment-report-querytable-Investment-Performance-by-Account-_Customized---from-period---two-years_.csv https://invent.kde.org/office/kmymoney/-/commit/ebcb355c41a691bb5dfa01556e03883b4c4180f8 Git commit 070c74eca433e7d5bac964e73cc95b0d8acae1d5 by Ralf Habacker. Committed on 26/03/2025 at 19:06. Pushed by habacker into branch 'master'. Add column for return value in investment reports Outputting the return as a value increases the information content of the report. With the addition of this column, the order of the columns displaying returns in percent has been changed to obtain a more natural order. After the return in a currency comes the return in percent, followed by the annual return and the extended internal rate of return. M +3 -0 kmymoney/plugins/views/reports/core/listtable.cpp M +1 -0 kmymoney/plugins/views/reports/core/listtable.h M +50 -16 kmymoney/plugins/views/reports/core/querytable.cpp M +12 -0 kmymoney/plugins/views/reports/core/querytable.h M +3 -0 kmymoney/plugins/views/reports/core/tests/querytable-test.cpp https://invent.kde.org/office/kmymoney/-/commit/070c74eca433e7d5bac964e73cc95b0d8acae1d5 Git commit 74a01fa225516039e03a92dafaf9f0894e3ac797 by Ralf Habacker. Committed on 26/03/2025 at 19:06. Pushed by habacker into branch 'master'. Add additional unit tests for ROI calculations M +1 -0 kmymoney/plugins/views/reports/core/querytable.cpp M +38 -0 kmymoney/plugins/views/reports/core/tests/querytable-test.cpp https://invent.kde.org/office/kmymoney/-/commit/74a01fa225516039e03a92dafaf9f0894e3ac797 |