ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.59k stars 809 forks source link

changed CAGR default preiods to 365 from 252 #302

Open yarimiz opened 10 months ago

yarimiz commented 10 months ago

When calculating CAGR, you are using calendar year of 365 days (see https://www.investopedia.com/terms/c/cagr.asp#:~:text=To%20calculate%20the%20CAGR%20of,one%20from%20the%20subsequent%20result.)

Using 252 periods is wrong and will produce misleading CAGR.

For a simple example: Say the between 2022-01-01 and 2022-12-31, I turned $100 to $200. My return is 100% and my CAGR is 100% Using 252 periods, my CAGR would be 61.83%, which is totally wrong.

gnzsnz commented 10 months ago

this is a duplicate with PR 281

unfortunately i haven't had an answer from the maintainers. I'm currently installing quantstats from my fork

pip install git+https://github.com/gnzsnz/quantstats-cagr.git@cagr

not ideal.....

PauloTupi10 commented 9 months ago

I agree. Use 365 days right the wrong.

alex-muci commented 7 months ago

A quick patch, whilst we wait for the maintener to merge the PR, can be inserting the following lines after your import statements (incl. "import quantstats as qs"), which is probably better/faster than installing some forks:

qs_cagr = qs.stats.cagr
def temp_cagr(returns, rf=0.0, compounded=True, periods=365):
    return qs_cagr(returns, rf, compounded, periods)
qs.stats.cagr = temp_cagr
grzesir commented 5 months ago

Since this library no longer seems to be maintained, we have created a duplicate of it that we plan to maintain and improve over time. If you'd like to use our version check it out here: https://github.com/Lumiwealth/quantstats_lumi

Please feel free to fork and send your pull request to this new library, we will be actively monitoring the library and approving PRs