tslumen.profile.correlation module

Auto/correlation functions, including Spearman, ACF, PACF, etc.

tslumen.profile.correlation.acf(data: pandas.core.series.Series, lags: int = 40, adjusted: bool = False, fft: bool = False, alpha: float = 0.05, missing: str = 'none')pandas.core.frame.DataFrame[source]

Calculates the autocorrelation function on level data.

Returns

DataFrame with 4 columns: lag, correlation, low and up.

Return type

pd.DataFrame

tslumen.profile.correlation.acf_1d(data: pandas.core.series.Series, lags: int = 40, adjusted: bool = False, fft: bool = False, alpha: float = 0.05, missing: str = 'none')pandas.core.frame.DataFrame[source]

Calculates the autocorrelation function on 1-differenced data.

Returns

DataFrame with 4 columns: lag, correlation, low and up.

Return type

pd.DataFrame

tslumen.profile.correlation.acf_2d(data: pandas.core.series.Series, lags: int = 40, adjusted: bool = False, fft: bool = False, alpha: float = 0.05, missing: str = 'none')pandas.core.frame.DataFrame[source]

Calculates the autocorrelation function on 2-differenced data.

Returns

DataFrame with 4 columns: lag, correlation, low and up.

Return type

pd.DataFrame

tslumen.profile.correlation.corr_kendall(data: pandas.core.frame.DataFrame)pandas.core.frame.DataFrame[source]
Parameters

data (pd.DataFrame) – Timeseries dataframe.

Returns

Kendall correlation.

Return type

pd.DataFrame

tslumen.profile.correlation.corr_pearson(data: pandas.core.frame.DataFrame)pandas.core.frame.DataFrame[source]
Parameters

data (pd.DataFrame) – Timeseries dataframe.

Returns

Pearson correlation.

Return type

pd.DataFrame

tslumen.profile.correlation.corr_spearman(data: pandas.core.frame.DataFrame)pandas.core.frame.DataFrame[source]
Parameters

data (pd.DataFrame) – Timeseries dataframe.

Returns

Spearman correlation.

Return type

pd.DataFrame

tslumen.profile.correlation.granger_causality(data: pandas.core.frame.DataFrame, test: str = 'ssr_chi2test', addconst: bool = True, maxlag: int = 5, max_diff: int = 3, adf_confidence: float = 0.1)Tuple[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame, int][source]

Attempts to make the data stationary by applying differencing if needed (up to max_diff) – determined based on ADFuller test on adf_confidence with autolag calculation based on AIC; for each series pair, runs granger causality test and gets the smallest p-value and corresponding lag; builds a matrix with the result.

Parameters
  • data (pd.DataFrame) – Timeseries dataframe.

  • test (str) – Test name to use with Granger Causality.

  • addconst (bool) – Include a constant in the model.

  • maxlag (int) – Compute Granger Causality up til maxlag.

  • max_diff (int) – Diff at most max_diff times to attain stationarity.

  • adf_confidence (float) – Confidence level for the ADFuller test on stationarity.

Returns

p-values matrix, lags matrix, number of differencing

Return type

pd.DataFrame, pd.DataFrame, int

tslumen.profile.correlation.lag_corr(data: pandas.core.series.Series, lags: Optional[Tuple[int, ]] = ())Tuple[pandas.core.frame.DataFrame, pandas.core.series.Series][source]

Creates a DataFrame with the level data plus shifts as per the lags parameter.

Parameters
  • data (pd.Series) – Timeseries data.

  • lags (Optional[Tuple[int, ..]]) – Lags to shift the data on. If not supplied attempts to find appropriate defaults based on the frequency.

Returns

DataFrame with shifted data, DataFrame with correlation between lagged and level

Return type

pd.DataFrame, pd.DataFrame

tslumen.profile.correlation.pacf(data: pandas.core.series.Series, lags: int = 40, method: str = 'ywadjusted', alpha: float = 0.05)pandas.core.frame.DataFrame[source]

Calculates the partial autocorrelation function on level data.

Returns

DataFrame with 4 columns: lag, correlation, low and up.

Return type

pd.DataFrame

tslumen.profile.correlation.pacf_1d(data: pandas.core.series.Series, lags: int = 40, method: str = 'ywadjusted', alpha: float = 0.05)pandas.core.frame.DataFrame[source]

Calculates the partial autocorrelation function on 1-differenced data.

Returns

DataFrame with 4 columns: lag, correlation, low and up.

Return type

pd.DataFrame

tslumen.profile.correlation.pacf_2d(data: pandas.core.series.Series, lags: int = 40, method: str = 'ywadjusted', alpha: float = 0.05)pandas.core.frame.DataFrame[source]

Calculates the partial autocorrelation function on 1-differenced data.

Returns

DataFrame with 4 columns: lag, correlation, low and up.

Return type

pd.DataFrame