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:
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:
| Item | NVDA | KO |
|---|---|---|
| GSADF Statistic | 1.5092 | 1.0560 |
| P-Value | 0.3165 | 0.6405 |
| Critical Value 10% | 1.9834 | 1.9834 |
| Critical Value 5% | 2.2071 | 2.2071 |
| Critical Value 1% | 2.8067 | 2.8067 |
| Observations | 522.0000 | 522.0000 |
| Minimum Window | 46.0000 | 46.0000 |
| Lags | 0.0000 | 0.0000 |
| Replications | 2,000.0000 | 2,000.0000 |
| Explosive (5%) | 0.0000 | 0.0000 |
10 rows
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.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to test. Defaults to “Adj Close”. | "Return" |
method | Literal["gsadf", "sadf"] | The test. Options are: “gsadf” (generalized sup ADF test, GSADF), “sadf” (forward sup ADF test, SADF). Defaults to “gsadf”. | "gsadf" |
lag_order | int | The number of lagged differences k in every ADF regression. Defaults to 0, as PSY (2015) use. | 0, as PSY (2015) use |
minimum_window | int | None | The smallest window in observations. Defaults to None, floor((0.01 + 1.8 / √T)·T). | |
simulations | int | The 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 |
seed | int | The seed of the simulation. Defaults to 0. | 42 |
log_prices | bool | Whether 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_benchmark | bool | Whether to include “Benchmark” among the assets. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
show_columns | str | list[str] | None | The 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