”n” in CAGR

Course Name: Technical Indicators Strategies in Python, Section No: 6, Unit No: 6, Unit type: Notebook

Can you please elaborate more on how "n" is calculated in the CAGR?

Hi Amit,

# Total number of trading candles per day
n = data.loc[datetime.datetime.strftime(data.index[-1].date(),'%Y-%m-%d')].shape[0]

# Total number of trading candles over time
trading_candles = len(data['Cumulative_Returns'])

# Calculate compound annual growth rate
performance_metrics['CAGR'] = "{0:.2f}%".format((data.Cumulative_Returns.iloc[-1]**(252*n/trading_candles)-1)*100)

The following are the steps that have been performed in the above block of code:

1. Calculate intraday frequency candles in a single day --> n

2. Calculate the total no of candles for the entire period --> trading_candles

3. Then we find the no. of years, 
You need to divide (candles for the entire period --> trading_candles) by the total candles in a year (252*n) 
This is because we assume 252 trading days in a year & n (intraday) candles daily 

So the equation for no. of years would be: trading_candles/252*n
    
4. In the formula for CAGR, we require 1/n (i.e. 1 / no. of years)
Hence, we use [1 / (1/(trading_candles/252*n)] = 252*n / trading_candles 
Since, the value of 1/(x/y) would be the same as (y/x))

I hope this clarifies your doubt.

thank you very much Kevin.