I am trying to calculate the rolling correlation between two xarray dataarrays.
Suppose my dataset is:
<xarray.Dataset>
Dimensions: (date: 2621, x: 100)
Coordinates:
* date (date) datetime64[ns] 2007-01-03 2007-01-04 ...
* x (x) int64 1 2 3 4 5 6 ...
Data variables:
a (date) float64 -0.001011 0.001227 -0.006087 0.002535 ...
b (date, x) float64 -0.001007 -0.0001312 -0.02594 ...
I would like to compute the rolling coefficients between a and b so that the dimensions of each coefficient is (date, x). Note that the date dimension is present because the rolling is applied along the date axis.
I was able to put together and ugly way to do this full of for loops but was wondering if there is a way to do it by somehow applying the reduce function on the rolling dataset object. I can't see a way to do it but there may be an entirely different approach I am missing.
This problem can be generalized by applying any arbitrary function that takes two series of numbers as inputs (in this case the correlation function.