Home › Forums › kdb+ › rolling linear regression in q › Re: rolling linear regression in q
-
Wrapped them into function:
tabData:([]y:10?100.0;x1:10?10.0;x2:10?20.0;x3:10?30.0;const:1.0); main:{[n;y;xs;tab] rolling:{[w;t] (w-1)_({ 1_x,y }[w#delete from t;t])}; fn:{[t;Y;X] yx:enlist t[Y] mmu flip t[`const,X]; xx:x mmu flip[x:t[`const,X]];yx lsq xx}; fn[;y;xs] each rolling[n;tab] } betas:main[5;`y;`x1`x2`x3;tabData]