Bug 414932

Summary: Incorrect "opening balance" in daily and weekly "Investment Worth Graph"
Product: kmymoney Reporter: zoltan1980
Component: reportsAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 5.0.7   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.0.8
Attachments: KMY file to reproduce error
Incorrect daily report for 1 year
Incorrect weekly report for 1 year
Incorrect weekly report for 2 years
Correct monthly report for 1 year

Description zoltan1980 2019-12-07 21:07:50 UTC
Created attachment 124363 [details]
KMY file to reproduce error

SUMMARY

The "opening balance" of an "Investment Worth Graph" is calculated using the latest stock price instead of the stock price in effect at the start of the report period. Only daily and weekly charts are affected, monthly charts look correctly.

STEPS TO REPRODUCE
I created a file to demonstrate the problem. It has a single stock with a starting price of $1 as of Jan 1, 2000, and increasing by $1 every month. There is a single share of this stock bought in Jan 1, 2000 and no other investment transaction. Use the attached file and open the Investment Worth Graph report. You can also switch to the report view to observe incorrect numbers in a table.

OBSERVED RESULT

When ticks are set to be daily (the default) or weekly, the "opening balance" on the left of the chart shows a value calculated using the latest price (which in this test file is much higher than expected). This happens regardless of the time range: please see the attached screenshots that use a range of 1 year (the default) and 2 years. When the ticks are set to be monthly, the values are correct.

EXPECTED RESULT

The opening balance should be calculated using the price that was in effect at the start of the period.

ADDITIONAL INFORMATION

I created the test file and the screenshots using an older version (plus some manual scripting), but the bug is present in v5.0.7 as well.
Comment 1 zoltan1980 2019-12-07 21:09:41 UTC
Created attachment 124365 [details]
Incorrect daily report for 1 year
Comment 2 zoltan1980 2019-12-07 21:10:06 UTC
Created attachment 124366 [details]
Incorrect weekly report for 1 year
Comment 3 zoltan1980 2019-12-07 21:10:20 UTC
Created attachment 124367 [details]
Incorrect weekly report for 2 years
Comment 4 zoltan1980 2019-12-07 21:10:54 UTC
Created attachment 124368 [details]
Correct monthly report for 1 year
Comment 5 Thomas Baumgart 2020-01-11 09:04:32 UTC
Git commit 286c3aecb316ab79b5e7115b26a9fdd58f147298 by Thomas Baumgart.
Committed on 11/01/2020 at 09:04.
Pushed by tbaumgart into branch '5.0'.

Fix calculation of columnDate

The returned date of columnDate was not correct in certain circumstances
so that the price information using this date was incorrect which
resulted in false opening balance values in reports.
FIXED-IN: 5.0.8

M  +9    -3    kmymoney/plugins/views/reports/core/pivottable.cpp

https://commits.kde.org/kmymoney/286c3aecb316ab79b5e7115b26a9fdd58f147298
Comment 6 Thomas Baumgart 2020-01-11 09:16:09 UTC
Git commit 38ea8dc4603f6e263d8d986e901e8870e534134a by Thomas Baumgart.
Committed on 11/01/2020 at 09:15.
Pushed by tbaumgart into branch 'master'.

Fix calculation of columnDate

The returned date of columnDate was not correct in certain circumstances
so that the price information using this date was incorrect which
resulted in false opening balance values in reports.
FIXED-IN: 5.0.8
(cherry picked from commit 286c3aecb316ab79b5e7115b26a9fdd58f147298)

M  +9    -3    kmymoney/plugins/views/reports/core/pivottable.cpp

https://commits.kde.org/kmymoney/38ea8dc4603f6e263d8d986e901e8870e534134a