Open TraderMikeS opened 7 months ago
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
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
quantstats @ git+https://github.com/gnzsnz/quantstats-cagr.git@cagr
or like this on the command line
pip install git+https://github.com/gnzsnz/quantstats-cagr.git@cagr
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?
total_days = len(df.index)
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.
Discussed in https://github.com/ranaroussi/quantstats/discussions/311
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.