fix years calculation in cagr() and removing the "periods" parameter #74
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.
CAGR is an annualized rate, so the cagr() function should figure out how many years go by between the first and last of the returns that are input to the function. To do this, we just figure out the number of days elapsed and divide by 365.
The current code takes a periods parameter and does some funny math that produces wrong results because the frequency (daily, weekly, monthly) of the returns is irrelevant for this function.
This mistake is the cause of multiple open issues:
#26 (comment)
#30
#44
This request is to use a constant 365 to calculate the number of years in cagr and remove the periods parameter only from this function.
Description by Korbit AI
What change is being made?
Remove the "periods" parameter from the
cagr()
function and correct the years calculation logic by directly dividing the days by 365.Why are these changes being made?
The "periods" parameter was unnecessary and removing it simplifies the function; this modification ensures a consistent annualization period. Additionally, correcting the years calculation to always use 365 days mitigates potential calculation errors and aligns with common financial analysis practice.