时间序列分析---AR(1)

AR(1):
x t = x t 1 + ε t x_t=x_{t-1}+\varepsilon_t

x 0 = 0 ε t i i d N ( 0 , 1 ) x_0=0,\varepsilon_t\sim iid\,N(0,1)

Python Code:

import numpy as np
import matplotlib.pyplot as plt

%matplotlib auto

num = 500
np.random.seed(1000)
epsilon1 = np.random.normal(0,1,num)
epsilon2 = np.random.normal(0,1,num)
epsilon3 = np.random.normal(0,1,num)

x1 = np.empty(num)
x2 = np.empty(num)
x3 = np.empty(num)

t=np.linspace(1,500,500)
rho = 1
x1[0] = 0
for i in range(1,num):
    x1[i] = rho*x1[i-1]+epsilon1[i]

x2[0] = 0
for i in range(1,num):
    x2[i] = rho*x2[i-1]+epsilon2[i]

x3[0] = 0
for i in range(1,num):
    x3[i] = rho*x3[i-1]+epsilon3[i]
    
plt.plot(t,x1)
plt.plot(t,x2)
plt.plot(t,x3)

plt.show()

The following figure gives 3 realizations (sample paths) of the model.
Result:
在这里插入图片描述

发布了56 篇原创文章 · 获赞 4 · 访问量 8323

猜你喜欢

转载自blog.csdn.net/qq_45669448/article/details/104583509