Skip to content
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

CAGR % Calculation in reports.html #275

Open
glformanek opened this issue Jul 10, 2023 · 7 comments
Open

CAGR % Calculation in reports.html #275

glformanek opened this issue Jul 10, 2023 · 7 comments

Comments

@glformanek
Copy link

The call to calculate the CAGR should allow you to use the periods_per_year in the calculation or use a different way to compute it. The CAGR formula is:
CAGR = (((Ending Value / Beginning Value) ^ (1 / # of years)) - 1) * 100

​The # of years could be calculated by taking the ending date - beginning date which gives you the days. Then divide the days by 365 to get the years.

Some references:
https://www.investopedia.com/terms/c/cagr.asp#:~:text=To%20calculate%20the%20CAGR%20of,one%20from%20the%20subsequent%20result
https://seekingalpha.com/article/4516791-compound-annual-growth-rate-cagr#cagr-formula

This is the statement that does the calculation and seems to be incorrect (I think it should use 365):
metrics["CAGR﹪%"] = _stats.cagr(df, rf, compounded) * pct

Just briefly looking, it could be done by hard coding 365 or perhaps using the below change:
metrics["CAGR﹪%"] = _stats.cagr(df, rf, compounded, periods=periods_per_year) * pct

@glformanek
Copy link
Author

Another possible fix would be to have the cagr funtion default to periods=365. This would line up with the references noted above. This would also be a simple change.

@gnzsnz
Copy link

gnzsnz commented Jul 15, 2023

this looks like a duplicate of 273

@glformanek what would be the rational for having periods=365?

I have fixed the issue on my local repository by simply removing the periods parameters. periods is only used to calculate the number of years.

years = (returns.index[-1] - returns.index[0]).days / periods

The thing is that i cant think of a case that requires periods different than 365.

this piece of code (returns.index[-1] - returns.index[0]).days will always returns days (unless the index is not in date format, which will just fail) and once you have this in days the only thing that will work to calculate CAGR is 365. But i might be missing something.

@glformanek
Copy link
Author

glformanek commented Jul 15, 2023 via email

@gnzsnz
Copy link

gnzsnz commented Jul 15, 2023

i checked the code, and cagr is never called using period parameter. so the proposed fix should not break anything.

we could leave the parameter, but to be honest i think it will only create confusion. i have submitted a pull request to @ranaroussi

@glformanek
Copy link
Author

glformanek commented Jul 15, 2023 via email

@rajnishb
Copy link

Moving from 252 to 365 will also fix annual volatility and many other calculations. It's plain wrong as of today and is misleading

@cammclean182
Copy link

Just started playing around with quantstats and ran into this issue when running over past work to compare the output.

Somewhat agree with everything above, but wanted to add, think we should make it 365.25 by default.

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

No branches or pull requests

4 participants