-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass4_1.py
More file actions
77 lines (61 loc) · 1.82 KB
/
Copy pathclass4_1.py
File metadata and controls
77 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'''
Created on 4 de set de 2019
@author: gusta
'''
# lib to use the acf and pcf correlations
from statsmodels.graphics.tsaplots import plot_pacf
# lib to import the arma methods
from statsmodels.tsa.arima_process import ArmaProcess
# lib to plot the data
import matplotlib.pyplot as plt
# to deal with numbers
import numpy as np
np.random.seed(0)
######################## simulating a model AR(1) ################################
#X_{t} = -1*x_{t-1} + z_{t}
# defining model parameters
ar = np.array([1, -1])
ma = np.array([1])
model = ArmaProcess(ar, ma)
# generating the new serie
serie = model.generate_sample(nsample=1000)
# plotting the serie
plt.plot(serie)
plt.show()
# to use the pacf
plot_pacf(serie, lags=10)
plt.show()
##################################################################################
######################## simulating a model ARMA(0,2) ############################
#X_{t} = 0.3*z_{t-1} + 0.7*z_{t-2}
# defining model parameters
ar = np.array([1])
ma = np.array([1, 0.3, 0.7])
model = ArmaProcess(ar, ma)
# generating the new serie
serie = model.generate_sample(nsample=1000)
# analyzing the series generated
print(model.isinvertible)
print(model.isstationary)
# plotting
plt.plot(serie)
plt.show()
# to use the pacf
plot_pacf(serie, lags=10)
plt.show()
#################################################################################
######################## simulating a model ARMA(2,2) ############################
#X_{t} = -1*x_{t-1} + 0.3*z_{t-1} + 0.7*z_{t-2}
# defining model parameters
ar = np.array([1, -1])
ma = np.array([1, 0.3, 0.7])
model = ArmaProcess(ar, ma)
# generating the new serie
serie = model.generate_sample(nsample=1000)
# plotting
plt.plot(serie)
plt.show()
# to use the pacf
plot_pacf(serie, lags=10)
plt.show()
#################################################################################