在这个场景中,主要是通过高阶函数each对应每一个数据来计算残差:t=table(2020.11.01 2020.11.02 as date, `IBM`MSFT as ticker, 1.0 2 as past1, 2.0 2.5 as past3, 3.5 7 as past5, 4.2 2.4 as past10, 5.0 3.7 as past20, 5.5 6.2 as past30, 7.0 8.0 as past60); mt = matrix(t[`past1`past3`past5`past10`past20`past30`past60]).transpose(); benchX = 10 15 7 8 9 1 2.0; t[`residual] = each(def(y, x){ return ols(y, x, true, 2).ANOVA.SS[1]}{,benchX}, mt)
在这个场景中,主要是通过高阶函数each对应每一个数据来计算残差: