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
目录
相关文章
|
1月前
|
数据采集 数据可视化 数据挖掘
数据分析大神养成记:Python+Pandas+Matplotlib助你飞跃!
在数字化时代,数据分析至关重要,而Python凭借其强大的数据处理能力和丰富的库支持,已成为该领域的首选工具。Python作为基石,提供简洁语法和全面功能,适用于从数据预处理到高级分析的各种任务。Pandas库则像是神兵利器,其DataFrame结构让表格型数据的处理变得简单高效,支持数据的增删改查及复杂变换。配合Matplotlib这一数据可视化的魔法棒,能以直观图表展现数据分析结果。掌握这三大神器,你也能成为数据分析领域的高手!
44 2
|
1月前
|
机器学习/深度学习 数据采集 数据可视化
基于爬虫和机器学习的招聘数据分析与可视化系统,python django框架,前端bootstrap,机器学习有八种带有可视化大屏和后台
本文介绍了一个基于Python Django框架和Bootstrap前端技术,集成了机器学习算法和数据可视化的招聘数据分析与可视化系统,该系统通过爬虫技术获取职位信息,并使用多种机器学习模型进行薪资预测、职位匹配和趋势分析,提供了一个直观的可视化大屏和后台管理系统,以优化招聘策略并提升决策质量。
|
1月前
|
机器学习/深度学习 算法 数据挖掘
2023 年第二届钉钉杯大学生大数据挑战赛初赛 初赛 A:智能手机用户监测数据分析 问题二分类与回归问题Python代码分析
本文介绍了2023年第二届钉钉杯大学生大数据挑战赛初赛A题的Python代码分析,涉及智能手机用户监测数据分析中的聚类分析和APP使用情况的分类与回归问题。
52 0
2023 年第二届钉钉杯大学生大数据挑战赛初赛 初赛 A:智能手机用户监测数据分析 问题二分类与回归问题Python代码分析
|
18天前
|
数据采集 数据可视化 数据挖掘
数据分析大神养成记:Python+Pandas+Matplotlib助你飞跃!
【9月更文挑战第2天】数据分析大神养成记:Python+Pandas+Matplotlib助你飞跃!
44 5
|
1月前
|
自然语言处理 算法 数据挖掘
基于python豆瓣电影评论的情感分析和聚类分析,聚类分析有手肘法进行检验,情感分析用snownlp
本文介绍了一个基于Python的情感分析和聚类分析项目,使用snownlp库对豆瓣电影评论进行情感分析,并采用手肘法辅助K-means算法进行聚类分析,以探索评论中的不同主题和情感集群。
基于python豆瓣电影评论的情感分析和聚类分析,聚类分析有手肘法进行检验,情感分析用snownlp
|
1月前
|
供应链 数据可视化 数据挖掘
【2023年第十一届泰迪杯数据挖掘挑战赛】B题:产品订单的数据分析与需求预测 建模及python代码详解 问题一
本文详细介绍了第十一届泰迪杯数据挖掘挑战赛B题的解决方案,涵盖了对产品订单数据的深入分析、多种因素对需求量影响的探讨,并建立了数学模型进行未来需求量的预测,同时提供了Python代码实现和结果可视化的方法。
70 3
【2023年第十一届泰迪杯数据挖掘挑战赛】B题:产品订单的数据分析与需求预测 建模及python代码详解 问题一
|
1月前
|
机器学习/深度学习 数据采集 数据挖掘
【2023年第十一届泰迪杯数据挖掘挑战赛】B题:产品订单的数据分析与需求预测 建模及python代码详解 问题二
本文提供了第十一届泰迪杯数据挖掘挑战赛B题问题二的详细解题步骤,包括时间序列预测模型的建立、多元输入时间预测问题的分析、时间序列预测的建模步骤、改进模型的方法,以及使用Python进行SARIMA模型拟合和预测的具体实现过程。
46 1
|
21天前
|
机器学习/深度学习 数据可视化 数据挖掘
为啥我敢说Python是数据分析界的扛把子语言?
为啥我敢说Python是数据分析界的扛把子语言?
|
1月前
|
数据采集 机器学习/深度学习 搜索推荐
【2023钉钉杯复赛】A题 智能手机用户监测数据分析 Python代码分析
本文介绍了2023钉钉杯复赛A题的智能手机用户监测数据分析,包括数据预处理、特征提取、推荐模型建立与评价的Python代码实现,旨在通过用户使用记录预测APP使用情况并建立推荐系统。
52 0
【2023钉钉杯复赛】A题 智能手机用户监测数据分析 Python代码分析
|
1月前
|
机器学习/深度学习 算法 数据挖掘
【2023 年第二届钉钉杯大学生大数据挑战赛初赛】 初赛 A:智能手机用户监测数据分析 问题一Python代码分析
本文提供了2023年第二届钉钉杯大学生大数据挑战赛初赛A题"智能手机用户监测数据分析"的Python代码分析,包括数据预处理、特征工程、聚类分析等步骤,以及如何使用不同聚类算法进行用户行为分析。
37 0
【2023 年第二届钉钉杯大学生大数据挑战赛初赛】 初赛 A:智能手机用户监测数据分析 问题一Python代码分析