quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

Issue with cagr function in stats

Open lemming78 opened this issue 1 year ago • 2 comments

I believe there is a mistake in the code when the return series is monthly.

I had to amend the periods argument to 365 to get a cagr figure that made sense. I can't help further, i'm not a python developer but was looking to help on this.

def cagr(returns, rf=0.0, compounded=True, periods=365):
    """
    Calculates the communicative annualized growth return
    (CAGR%) of access returns

Could you kindly implement a fix? Total return is fine instead.

lemming78 avatar Jun 18 '24 09:06 lemming78

Hey the reason they differ is because the utils_cagr function is incorrectly counting calendar days instead of trading days when identifying the annualization period.

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

this method will unfortunately count calendar days, when in reality it would be more accurate to count the length of the returns object.

hopefully they fix this, I had to do this locally as I was getting incorrect CAGR's.

jakewillms17 avatar Jun 20 '24 13:06 jakewillms17

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

grzesir avatar Jul 30 '24 06:07 grzesir