#statsmodels用于数据的统计建模分析
#此例为ADF平稳性检验的例子
from statsmodels.tsa.stattools import adfuller as ADF
import numpy as np
#np.random.rand返回100个服从【0,1)之间均匀分布的随机样本值
'''
statsmodels.tsa.stattools.adfuller(
x, maxlag=None, regression='c', autolag='AIC', store=False, regresults=False)[source]¶
x: 序列,一维数组
maxlag:差分次数
regresion:{c:只有常量,
ct:有常量项和趋势项,
ctt:有常量项、线性和二次趋势项,
nc:无任何选项}
autolag:{aic or bic: default, then the number of lags is chosen to minimize the corresponding information criterium,
None:use the maxlag,
t-stat:based choice of maxlag.
Starts with maxlag and drops a lag until the t-statistic on the last lag length is significant at the 95 % level.}
)'''
print(ADF(np.random.rand(100)))
结果为:(-11.132232301402519, 3.260491543071536e-20, 0, 99, {'1%': -3.498198082189098, '5%': -2.891208211860468, '10%': -2.5825959973472097}, 35.95266020626107)
-11.132232301402519<'1%'.val
原假设不成立,数据是平稳的。