当前位置: 首页>>代码示例>>Python>>正文


Python stattools.adfuller方法代码示例

本文整理汇总了Python中statsmodels.tsa.stattools.adfuller方法的典型用法代码示例。如果您正苦于以下问题:Python stattools.adfuller方法的具体用法?Python stattools.adfuller怎么用?Python stattools.adfuller使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在statsmodels.tsa.stattools的用法示例。


在下文中一共展示了stattools.adfuller方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_custom_difference

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_custom_difference(self, custom_transformation_size):
        self.d = custom_transformation_size[0]
        self.D = custom_transformation_size[1]

        self.transformed_time_series = self.original_timeseries.diff(self.d).diff(self.seasonality * self.D).dropna()
        self.dftest = adfuller(self.transformed_time_series, autolag='AIC')
        self.transformation_function = lambda x: x

        self.test_stationarity_code = '''
                # Applying Augmented Dickey-Fuller test
                dftest = adfuller(df.diff({}).diff({}).dropna(), autolag='AIC')
                '''.format(self.d, self.D)

        self.label = 'Custom Difference' if self.dftest[0] < self.dftest[4]['1%'] else None

        return self.dftest, self.transformed_time_series, self.label, self.d, self.D, self.transformation_function, self.test_stationarity_code, self.seasonality 
开发者ID:paulozip,项目名称:arauto,代码行数:18,代码来源:transformation_function.py

示例2: test_stationarity

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_stationarity(timeseries):
    #Determing rolling statistics
    rolmean = pd.Series(timeseries).rolling(window=12).mean()
    rolstd = pd.Series(timeseries).rolling(window=12).std()
    #Plot rolling statistics:
    orig = plt.plot(timeseries, color='blue',label='Original')
    mean = plt.plot(rolmean, color='red', label='Rolling Mean')
    std = plt.plot(rolstd, color='black', label = 'Rolling Std')
    plt.legend(loc='best')
    plt.title('Rolling Mean & Standard Deviation')
    plt.show(block=False)
    #Perform Dickey-Fuller test:
    print("Results of Dickey-Fuller Test:")
    array = np.asarray(timeseries, dtype='float')
    np.nan_to_num(array,copy=False)
    dftest = adfuller(array, autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
        dfoutput['Critical Value (%s)'%key] = value
    print(dfoutput)


# Load data 
开发者ID:boragungoren-portakalteknoloji,项目名称:METU-BA4318-Spring2019,代码行数:25,代码来源:Stationarity-Patients.py

示例3: test_adf_autolag

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_adf_autolag():
    #see issue #246
    #this is mostly a unit test
    d2 = macrodata.load().data

    for k_trend, tr in enumerate(['nc', 'c', 'ct', 'ctt']):
        #[None:'nc', 0:'c', 1:'ct', 2:'ctt']
        x = np.log(d2['realgdp'])
        xd = np.diff(x)

        #check exog
        adf3 = tsast.adfuller(x, maxlag=None, autolag='aic',
                              regression=tr, store=True, regresults=True)
        st2 = adf3[-1]

        assert_equal(len(st2.autolag_results), 15 + 1)  #+1 for lagged level
        for l, res in sorted(iteritems(st2.autolag_results))[:5]:
            lag = l-k_trend
            #assert correct design matrices in _autolag
            assert_equal(res.model.exog[-10:,k_trend], x[-11:-1])
            assert_equal(res.model.exog[-1,k_trend+1:], xd[-lag:-1][::-1])
            #min-ic lag of dfgls in Stata is also 2, or 9 for maic with notrend
            assert_equal(st2.usedlag, 2)

        #same result with lag fixed at usedlag of autolag
        adf2 = tsast.adfuller(x, maxlag=2, autolag=None, regression=tr)
        assert_almost_equal(adf3[:2], adf2[:2], decimal=12)


    tr = 'c'
    #check maxlag with autolag
    adf3 = tsast.adfuller(x, maxlag=5, autolag='aic',
                          regression=tr, store=True, regresults=True)
    assert_equal(len(adf3[-1].autolag_results), 5 + 1)
    adf3 = tsast.adfuller(x, maxlag=0, autolag='aic',
                          regression=tr, store=True, regresults=True)
    assert_equal(len(adf3[-1].autolag_results), 0 + 1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:39,代码来源:test_adfuller_lag.py

示例4: unitroot_adf

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def unitroot_adf(x, maxlag=None, trendorder=0, autolag='AIC', store=False):
    return adfuller(x, maxlag=maxlag, regression=trendorder, autolag=autolag,
                    store=store, regresults=False)


#TODO: I like the bunch pattern for this too. 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:diagnostic.py

示例5: diff_nonstationary

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def diff_nonstationary(x, alpha):
    
    """Returns number of differentiations required to transform
    a non-stationary time series into a stationary one. If 0 (zero) is
    returned, there's no need to differentiate."""
    """
    PARAMETERS:
    1) x - input time series
    2) alpha - significance level
    """
    
    i = 0 # no need to differentiate
    pvalue = adfuller(x, regression =
            ('ct' if
            stats.linregress( pd.Series(range(1, len(x)+1)), x ).pvalue<alpha
            else 'c')
            )[1]
    while pvalue>alpha:
        x = x.diff()
        pvalue = adfuller(x.dropna(),
            regression = 'c')[1]
        i += 1
        if pvalue<=alpha:
            break
    return(int(i))
    
### End of code 
开发者ID:dgwozdz,项目名称:HN_SO_analysis,代码行数:29,代码来源:diff_nonstationary.py

示例6: _adfTest

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def _adfTest(self, s):
        """
            ADF Test
            p值越大:随机漫步,可能是趋势
            p值越小:均值回归
        """
        result = stattools.adfuller(s, 1)

        return result[1] 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:11,代码来源:DySS_Pairs.py

示例7: _adfTest

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def _adfTest(self, df):
        """
            ADF Test
            p值越大:随机漫步,可能是趋势
            p值越小:均值回归
        """
        df = df[-21:-1]

        result = stattools.adfuller(df['close'], 1)

        return result[1] 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:13,代码来源:DySS_LimitUpAnalysis.py

示例8: adfTest

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def adfTest(s):
        """
            ADF Test
            p值越大:随机漫步,可能是趋势
            p值越小:均值回归
        """
        result = stattools.adfuller(s, 1)

        return result[1] 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:11,代码来源:DyStockDataML.py

示例9: test_absolute_data

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_absolute_data(self):
        '''
        Run the Adfuller test on the original data, without transformation

        Returns:
            dftest (tuple): a tuple containing the Augmented Dickey-Fuller test. Among other things, 
                it contains the test statistics, the critical values, and p-values. Please refer to 
                (https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html) for
                further information
            transformed_time_series (pandas Series): the transformed time series if applied. For this function,
                it returns the original time series, since no transformations are applied. 
            label (str): if the adfuller result is statistical significant, a string is returned informing the
                transformation that was applied to the time series. This informations is only needed to inform on
                Matplotlib plots in test_stationarity function 
            d (int): the amount of integrated terms used in this function/transformation. For this function, no differencing is
                applied, since it returns the original time series 
            D (int): the amount of seasonal integrated terms used in this function/transformation. For this function, no differencing is
                applied, since it returns the original time series
            transformation_function (func): this module contains two distinct transformation functions: numpy.log and lambda x: x.
                This value informs what transformation function was used on the time series. If Logarithm was used, returns numpy.log,
                otherwise, returns a lambda function 
            test_stationarity_code (str): the code that was used on this transformation. This is used in future to generate the code
                for the user on Arauto .
            seasonality (int): the amount of seasonality terms
        '''

        self.dftest = adfuller(self.original_timeseries, autolag='AIC')
        
        self.test_stationarity_code = '''
                # Applying Augmented Dickey-Fuller test
                dftest = adfuller(df, autolag='AIC')
                    '''
        self.label = 'Absolute' if self.dftest[0] < self.dftest[4]['1%'] else None
        
        return self.dftest, self.transformed_time_series, self.label, self.d, self.D, self.transformation_function, self.test_stationarity_code, self.seasonality 
开发者ID:paulozip,项目名称:arauto,代码行数:37,代码来源:transformation_function.py

示例10: test_first_difference

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_first_difference(self):
        '''
        Run the Adfuller test on the original data with first difference

        Returns:
            dftest (tuple): a tuple containing the Augmented Dickey-Fuller test. Among other things, 
                it contains the test statistics, the critical values, and p-values. Please refer to 
                (https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html) for
                further information
            transformed_time_series (pandas Series): the transformed time series if applied.
            label (str): if the adfuller result is statistical significant, a string is returned informing the
                transformation that was applied to the time series. This informations is only needed to inform on
                Matplotlib plots in test_stationarity function 
            d (int): the amount of integrated terms used in this function/transformation.
            D (int): the amount of seasonal integrated terms used in this function/transformation.
            transformation_function (func): this module contains two distinct transformation functions: numpy.log and lambda x: x.
                This value informs what transformation function was used on the time series. If Logarithm was used, returns numpy.log,
                otherwise, returns a lambda function 
            test_stationarity_code (str): the code that was used on this transformation. This is used in future to generate the code
                for the user on Arauto .
            seasonality (int): the amount of seasonality terms
        '''

        self.transformed_time_series = self.original_timeseries.diff().dropna()
        self.dftest = adfuller(self.transformed_time_series, autolag='AIC')

        self.test_stationarity_code = '''
                # Applying Augmented Dickey-Fuller test
                dftest = adfuller(df.diff().dropna(), autolag='AIC')
                    '''
        self.label = 'Difference' if self.dftest[0] < self.dftest[4]['1%'] else None
        self.d = 1
        self.D = 0
        
        return self.dftest, self.transformed_time_series, self.label, self.d, self.D, self.transformation_function, self.test_stationarity_code, self.seasonality 
开发者ID:paulozip,项目名称:arauto,代码行数:37,代码来源:transformation_function.py

示例11: test_log_transformation

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_log_transformation(self):
        '''
        Run the Adfuller test on the original data with log transformation

        Returns:
            dftest (tuple): a tuple containing the Augmented Dickey-Fuller test. Among other things, 
                it contains the test statistics, the critical values, and p-values. Please refer to 
                (https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html) for
                further information
            transformed_time_series (pandas Series): the transformed time series if applied.
            label (str): if the adfuller result is statistical significant, a string is returned informing the
                transformation that was applied to the time series. This informations is only needed to inform on
                Matplotlib plots in test_stationarity function 
            d (int): the amount of integrated terms used in this function/transformation.
            D (int): the amount of seasonal integrated terms used in this function/transformation.
            transformation_function (func): this module contains two distinct transformation functions: numpy.log and lambda x: x.
                This value informs what transformation function was used on the time series. If Logarithm was used, returns numpy.log,
                otherwise, returns a lambda function 
            test_stationarity_code (str): the code that was used on this transformation. This is used in future to generate the code
                for the user on Arauto .
            seasonality (int): the amount of seasonality terms
        '''

        self.transformed_time_series = np.log1p(self.original_timeseries)
        self.dftest = adfuller(self.transformed_time_series, autolag='AIC')
        self.transformation_function = np.log1p

        self.test_stationarity_code = '''
                # Applying Augmented Dickey-Fuller test
                df = np.log1p(df) 
                dftest = adfuller(np.log1p(df), autolag='AIC')
                    '''
        self.label = 'Log transformation' if self.dftest[0] < self.dftest[4]['1%'] else None
        self.d = 0
        self.D = 0

        return self.dftest, self.transformed_time_series, self.label, self.d, self.D, self.transformation_function, self.test_stationarity_code, self.seasonality 
开发者ID:paulozip,项目名称:arauto,代码行数:39,代码来源:transformation_function.py

示例12: test_seasonal_difference

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_seasonal_difference(self):
        '''
        Run the Adfuller test on the original data with seasonal difference

        Returns:
            dftest (tuple): a tuple containing the Augmented Dickey-Fuller test. Among other things, 
                it contains the test statistics, the critical values, and p-values. Please refer to 
                (https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html) for
                further information
            transformed_time_series (pandas Series): the transformed time series if applied.
            label (str): if the adfuller result is statistical significant, a string is returned informing the
                transformation that was applied to the time series. This informations is only needed to inform on
                Matplotlib plots in test_stationarity function 
            d (int): the amount of integrated terms used in this function/transformation.
            D (int): the amount of seasonal integrated terms used in this function/transformation.
            transformation_function (func): this module contains two distinct transformation functions: numpy.log and lambda x: x.
                This value informs what transformation function was used on the time series. If Logarithm was used, returns numpy.log,
                otherwise, returns a lambda function 
            test_stationarity_code (str): the code that was used on this transformation. This is used in future to generate the code
                for the user on Arauto .
            seasonality (int): the amount of seasonality terms
        '''

        self.transformed_time_series = self.original_timeseries.diff(self.seasonality).dropna()
        self.dftest = adfuller(self.transformed_time_series, autolag='AIC')
        self.transformation_function = lambda x: x

        self.test_stationarity_code = '''
                # Applying Augmented Dickey-Fuller test
                dftest = adfuller(df.diff({}).dropna(), autolag='AIC')
                    '''.format(self.seasonality)
        self.label = 'Seasonality Difference' if self.dftest[0] < self.dftest[4]['1%'] else None
        self.d = 0
        self.D = 1

        return self.dftest, self.transformed_time_series, self.label, self.d, self.D, self.transformation_function, self.test_stationarity_code, self.seasonality 
开发者ID:paulozip,项目名称:arauto,代码行数:38,代码来源:transformation_function.py

示例13: test_seasonal_log_difference

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_seasonal_log_difference(self):
        '''
        Run the Adfuller test on the original data with seasonal difference and log first difference

        Returns:
            dftest (tuple): a tuple containing the Augmented Dickey-Fuller test. Among other things, 
                it contains the test statistics, the critical values, and p-values. Please refer to 
                (https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html) for
                further information
            transformed_time_series (pandas Series): the transformed time series if applied.
            label (str): if the adfuller result is statistical significant, a string is returned informing the
                transformation that was applied to the time series. This informations is only needed to inform on
                Matplotlib plots in test_stationarity function 
            d (int): the amount of integrated terms used in this function/transformation.
            D (int): the amount of seasonal integrated terms used in this function/transformation.
            transformation_function (func): this module contains two distinct transformation functions: numpy.log and lambda x: x.
                This value informs what transformation function was used on the time series. If Logarithm was used, returns numpy.log,
                otherwise, returns a lambda function 
            test_stationarity_code (str): the code that was used on this transformation. This is used in future to generate the code
                for the user on Arauto .
            seasonality (int): the amount of seasonality terms
        '''

        self.transformed_time_series = np.log1p(self.original_timeseries).diff().diff(self.seasonality).dropna()
        self.dftest = adfuller(self.transformed_time_series, autolag='AIC')
        self.transformation_function = np.log1p

        self.test_stationarity_code = '''
                # Applying Augmented Dickey-Fuller test
                df = np.log1p(df)
                dftest = adfuller(df.diff().diff({}).dropna(), autolag='AIC')
                '''.format(self.seasonality)

        self.label = 'Log Difference + Seasonal Difference' if self.dftest[0] < self.dftest[4]['1%'] else None
        self.d = 1
        self.D = 1

        return self.dftest, self.transformed_time_series, self.label, self.d, self.D, self.transformation_function, self.test_stationarity_code, self.seasonality 
开发者ID:paulozip,项目名称:arauto,代码行数:40,代码来源:transformation_function.py

示例14: test_stationarity

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def test_stationarity(timeseries):
    print('Results of Dickey-Fuller Test:')
    dftest = adfuller(timeseries[1:], autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic', 'p-value', '#Lags Used', 'Number of Observations Used'])
    print (dfoutput) 
开发者ID:PacktPublishing,项目名称:Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading,代码行数:7,代码来源:seasonality.py

示例15: get_filename_without_ext

# 需要导入模块: from statsmodels.tsa import stattools [as 别名]
# 或者: from statsmodels.tsa.stattools import adfuller [as 别名]
def get_filename_without_ext(path):
    filename = os.path.basename(path)
    return os.path.splitext(filename)[0]


# def compute_intercept_and_pvalue(p1, p2):
#     # log Y = intercept + log X + c
#     Y, X = pd.Series(np.log(p1)), pd.Series(np.log(p2))

#     # returns (intercept, pvalue)
#     return (np.mean(Y - X), smts.adfuller(Y - X)[1]) 
开发者ID:wywongbd,项目名称:pairstrade-fyp-2019,代码行数:13,代码来源:process_raw_prices.py


注:本文中的statsmodels.tsa.stattools.adfuller方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。