arma.py 637 字节
Newer Older
F
feilong 已提交
1
# -*- coding: UTF-8 -*-
F
feilong 已提交
2
# 作者:huanhuilong
F
feilong 已提交
3 4 5 6 7 8 9 10
# 标题:Python 时间序列分析
# 描述:ARMA模型

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.tsa.arima_process import ArmaProcess

F
feilong 已提交
11

F
feilong 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24
def test():
    # build a list MA parameters
    ma = [0.8 ** i for i in range(30)]

    # Simulate the MA(30) model
    ar = np.array([1])
    AR_object = ArmaProcess(ar, ma)
    simulated_data = AR_object.generate_sample(nsample=5000)

    # Plot the ACF
    plot_acf(simulated_data, lags=30)
    plt.savefig('/tmp/arma_acf.png')

F
feilong 已提交
25

F
feilong 已提交
26
if __name__ == '__main__':
F
feilong 已提交
27
    test()