Pieces

[Python] CAGR calculate function

문득 생각이 나서 파이썬으로 계산해보는 CAGR(연평균복합성장률)

- 여러 해 동안의 성장률을 기하평균으로 계산(산술로 계산하면 결과가 왜곡됨) 

- 공식은 ((최종 value) / (최초 value)의 (1/N) 제곱 - 1). 여기서 N은 연수. 이를 백분율로 환산하면 CAGR이 된다. 

 

CAGR formula

 

파이썬으로 작성하면 아래와 같다.

심히 간단하다. 

def CAGR(beginning, ending, numberofyears):
    """
    beginning = 최초의 값
    ending = 최종의 값
    numberofyears = 연수
    """
    cagr = (ending/beginning)**(1/numberofyears) - 1
    return print("CAGR : {:.2%}".format(cagr))

 

 


이미지 출처 : CAGR Formula (from wallstreetmojo.com)

 

CAGR Formula

Formula to Calculate CAGR (Compounded Annual Growth Rate) CAGR (Compounded Annual Growth Rate) refers to the rate of return that is achieved by an

www.wallstreetmojo.com