i am looking for a way to reduce the time calculation of multiple functions calculations on a pandas dataframe ie i am trying to do (a reduce version of what i am trying to do…in the original version there are more functions).
It takes more than 2 minutes on my computer.
tab = (
fund_price
.sort_index()
.apply([
# Date de première/dernière VL
lambda x: x.first_valid_index().date(),
lambda x: x.last_valid_index().date(),
# Mesure de performance
## Perf total
lambda x: 100*cagr(x[-52:].pct_change(), period='weekly') if x[-52:].isnull().sum() <= 1 else np.nan,
lambda x: 100*cagr(x[-3*52:].pct_change(), period='weekly'),
lambda x: 100*cagr(x[-5*52:].pct_change(), period='weekly')
],)
.set_axis([
'Date de début', 'Date de fin',
'Perf 1 an', 'Perf 3 ans', 'Perf 5 ans',])
.T)