I have a list of 10 stocks differentiated by PERMNO. I would like to group those stocks by PERMNO and calculate the rolling correlation between the stock return (RET) for ea
I found an efficient solution. Fairly simple.
def roll_corr_groupby(x,i): x['Z'] = rolling_corr(x['col 1'], x['col 2'],i) return x x.groupby(['key']).apply(roll_corr_groupby) x.head()