My dataframe:
Date AAPL NFLX INTC AAPL_Ret NFLX_Ret INTC_Ret
0 2008-01-31 27.834286 3.764286 25.350000
1 2008-02-29 27.847143 3.724286 24.670000 -0.07 0.25 -0.05
2 2008-03-31 25.721428 3.515714 22.670000 0.15 0.10 0.06
3 2008-04-30 25.377142 3.554286 22.879999 etc
4 2008-05-31 24.464285 3.328571 22.260000
After resampling my original dataframe I calculated the returns for each stock (see above). Now I'd like to calculate (i) percentiles for the returns across stocks, i.e., going across the row (essentially comparing a stock to others) and not down the column, call that "Relative Percentile" say (ii) percentiles for each stock's own returns, going down the column, call that "Absolute Percentile"
I was shown how to select the _Ret columns to do the quantile calculation but am stuck at going from selecting the _Ret columns to create new columns with the relative quantile and absolute quantiles.
Have tried this:
df['Quantile'] = df[[col for col in df.columns if "_Ret" in col]].quantile(0.9)
But this returns a blank "Quantile" column in between AAPL_Ret and NFLX_Ret
How to do this? Thanks