I'm new to Python and just doodled around to get to know the language. Basically, I wanted produce random walks and have them analyzed. However, I was not able to accomplish a list of fit objects with different ARMA model fits for different random walk realizations.
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
def randwalk(N,sigma):
k=1
R=np.zeros(N)
while(k<N):
R[k]=R[k-1]+np.random.randn(1)*sigma
k+=1
return R
m=3
N=100
R1=np.zeros((N,m))
for k in range(m):
R1[:,k]=randwalk(N,0.1)
plt.plot(range(N),(R1))
plt.show()
ll= [(2,0),(2,0)]
fit=[]
for kk in range(len(ll)):
fit[kk]= [sm.tsa.ARMA(R1[:,ii], order=ll[kk]).fit() for ii in range(m)]
Neither fit[kk] nor fit[kk][:] seem to work. I have looked into Creating a list of objects in Python and Nested lists python
Later, ll[1] will be different, e.g. (2,1). sm.tsa.ARMA seems to work if you run the loop body with kk=0 "by hand".
Eventually, I would like to access fit[:][:].bic values.
I'm really sorry, i feel this is a basic syntax question...
I'm using Canopy on Windows 7.
Edit: Also,
ll= [(2,0),(2,0)]
fit=[]
for kk in range(len(ll)):
fit.append([sm.tsa.ARMA(R1[:,ii], order=ll[kk]).fit() for ii in range(m)])
doesn't work.