Skip to content

Instantly share code, notes, and snippets.

@ccerv1
Created February 16, 2019 12:20
Show Gist options
  • Select an option

  • Save ccerv1/f6e8d48676f58567c4d4ba78031bd327 to your computer and use it in GitHub Desktop.

Select an option

Save ccerv1/f6e8d48676f58567c4d4ba78031bd327 to your computer and use it in GitHub Desktop.
Creates a CAGR value (as a formatted string)
def cagr(series):
start_val = series.iloc[0]
end_val = series.iloc[-1]
num_vals = len(series)
CAGR = (end_val/start_val)**(1/num_vals)-1
prefix = ''
if CAGR > 0:
prefix = '+'
return prefix + '{:.1%}'.format(CAGR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment