我尝试优化了以下函数,测试后发现性能可以提升:
def halfLifeW(half_life,window){i
Lambda = pow(0.5,1\half_life)
W = accumulate(mul{Lambda}, window-1, Lambda)
return reverse(W)
} def cneBeta(stock_ret,index_ret){ stock_ret_list = matrix(movingWindowData(stock_ret, 252, fixed=true)) index_ret_list = matrix(movingWindowData(index_ret, 252, fixed=true)) stock_ret_list=dropna(stock_ret_list) index_ret_list=dropna(index_ret_list) beta = peach(getWlsKey{63,`Coefficient,1,1}, stock_ret_list.transpose(), index_ret_list.transpose()) return beta }