我得到了单变量时间序列建模(自回归模型)的过程。在这个过程中,我想使用 while 循环生成 100 个观察结果。
import numpy as np
np.random.seed(17)
T = 200
alpha1 = 0.8
alpha2 = 0.15
u = np.random.randn(T)
y = np.zeros (T)
for t in np.arange(2,200):
y[t] = alpha1*y[t-1] + alpha2*y[t-2] + u[t]
y = y[100:]
# Write a while loop which generates 100 observations from AR(2) defined above
# This is my first try. However, it seems that I am initiating an infinite loop for some reason. Does anybody have a suggestion on how to generate 100 observations from the process described above?
import numpy as np
np.random.seed(17)
T = 200
alpha1 = 0.8
alpha2 = 0.15
u = np.random.randn(T)
y = np.zeros (T)
t = 2
while t <=102 :
y[t] = alpha1*y[t-1] + alpha2*y[t-2] + u[t]
y = y[:]
print(y)
catspeake
相关分类