Calculate the CUSUM test for the stability of the mean of returns over time.

The test fits a constant-mean model to the returns and cumulates the (scaled) OLS residuals into a path that behaves like a Brownian Bridge under the null hypothesis of a stable mean. A stable mean keeps the path close to zero, while a mean shift partway through the series (a structural break, e.g. a regime change) drags the path away from zero; the test statistic is the maximum absolute value of that path.

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

  • Ploberger, W., & Kramer, W. (1992). “The CUSUM Test with OLS Residuals.” Econometrica, 60(2), 271-285.

Also known as: CUSUM test, CUSUM of OLS residuals test, Ploberger-Kramer test.

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

Calculate the CUSUM Test in Python

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

pip install financetoolkit -U

Then call get_cusum_test as shown below.

from financetoolkit import Toolkit

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

toolkit.econometrics.get_cusum_test(period="quarterly", within_period=False)

Parameters

get_cusum_test accepts the following parameters:

  • period (str, optional): The data frequency for returns (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
  • within_period (bool, optional): Whether to calculate the test within the specified period or for the entire period. Thus whether to look at the test within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to False.
  • 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