我(非常)是python的新手,以前是Matlab用户。
我尝试创建代码以将时间序列加载到矩阵[serie1,2,3等]的行中,然后将这些时间序列操作为循环(请参阅下面的代码)。 我的问题有三个(下面有3个循环):
1 - 如何创建一个循环来逐个填充数组的行。 2 - 填充一个三维数组的东西我计算这些时间序列(相关系数) 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