Course Name: Factor Investing: Concepts and Strategies, Section No: 9, Unit No: 3, Unit type: Notebook
Regarding CAGR calculation:
Total number of trading candles per day
candle_difference = returns.index.to_series().diff().mean().days
if candle_difference >= 1:
n = np.floor(candle_difference)
else:
n = returns.loc[datetime.datetime.strftime(
returns.index[-1].date(), ‘%Y-%m-%d’)].shape[0]
Total number of trading candles over time
trading_candles = len(returns[‘cumulative_returns’])
Calculate compound annual growth rate
performance_metrics[‘CAGR’] = “{0:.2f}%”.format(
(returns.cumulative_returns.iloc[-1] ** (252 * n / trading_candles) - 1) * 100)
print(performance_metrics[‘CAGR’])
For the line:
if candle_difference >= 1:
n = np.floor(candle_difference)
Should it be: n = 1/(np.floor(candle_difference)) instead?