Calculate the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test for stationarity, per asset.

KPSS is the natural complement to the Augmented Dickey-Fuller test: where the ADF null hypothesis is that the series HAS a unit root, the KPSS null hypothesis is that the series IS stationary, with a unit root as the alternative. Running both together is standard practice to triangulate a confident conclusion – ADF rejecting a unit root and KPSS failing to reject stationarity together give a confident stationarity conclusion, while the two tests disagreeing flags an ambiguous case.

For more information about the method, see the following paper:

  • Kwiatkowski, D., Phillips, P.C.B., Schmidt, P., & Shin, Y. (1992). “Testing the Null Hypothesis of Stationarity against the Alternative of a Unit Root.” Journal of Econometrics, 54(1-3), 159-178.

Also known as: KPSS test, stationarity test.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the KPSS Test for you. Just ask in plain English.

Calculate the KPSS Test in Python

The KPSS Test is available in the Econometrics module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_kpss_test as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AMZN", "TSLA"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2019-01-01",
    end_date="2023-12-31",
)

toolkit.econometrics.get_kpss_test(period="quarterly")

Which returns:

  AMZN TSLA
KPSS Statistic 0.1739 0.5193
P-Value 0.1 0.0373
Lags Used 2 2
Observations 20 20
Critical Value 1% 0.739 0.739
Critical Value 2.5% 0.574 0.574
Critical Value 5% 0.463 0.463
Critical Value 10% 0.347 0.347
Reject Stationarity (5%) 0 1

Parameters

get_kpss_test accepts the following parameters:

  • period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
  • column (str, optional): The historical data column to test. Defaults to “Adj Close”.
  • regression (str, optional): Which deterministic term to remove before testing, one of “c” (constant, level-stationarity) or “ct” (constant and trend, trend-stationarity). Defaults to “c”.
  • lags (int, optional): The truncation lag for the long-run variance estimate. Defaults to statsmodels’ automatic (Hobijn, Franses & Ooms, 2004) bandwidth selection.
  • include_benchmark (bool, optional): Whether to include “Benchmark” among the assets tested. Defaults to False.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.

The Econometrics module page introduces the module, and the sidebar lists all of its functions.

Share