I looked at similar answers but could not find one that suits my problem.
I have a daily covariance matrix that is constructed as a MultiIndex. It has "k" dates, and for each date "k" it has a matrix of size "n" by "n". The dimensions are technically (k, n, n) but as this is a MultiIndex pandas views this as shape (kxn, n).
As a minimum working example, I can provide the below:
dates = pd.date_range(start='20120101', end='20210101', freq='D')
X = pd.DataFrame( {'A' : np.random.rand(len(dates)), 'B' : np.random.rand(len(dates)), 'C' : np.random.rand(len(dates)), 'D' : np.random.rand(len(dates)), 'E' : np.random.rand(len(dates)) }, index=dates).ewm(halflife=30, min_periods=1).cov()
I would like to resample it from daily to minutely. Assuming my MultiIndex covariance matrix is called "X", I have managed to get the following to work:
X.unstack().resample("T").first().ffill().stack()
However, this takes an awfully long time to compute. Is there a faster and more efficient way to perform this operation?
This used to be quick with Panels that were deprecated after pandas 0.24. From my own profiling work the most memory intensive part seems to be the 'stack()'