import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.tsa.stattools as ts
data.columns=['date','open','high','low','close','amt','opi']
x = np.array(np.log(data['close']))
result = ts.adfuller(x, 1,regresults=True) # maxlag is now set to 1
print(result)

#结果：

(-1.0159755159305488, 0.74739309585919544, {'1%': -3.4336805486772994, '10%': -2.5675532292926859, '5%': -2.8630112431183181},
<statsmodels.tsa.stattools.ResultsStore object at 0x0A9C3CD0>)

#以上计算的价格的对数的单位根检验，检验结果不显著，存在单位根。但是计算每天对数收益率的时候，这个是不存在单位根的。

adfuller(x, maxlag=None, regression='c', autolag='AIC', store=False, regresults=False)
Augmented Dickey-Fuller unit root test
The Augmented Dickey-Fuller test can be used to test for a unit root in a
univariate process in the presence of serial correlation.
Parameters
----------
x : array_like, 1d
data series
maxlag : int
Maximum lag which is included in test, default 12*(nobs/100)^{1/4}
regression : str {'c','ct','ctt','nc'}
Constant and trend order to include in regression
* 'c' : constant only (default)
* 'ct' : constant and trend
* 'ctt' : constant, and linear and quadratic trend
* 'nc' : no constant, no trend
autolag : {'AIC', 'BIC', 't-stat', None}
* if None, then maxlag lags are used
* if 'AIC' (default) or 'BIC', then the number of lags is chosen
to minimize the corresponding information criterium
* '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.
store : bool
If True, then a result instance is returned additionally to
the adf statistic (default is False)
regresults : bool
If True, the full regression results are returned (default is False)
Returns
-------
Test statistic
pvalue : float
MacKinnon's approximate p-value based on MacKinnon (1994)
usedlag : int
Number of lags used.
nobs : int
Number of observations used for the ADF regression and calculation of
the critical values.
critical values : dict
Critical values for the test statistic at the 1 %, 5 %, and 10 %
levels. Based on MacKinnon (2010)
icbest : float
The maximized information criterion if autolag is not None.
regresults : RegressionResults instance
The
resstore : (optional) instance of ResultStore
an instance of a dummy class with results attached as attributes
Notes
-----
The null hypothesis of the Augmented Dickey-Fuller is that there is a unit
root, with the alternative that there is no unit root. If the pvalue is
above a critical size, then we cannot reject that there is a unit root.
The p-values are obtained through regression surface approximation from
MacKinnon 1994, but using the updated 2010 tables.
If the p-value is close to significant, then the critical values should be
used to judge whether to accept or reject the null.
The autolag option and maxlag for it are described in Greene.
Examples
--------
see example script
References
----------
Greene
Hamilton
P-Values (regression surface approximation)
MacKinnon, J.G. 1994.  "Approximate asymptotic distribution functions for
unit-root and cointegration tests.  Journal of Business and Economic
Statistics 12, 167-76.
Critical values
MacKinnon, J.G. 2010. "Critical Values for Cointegration Tests."  Queen's
University, Dept of Economics, Working Papers.  Available at
http://ideas.repec.org/p/qed/wpaper/1227.html

|
2月前
|

R语言在员工上网行为监控中的数据分析

262 3
|
2月前
|

R语言对综合社会调查GSS数据进行自举法bootstrap统计推断、假设检验、探索性数据分析可视化|数据分享（上）
R语言对综合社会调查GSS数据进行自举法bootstrap统计推断、假设检验、探索性数据分析可视化|数据分享
41 0
|
26天前
|

《谁说菜鸟不会数据分析（SPSS篇）》面向职场新人，以轻松方式讲解SPSS在数据分析中的应用，涵盖统计描述、推断和探索性分析，避开复杂术语，适合产品运营、市场、金融等领域从业者提升效率。[PDF下载](https://zhangfeidezhu.com/?p=339)
22 0
|
2月前
|

R语言中的神经网络预测时间序列：多层感知器（MLP）和极限学习机（ELM）数据分析报告
R语言中的神经网络预测时间序列：多层感知器（MLP）和极限学习机（ELM）数据分析报告
36 3
|
2月前
|

R语言Stan贝叶斯回归置信区间后验分布可视化模型检验|附数据代码
R语言Stan贝叶斯回归置信区间后验分布可视化模型检验|附数据代码
214 1
|
2月前
|

R语言大学城咖啡店消费问卷调查数据报告：信度分析、主成分分析可视化
R语言大学城咖啡店消费问卷调查数据报告：信度分析、主成分分析可视化
30 1
|
2月前
|

R语言电影数据分析：随机森林探索电影受欢迎程度因素、参数调优可视化
R语言电影数据分析：随机森林探索电影受欢迎程度因素、参数调优可视化
44 1
|
2月前
|

R语言汇率、股价指数与GARCH模型分析：格兰杰因果检验、脉冲响应与预测可视化
R语言汇率、股价指数与GARCH模型分析：格兰杰因果检验、脉冲响应与预测可视化
24 0
|
2月前
|

43 0
|
2月前
|

R语言用逻辑回归预测BRFSS中风数据、方差分析anova、ROC曲线AUC、可视化探索
R语言用逻辑回归预测BRFSS中风数据、方差分析anova、ROC曲线AUC、可视化探索
30 0