[PYTHON] About CAGR

1. Purpose

Describe the CAGR and the code to calculate the CAGR.

2 Contents

2-1 CAGR formula

For the price of a stock, let S_0 be the stock price on the base date and S_n be the stock price n business days after the start date. At this time, CAGR (compound average growth rate) is calculated by the following formula.

CAGR = \biggl({\frac{S_n}{S_0}} \biggl)^{\frac{1}{years}}-1

However, years = n / (total number of trading days in one year).

2-2 What does CAGR mean?

CAGR (Compound Annual Growth Rate) is the geometric mean per year calculated from the growth rate over multiple years. For example, consider the average growth rate for three years when sales of 100 million yen grow to 160 million yen in three years. In response to this problem, 160 ÷ 100 = 1.6, that is, a 60% increase in three years, so the idea that the average annual growth rate is 60/3 = 20, which is 20%, is incorrect. In general business thinking, the compound annual growth rate is based on the idea of compound interest, and we have to find x such that 100 x (1 + x) x (1 + x) x (1 + x) = 160. Therefore, 3√1.6 = 1.1696 ... That is, 17.0% is the correct answer.

Source: https://mba.globis.ac.jp/about_mba/glossary/detail-11621.html

2-3 CAGR Code to calculate

test.py


#CAGR(Annual growth rate)To calculate
def CAGR(DF):
    df = DF.copy()
    df["daily_ret"] = DF["Close"].pct_change() #Calculate the rate of change from the day before the closing price of the stock price.
    df["cum_return"] = (1 + df["daily_ret"]).cumprod() #cumprod(Returns the cumulative product of all elements in a scalar y.
    n = len(df)/252
    CAGR = (df["cum_return"][-1])**(1/n) - 1
    return CAGR

Recommended Posts

About CAGR
About LangID
About virtiofs
About python-apt
About Permission
About sklearn.preprocessing.Imputer
About gunicorn
About requirements.txt
About locale
About permissions
About Opencv ②
About axis = 0, axis = 1
About Opencv ③
About import
About numpy
About pip
About Linux
About numpy.newaxis
About endian
About Linux
About import
About Opencv ①
About Linux
About Linux
About Linux ①
About cv2.imread
About _ and __
About wxPython
About python slices
About python comprehension
About Docker Volume
[Linux] About export
About reference type
About Twitter scraping
About the test
Learn about programming
About Flask customization
About variable scope. .. ..
About Python tqdm.
About python yield
Notes about with
About python, class
About Linear Models
About Go functions
About pandas describe
About Kivy root
About Firestore timeout
About python inheritance
About python, range ()
About Confusion Matrix
[Linux] About PATH
About python decorators
Linux (about groups)
Note about awk
About python reference
About Bitnami Autostart
About Python decorators
About Milkcocoa SDK
Notes about pytorch
[Python] About multi-process
About Numpy broadcast