spss、R语言、Python数据分析系列(7):python-adf单位根检验

简介: spss、R语言、Python数据分析系列(7):python-adf单位根检验
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.tsa.stattools as ts
data=pd.read_csv('C:/Users/HXWD/Desktop/数据/rb.csv',encoding='gbk')
data.columns=['date','open','high','low','close','amt','opi']
data.head()
np.log(data['close']).head()
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
    -------
    adf : float
        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月前
|
数据采集 数据可视化 数据挖掘
Python数据分析实战:Pandas处理结构化数据的核心技巧
在数据驱动时代,结构化数据是分析决策的基础。Python的Pandas库凭借其高效的数据结构和丰富的功能,成为处理结构化数据的利器。本文通过真实场景和代码示例,讲解Pandas的核心操作,包括数据加载、清洗、转换、分析与性能优化,帮助你从数据中提取有价值的洞察,提升数据处理效率。
142 3
|
15天前
|
数据可视化 大数据 关系型数据库
基于python大数据技术的医疗数据分析与研究
在数字化时代,医疗数据呈爆炸式增长,涵盖患者信息、检查指标、生活方式等。大数据技术助力疾病预测、资源优化与智慧医疗发展,结合Python、MySQL与B/S架构,推动医疗系统高效实现。
|
4月前
|
数据采集 数据可视化 搜索推荐
Python数据分析全流程指南:从数据采集到可视化呈现的实战解析
在数字化转型中,数据分析成为企业决策核心,而Python凭借其强大生态和简洁语法成为首选工具。本文通过实战案例详解数据分析全流程,涵盖数据采集、清洗、探索、建模、可视化及自动化部署,帮助读者掌握从数据到业务价值的完整技能链。
509 0
|
2月前
|
数据可视化 数据挖掘 大数据
基于python大数据的水文数据分析可视化系统
本研究针对水文数据分析中的整合难、分析单一和可视化不足等问题,提出构建基于Python的水文数据分析可视化系统。通过整合多源数据,结合大数据、云计算与人工智能技术,实现水文数据的高效处理、深度挖掘与直观展示,为水资源管理、防洪减灾和生态保护提供科学决策支持,具有重要的应用价值和社会意义。
|
3月前
|
存储 数据挖掘 大数据
基于python大数据的用户行为数据分析系统
本系统基于Python大数据技术,深入研究用户行为数据分析,结合Pandas、NumPy等工具提升数据处理效率,利用B/S架构与MySQL数据库实现高效存储与访问。研究涵盖技术背景、学术与商业意义、国内外研究现状及PyCharm、Python语言等关键技术,助力企业精准营销与产品优化,具有广泛的应用前景与社会价值。
|
数据采集 机器学习/深度学习 数据可视化
R语言从数据到决策:R语言在商业分析中的实践
【9月更文挑战第1天】R语言在商业分析中的应用广泛而深入,从数据收集、预处理、分析到预测模型构建和决策支持,R语言都提供了强大的工具和功能。通过学习和掌握R语言在商业分析中的实践应用,我们可以更好地利用数据驱动企业决策,提升企业的竞争力和盈利能力。未来,随着大数据和人工智能技术的不断发展,R语言在商业分析领域的应用将更加广泛和深入,为企业带来更多的机遇和挑战。
|
8月前
|
数据采集 机器学习/深度学习 数据可视化
探索大数据分析的无限可能:R语言的应用与实践
探索大数据分析的无限可能:R语言的应用与实践
294 9
|
数据可视化 数据挖掘 API
【R语言实战】聚类分析及可视化
【R语言实战】聚类分析及可视化
|
机器学习/深度学习 数据可视化
R语言逻辑回归logistic模型ROC曲线可视化分析2例:麻醉剂用量影响、汽车购买行为2
R语言逻辑回归logistic模型ROC曲线可视化分析2例:麻醉剂用量影响、汽车购买行为
|
数据挖掘 C语言 C++
R语言是一种强大的统计分析工具,提供了丰富的函数和包用于时间序列分析。
【10月更文挑战第21天】时间序列分析是一种重要的数据分析方法,广泛应用于经济学、金融学、气象学、生态学等领域。R语言是一种强大的统计分析工具,提供了丰富的函数和包用于时间序列分析。本文将介绍使用R语言进行时间序列分析的基本概念、方法和实例,帮助读者掌握R语言在时间序列分析中的应用。
278 3

推荐镜像

更多