-
-
Notifications
You must be signed in to change notification settings - Fork 938
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 is not accurate - need to update to take the #317
Comments
i found this issue and submited a pull request to fix it some time ago, #281 you can pull from here if it works for you https://github.com/gnzsnz/quantstats-cagr/tree/cagr Regards |
Thank you very much for your help. But how I can use your updated version in spyder now? which code I have to use? Thank you very much |
I add this to my requirement.txt file
or like this on the command line
|
Thank you very much for your answer. Just a clarification. I have Anaconda and I use spyder. I can write ! pip install ... Etc directly in spyder? |
I have a problem with that: you are assuming daily market data. Is there anywhere in the quantstats docs that say that it only works with daily data? I do not think that the code should make that assumption. Instead, it should look at the actual time difference of the first and last indices (which should be checked to confirm that they are times and not something like str or int) and from that difference compute the effective number of days. |
Check out https://github.com/Lumiwealth/quantstats_lumi, which is being updated regularly. We are a fork of this library that is being maintained by Lumiwealth |
Discussed in #311
Originally posted by wpearce1 November 7, 2023
The current way to calculate CAGR is incorrect. The years component should be:
total_days = len(df.index)
years = total_days / 252.
it looks like the way it is currently configured it counting weekends in the numerator but not the denominator. this understates CAGR.
thanks
def cagr(returns, rf=0.0, compounded=True, periods=252):
"""
Calculates the communicative annualized growth return
(CAGR%) of access returns
Your "total_days = len(df.index)" and "years = total_days / 252" . Is correct. However, note that the number of days in the quantstats formula
years = (returns.index[-1] - returns.index[0]).days / periods is calculating a calendar number of days where len(df.index) is counting trading days. If you are counting calendar days, use 365. If counting trading days use 252.
The quantstats formula should use 365 unless it changes the method to use trading days vs calendar days. Both 252 and 365 are not quite the same for all years. It would probably be better to use 365.25 to account for leap years.
The text was updated successfully, but these errors were encountered: