def least_square_lagged_regression(u_array):
"""
u_array, q, T+1, p
"""
q,T,p = u_array.shape
T -= 1
# t0, t1 term is t1 regressed on t0
lagged_coef_mat = np.zeros([T,T],dtype = np.object)
for t0 in range(T):
for t1 in range(t0,T):
tmp_coef = np.zeros([p,p])
for i in range(p):
# least square regression u_t+h[i] u_t
tmp_y = u_array[:,t1+1,i]
tmp_x = u_array[:,t0,:]
# (X'X)^{-1} X' Y
tmp_coef[i,:] = np.linalg.inv(tmp_x.T.dot(tmp_x)).dot(tmp_x.T.dot(tmp_y))
lagged_coef_mat[t0,t1] = tmp_coef
return lagged_coef_mat
评论列表
文章目录