Change Points

Find the change points of every asset’s series: the dates at which its mean, its volatility or both change.

The change points follow the PELT (Pruned Exact Linear Time) method of Killick, Fearnhead and Eckley (2012). It finds the exact segmentation that minimizes the Gaussian cost of every segment plus a penalty per change, with no upper limit on the number of changes, and prunes the candidate dates that can no longer be the last change, so it runs in about linear time.

Where get_structural_breaks (Bai and Perron) looks for shifts in the mean with a common variance and at most a few breaks, PELT with the default mean and variance cost also splits the series where the volatility changes, which for returns separates calm and turbulent periods; the variance cost keeps the mean fixed and only lets the volatility change, the mean cost only the mean. Every segment is dated after the fact with the whole series, as a description of the past rather than a signal on the day.

The formula is as follows, with \(y_{t}\) the column series (Return by default), n observations and a segment s of \(n_{s}\) observations:

\[\text{Mean and variance cost:}\;\; C(s) = n_{s} \cdot \ln(\hat{\sigma}_{s}^{2}),\;\; \text{with}\;\; \hat{\sigma}_{s}^{2} = \frac{\sum_{t \in \text{s}}(y_{t} - \bar{y}_{s})^{2}}{n_{s}}\] \[\text{Variance cost:}\;\; C(s) = n_{s} \cdot \ln\left(\frac{\sum_{t \in \text{s}}(y_{t} - \bar{y})^{2}}{n_{s}}\right),\;\; \text{with ȳ the mean of the whole series}\] \[\text{Mean cost:}\;\; C(s) = \frac{\sum_{t \in \text{s}}(y_{t} - \bar{y}_{s})^{2}}{\hat{\sigma}^{2}},\;\; \text{with}\;\; \hat{\sigma} = \frac{\operatorname{MAD}(\Delta y)}{(0.6745 \cdot \sqrt{2}) \;\text{the robust standard deviation from the changes of the series}}\]
  • The segmentation minimizes \(\sum C (s)\) + β·(number of changes), every segment at least minimum_segment observations (5 by default)
\[\beta = (p + 1) \cdot \ln(n),\;\; \text{the BIC},\;\; \text{with}\;\; p = 2 \;\text{parameters per segment for the mean and variance cost and 1 for the mean or the variance cost plus 1 for the date of the change},\;\; \text{unless penalty is given}\]
  • Per segment: its Start, End, Observations, Mean and Standard Deviation (ddof=1)

Also known as: PELT, change point detection, changepoints, variance change points, volatility regimes, segmentation, multiple structural breaks.

Example · QQQ, TLT · 2016 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_change_points:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["QQQ", "TLT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2016-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_change_points(period="monthly", cost="variance")

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

When did the volatility of the monthly returns of the Invesco QQQ and iShares 20+ Year Treasury Bond (TLT) ETFs shift from 2016 to 2025?

Which returns:

Using Your Own Data

get_change_points runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_change_points()

Parameters

get_change_points accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column to analyze. Defaults to “Return”; use “Adj Close” (or “Level” with standalone data) for the series itself, such as an inflation rate."Return"
coststrWhat may change between segments. Options are: “mean_variance” (both), “variance” (the volatility around the mean of the series), “mean” (the mean). Defaults to “mean_variance”."mean_variance"
penaltyfloat | NoneThe penalty \(\beta\) per change; a larger one finds fewer changes. Defaults to None, the BIC \((p + 1) \cdot \ln (n)\).None, the BIC $$(p + 1) \cdot \ln (n)$$
minimum_segmentintThe fewest observations of a segment. A segment of two nearly equal values has a variance close to zero, which the Gaussian cost rewards without bound, so the variance costs need a few more. Defaults to 5.5
include_benchmarkboolWhether to include “Benchmark” among the assets. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Killick, R., Fearnhead, P. and Eckley, I.A. (2012). “Optimal Detection of Changepoints With a Linear Computational Cost.” Journal of the American Statistical Association, 107(500), 1590-1598.
  • Paper Jackson, B. et al. (2005). “An Algorithm for Optimal Partitioning of Data on an Interval.” IEEE Signal Processing Letters, 12(2), 105-108.
  • Library Referenced against ruptures’ Pelt
  • Library Referenced against changepoint (R)’s penalty_decision
  • Library Shares similar logic as RiskLabAI’s pelt_change_points
Share