mizarlabs.structural_breaks package

Submodules

mizarlabs.structural_breaks.cusum_chu_stinchcome_white module

Implementation of Chu-Stinchcombe-White test

class mizarlabs.structural_breaks.cusum_chu_stinchcome_white.ChuStinchcombeWhiteStatTest(side_test: str)[source]

Bases: object

CRITICAL_VALUE = 'critical_value'
STATISTIC = 'statistic'
run(series_to_test: pandas.core.series.Series)pandas.core.frame.DataFrame[source]

Runs the Chu-Stinchcombe-White stat test and returns a dataframe with the test statistics and corresponding critical values.

Parameters

series_to_test (pd.Series) – Time series to be tested.

Returns

DataFrame with results.

Return type

pd.DataFrame

mizarlabs.structural_breaks.cusum_chu_stinchcome_white.get_test_statistics_array(side_test: str, t_indices: numpy.ndarray, time_series_array: numpy.ndarray)numpy.ndarray[source]

Returns an array with the test statistics of the Chu-Stinchcombe-White and the critical values

Parameters
  • side_test (str) – ‘one_sided_positive’ or ‘one_sided_negative’ or ‘two_sided’

  • t_indices (np.ndarray) – t indices to loop over

  • time_series_array (np.ndarray) – Time series to be tested

Returns

Array with two columns, one for the test statistic and one for the critical values

Return type

np.ndarray

mizarlabs.structural_breaks.cusum_chu_stinchcome_white.get_y_t_y_n_diff(side_test: str, y_t: numpy.float64, y_n: numpy.float64)numpy.float64[source]

Returns the difference between y_t and y_n given a test specification.

Parameters
  • side_test (str) – ‘one_sided_positive’ or ‘one_sided_negative’ or ‘two_sided’

  • y_t (np.float64) – value of the series to be tested at time t

  • y_n (np.float64) – value of the series to be tested at time n, where n < t

Returns

difference between y_t and y_n given a test specification

Return type

np.float64

mizarlabs.structural_breaks.sadf module

Explosiveness tests: SADF

class mizarlabs.structural_breaks.sadf.SupremumAugmentedDickeyFullerStatTest(model: str, lags: Union[int, list], min_length: int, add_constant: bool, phi: float)[source]

Bases: object

Implementation of SADF, p. 252-261.

SADF fits the ADF regression at each end point t with backwards expanding start points. For the estimation of SADF(t), the right side of the window is fixed at t. SADF recursively expands the beginning of the sample up to t - min_length, and returns the sup of this set.

When doing with sub- or super-martingale test, the variance of beta of a weak long-run bubble may be smaller than one of a strong short-run bubble, hence biasing the method towards long-run bubbles. To correct for this bias, ADF statistic in samples with large lengths can be penalized with the coefficient phi in [0, 1] such that:

ADF_penalized = ADF / (t - t0) ^ phi), where t0 is between 1 and t - min_length

Parameters
  • model (str) – model test specification, which can be ‘no_trend’, ‘linear’, ‘quadratic’, ‘sm_poly_1’, ‘sm_poly_2’, ‘sm_exp’, ‘sm_power’

  • lags (Union[int, list]) – either number of lags to use or array of specified lags

  • min_length (int) – minimum number of observations needed for estimation

  • add_constant (bool) – flag to add constant, NOTE: sub- and super-martingale tests always have a constant.

  • phi (float) – coefficient to penalize large sample lengths when computing SMT, in [0, 1]

run(series_to_test: pandas.core.series.Series)pandas.core.series.Series[source]

Runs the Supremum Augmented Dickey Fuller test and returns a series with SADF statistics.

When the model specification is for sub- and super-martingale then a series with SMT statistics is returned. See page 260 for additional details.

Parameters

series_to_test (pd.Series) – series for which SADF statistics are generated

Returns

series of SADF statistics (or SMT in case of sub- and super-martingale tests)

Return type

pd.Series

mizarlabs.structural_breaks.sdfc module

Explosiveness tests: Chow-Type Dickey-Fuller Test

class mizarlabs.structural_breaks.sdfc.SupremumDickeyFullerChowStatTest(min_num_samples: int = 20)[source]

Bases: object

run(series_to_test: pandas.core.series.Series)pandas.core.series.Series[source]
mizarlabs.structural_breaks.sdfc.get_beta_and_beta_var(X: numpy.ndarray, y: numpy.ndarray)Tuple[float][source]

Returns the OLS estimates of the coefficients and the variance of the coefficients.

Parameters
  • X (pd.DataFrame) – Matrix with features values

  • y (pd.Series) – Series with target values.

Returns

Tuple with the coefficients and the variance of the coefficients estimate.

Return type

Tuple[np.ndarray, np.ndarray]

mizarlabs.structural_breaks.sdfc.get_dfc_array(indices: numpy.ndarray, y_diff: numpy.ndarray, y_lag: numpy.ndarray)numpy.ndarray[source]

Returns the Chow-Type Dickey-Fuller t-values.

Parameters
  • indices (np.ndarray) – Indices to iterate over

  • y_diff (np.ndarray) – Differenced time series

  • y_lag (np.ndarray) – Lagged time series

Returns

Array with t-values.

Return type

np.ndarray

Module contents