roi: better debug, faster and fixes calculation on dates that have just P update (fixes #2298) #2300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #2298
On days that has just price (P) directives we need to update internal TWR unit cost accordingly (and we were not doing this).
However, simply pretending that every day with P directive has a zero-value cashflow is suboptimal for people who has lots of P directives and few actual investment-related transactions.
So TWR code was rewritten to ditch the old pre-new-valuation-framework code and do the Proper Thing that better lines up with canonical way to compute TWR, by splitting the reporting inteval into subperiod on every cashflow, valuing investment immediately after each one, and computing the geometric mean of all subperiod returns, adjusted for cashflows.
This should do valuations on every cashflow date + two more for start and end of reporting period (actually this last bit is not new and is happening already).
Small variations in tests is due to the code now doing valuation consistently for all casflows/cashflow dates, which was not being done before.