Skip to content

fix years calculation in cagr() and removing the "periods" parameter #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cantupaz
Copy link

@cantupaz cantupaz commented Apr 21, 2025

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.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link

korbit-ai bot commented Apr 21, 2025

Important

Required App Permission Update

Noise Reduction Improvements

This update requests write permissions for Commit Statuses in order to send updates directly to your PRs without adding comments that spam notifications. Visit our changelog to learn more.

Click here to accept the updated permissions

To accept the updated permissions, sufficient privileges are required

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've completed my review and didn't find any issues.

Files scanned
File Path Reviewed
quantstats_lumi/stats.py
quantstats_lumi/reports.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant