Bubble Test (GSADF)

Calculate the GSADF test of Phillips, Shi and Yu (2015) or the SADF test of Phillips, Wu and Yu (2011) for explosive behaviour, a bubble, in the log prices, per asset.

The ADF test looks for mean reversion (a left tail); these tests look at the right tail: a price that grows faster than a random walk, as in a bubble, gives a large positive ADF statistic over the window of the bubble. The SADF test runs the ADF regression on every window from the first observation that is at least the minimum window long and takes the largest statistic; the GSADF test also moves the start of the window, so it finds a bubble that came after an earlier one collapsed. A statistic above its critical value rejects the random walk in favour of explosive behaviour somewhere in the sample; which dates are explosive follows from get_bubble_episodes.

The formula is as follows, with \(y_{t}\) the log of the column (Adj Close by default) and T observations:

\[\operatorname{ADF}(r_{1},\; r_{2}) = \frac{\hat{\beta}}{\operatorname{SE}(\hat{\beta}) \;\text{of}\; \Delta y_{t}} = \alpha + \beta \cdot y_{t-1} + \sum_{i=1}^{k} \gamma_{i} \cdot \Delta y_{t-i} + \epsilon_{t} \;\text{on the observations}\; r_{1} \;\text{to}\; r_{2},\;\; \text{with}\;\; k = \text{lag\_order}\] \[w = \left\lfloor \left(0.01 + \frac{1.8}{\sqrt{T}}\right) \cdot T \right\rfloor,\;\; \text{the minimum window of PSY (2015)}\] \[\text{SADF} = \max \;\text{over}\; r_{2} \geq w - 1 \;\text{of ADF}(0,\; r_{2})\] \[\text{GSADF} = \max \;\text{over}\; r_{2} \;\text{of BSADF}(r_{2}),\;\; \text{with}\;\; \operatorname{BSADF}(r_{2}) = \max \;\text{over}\; r_{1} \leq r_{2} - w + 1 \;\text{of ADF}(r_{1},\; r_{2})\] \[\text{Critical values and the p-value from} \;\text{simulations} \;\text{random walks}\; y_{t} = y_{t-1} + \frac{1}{T} + \epsilon_{t},\;\; \epsilon_{t} \sim N(0,\; 1),\;\; \text{with the same } T \text{, } w \text{ and } k \text{: the 90\%, 95\% and 99\% quantiles of the simulated statistic and the share of simulated statistics at least as large}\]

Also known as: GSADF test, SADF test, sup ADF, generalized sup ADF, PSY test, PWY test, explosive root test, right-tailed unit root test, bubble detection.

Example · NVDA, KO · 2016 to 2025

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

from financetoolkit import Toolkit

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

toolkit.econometrics.get_bubble_test(period="weekly")

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

Did the weekly share prices of Nvidia and Coca-Cola show a bubble from 2016 to 2025, according to the GSADF test of Phillips, Shi and Yu?

Which returns:

Using Your Own Data

get_bubble_test 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_bubble_test()

Parameters

get_bubble_test accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column to test. Defaults to “Adj Close”."Return"
methodLiteral["gsadf", "sadf"]The test. Options are: “gsadf” (generalized sup ADF test, GSADF), “sadf” (forward sup ADF test, SADF). Defaults to “gsadf”."gsadf"
lag_orderintThe number of lagged differences k in every ADF regression. Defaults to 0, as PSY (2015) use.0, as PSY (2015) use
minimum_windowint | NoneThe smallest window in observations. Defaults to None, floor((0.01 + 1.8 / √T)·T).
simulationsintThe number of simulated random walks for the critical values. Defaults to 2,000, as in - PSY (2015): the critical values serve every series of the same length, so with 500 random walks the size of the test at 5% ranges from about 3.5% to 7% depending on the seed.1000
seedintThe seed of the simulation. Defaults to 0.42
log_pricesboolWhether to take the natural logarithm of the series first. Pass False for a series that can be zero or negative, such as a rate. Defaults to True.True
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, which uses the rounding of the Toolkit (4 unless set otherwise).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 Phillips, P.C.B., Shi, S. and Yu, J. (2015). “Testing for Multiple Bubbles: Historical Episodes of Exuberance and Collapse in the S&P 500.” International Economic Review, 56(4), 1043-1078.
  • Paper Phillips, P.C.B., Wu, Y. and Yu, J. (2011). “Explosive Behavior in the 1990s Nasdaq: When Did Exuberance Escalate Asset Values?” International Economic Review, 52(1), 201-226.
  • Paper López de Prado, M. (2018). “Advances in Financial Machine Learning.” Wiley, section 17.4.2 (Snippets 17.1 to 17.4).
  • Library Referenced against RiskLabAI’s get_gsadf_statistic
  • Library Referenced against RiskLabAI’s simulate_psy_critical_values
  • Library Referenced against statsmodels’ adfuller
Share