Created
February 16, 2019 12:20
-
-
Save ccerv1/f6e8d48676f58567c4d4ba78031bd327 to your computer and use it in GitHub Desktop.
Creates a CAGR value (as a formatted string)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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