I am doing this assignment where I am trying to run this program 5000 times and do an AR(1) and AR(2) fit to the model. First I defined a function that generated a time series as follows:
def ts_gen_ar1(size,sigma,alpha1):
wt = np.random.normal(0,sigma**2,size=size)
x = np.zeros(size)
for i in np.arange(1,size):
x[i] = 0.2 + alpha1*x[i-1] + wt[i]
return x
Then i executed the following statements thats taking extremely long time to work
sample_ar1 = []
sample_ar2 = []
for i in range(0,5000):
rt = ts_gen_ar1(2500,1,0.8)
coeff_ar1 = sm.tsa.ARMA(rt,order=(1,0)).fit().params[1]
coeff_ar2 = sm.tsa.ARMA(rt,order=(2,0)).fit().params[1:]
sample_ar1.append(coeff_ar1)
sample_ar2.append(coeff_ar2)
can someone suggest how to speed this up? I am also getting fitting errors where my program says MLE failed to converge for certain iterations.
Thanks