def compute(self, today, assets, out, close):
# prepare X matrix (x_is - x_bar)
X = range(self.window_length)
X_bar = np.nanmean(X)
X_vector = X - X_bar
X_matrix = np.tile(X_vector, (len(close.T), 1)).T
# prepare Y vectors (y_is - y_bar)
Y_bar = np.nanmean(close, axis=0)
Y_bars = np.tile(Y_bar, (self.window_length, 1))
Y_matrix = close - Y_bars
# multiply X matrix an Y matrix and sum (dot product)
# then divide by variance of X
# this gives the MLE of Beta
betas = (np.sum((X_matrix * Y_matrix), axis=0) / X_var) / (self.window_length)
# prepare variance of X
X_var = np.nanvar(X)
# now use to get to MLE of alpha
out[:] = Y_bar - (betas * X_bar)
quanta_lib.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录