I have a DatetimeIndex indexed dataframe with two columns. The index is uneven.
A B
Date
2016-01-04 1 20
2016-01-12 2 10
2016-01-21 3 10
2016-01-25 2 20
2016-02-08 2 30
2016-02-15 1 20
2016-02-21 3 20
2016-02-25 2 20
I want to compute the dot product of time-series A and B over a rolling window of length 20 days.
It should return:
dot
Date
2016-01-04 Nan
2016-01-12 Nan
2016-01-21 Nan
2016-01-25 110
2016-02-08 130
2016-02-15 80
2016-02-21 140
2016-02-25 180
here is how this is obtained:
110 = 2*10+3*10+2*20 (product obtained in period from 2016-01-06 to 2016-01-25 included)
130 = 3*10+2*20+2*30 (product obtained in period from 2016-01-20 to 2016-02-08)
80 = 1*20+2*30 (product obtained in period from 2016-01-27 to 2016-02-15)
140 = 3*20+1*20+2*30 (product obtained in period from 2016-02-02 to 2016-02-21)
180 = 2*20+3*20+1*20+2*30 (product obtained in period from 2016-02-06 to 2016-02-25)
The dot product is an example that should be generalizable to any function taking two series and returning a value.