Moving correlation. Sliding window for dyadic function?

Dear all,

I am struggling to alter the following sliding window function to operate for dyadic functions.

swin:{[f;w;s] f each { 1_x,y }\[w#0;s]}

This only works for input functions that take one list as an argument; avg, max, min etc.

I would like to use a sliding window for functions like cor, lsq etc, which take 2 lists as input arguments. Does anyone know how to do this?

Faithfully,

Alexander

For dyadics, you will need to produce two series, below is one way to do it

q)f:{[f;w;s1;s2](f .)each{x('[_[1];,])'y,z}\[2#enlist w#0;s1;s2]}q)f[cor;3;29 10 54;1 3 9]1 0.1555428 0.7727746

Can also adjust swin2 simillarly

q)\ {x'/0^(y-1)('[;]/(+:;|:;:':\))'z}[cor;3;(29 10 54;1 3 9)]1 0.1555428 0.7727746q)q)swin2:{x'/[0^(y-1)('[;]/[(flip;reverse;prev\)])'z]}q)swin2[cor;3;(29 10 54;1 3 9)]1 0.1555428 0.7727746

Great. Thank you Ajay!!!