我是(非常)python 新手,以前是 Matlab 用户。
我尝试创建代码以将时间序列加载到矩阵 [serie1、2、3 等] 的行中,然后将这些时间序列操作到一个循环中(参见下面的代码)。我的问题是三重的(下面有 3 个循环):
1-如何创建一个循环来一一填充数组的行。2-用我计算出的那些时间序列(相关系数)填充一个 3d 数组 3-计算每个时间段下三角矩阵的平均相关性
我做错了什么?
非常感谢你的帮助!
i=0
while i<length(fx_tech):
for f in fx_tech:
time_series[:,i]= (LoadSeries(f[2],'7','fx','0',(ts.now('Y')-20).asfreq('B'),ts.now('B')-1,'0','0','B'))
i=1+i
#i want to populate a matrix with all series, fx_tech is a list of series i have
#to feed through the "loadseries" command. I know the first set of loops is wrong.
#then loop over each series pair and populate the matrix "corr"
corr = zeros((len(time_series)-1,len(fx_tech),len(fx_tech))) #allocate matrix
i=0
j=0
while i < len(fx_tech):
while j < len(fx_tech):
corr[:,i,j] = gencorrelation(time_series[:,i],time_series[:,j],lambda1)
j=1+j
i=1+i
#finally calculate the average of the elements below the diagonal for each time period.
mean_fx = []
i=0
while i < len(time_series)-1:
diag[:,:] = corr[i,:,:]-eye(len(fx_tech))
mean_fx.append = sum(diag)/((len(fx_tech)**2)/2-len(fx_tech))
i=1+i