Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Calculating CAGR Using USEquityPricing

From Investopedia, "The compound annual growth rate (CAGR) is the mean annual growth rate of an investment over a specified period of time longer than one year."

To calculate the CAGR of a security, you would use the following calculation.

a = 'starting value'  
b = 'current value'  
x = 'number of years'

((b / a) ^ (1 / x)) - 1

Currently, I am trying to figure out a way to efficiently calculate the CAGR of a group of securities filtered by fundamental data, and sort by CAGR from high to low. After browsing through the API and help documents, I am unsure of where/how to successfully pull the value of a security on a date three years ago for the CAGR calculation. I am sure this is simply a matter of lack of Python knowledge, but any assistance would be greatly appreciated.

References:

http://www.investopedia.com/terms/c/cagr.asp
http://www.investopedia.com/calculator/cagr.aspx

6 responses

Bumping for visibility.

Delman

Here's a notebook showing a custom factor to calculate CAGR. The window_length can be set to get whatever start date you wish.

The filter can be set to whatever fundamental filter you wish.

As a side note. If you are simply sorting a list by CAGR (and not using the actual value) you could also sort by simple returns (end/start) and get the same ordering. 'Returns' is a built in factor so you wouldn't need to create a custom one.

Hope this helps.

I was planning on using the 5-year CAGR as a pipeline filter to remove low-return securities. Would it be more efficient to do that using raw returns implemented the same way as the notebook?

I wouldn't worry about 'efficiency' unless you begin getting timeout errors. First worry about your algorithm doing what you want it to do and having clear understandable code.

'Return' and 'CAGR' are similar except that CAGR raises each Return to a constant power ( for 5 years this power is 1/5). This effectively weights higher Returns more (ie compounded growth). For ordering (eg 'top 5') this doesn't matter. However, for some calculations it does make a difference. Averages are one example. Below are four Returns (A, B, C, D), the associated 5 year CAGR, and the simple average of each. Notice that D is the only one with above average Returns, while both C and D have above average CAGR.

5 Yr Return 5 Yr CAGR  

A 1.000 1.000
B 1.100 1.019
C 1.250 1.046
D 1.700 1.112

    1.263   1.044  Average

With all that said, a basic decision to make is whether you wish to filter by an absolute or a relative Return/CAGR. Should one filter by 'stocks with a CAGR > .12' or 'stocks with the top 20 Returns' or maybe 'stocks with returns > the S&P500 Returns'. Take a look at the post https://www.quantopian.com/posts/alphalens-a-new-tool-for-analyzing-alpha-factors . Alphalens is a good tool to begin understanding if a particular factor or filter actually expresses some predictive value for future returns.

Hope that helps. Good luck.

Thank you for framing it in that perspective, I will definitely be checking Alphalens out.

Portfolio CAGR added to PvR tool. It is available as context.cagr
Appreciate having that tested by someone.