Bubble Episodes
Date-stamp the explosive episodes (bubbles) of the log prices, per asset, with the backward SADF (BSADF) sequence of Phillips, Shi and Yu (2015) or the forward ADF sequence of Phillips, Wu and Yu (2011).
For every date, the BSADF statistic is the largest ADF statistic of the windows that end on that date, so it only uses data up to the date: it rises once the prices start to grow explosively and falls back when the bubble collapses. A bubble starts on the first date its statistic crosses above the critical value of that date and ends on the last date before it falls back. PSY (2015) show that the backward windows date-stamp a bubble that follows an earlier one, which the forward sequence of PWY (2011) misses.
The formula is as follows, with \(y_{t}\) the log of the column (Adj Close by default) and the \(\text{ADF} (r_{1} , r_{2})\) statistics and minimum window w of get_bubble_test:
Also known as: BSADF, backward sup ADF, PSY date-stamping, bubble dating, explosive episodes, exuberance periods.
Example · NVDA, KO · 2016 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_bubble_episodes:
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_episodes(period="weekly")
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
When did the weekly share prices of Nvidia and Coca-Cola go through explosive, bubble-like episodes from 2016 to 2025?
Which returns:
| Item | Start | End | Duration | Peak Date | Peak Statistic |
|---|---|---|---|---|---|
| ('NVDA', 1) | 2020-08-03/2020-08-09 | 2020-09-07/2020-09-13 | 6 | 2020-08-24/2020-08-30 | 1.0916 |
| ('NVDA', 2) | 2021-10-25/2021-10-31 | 2021-12-27/2022-01-02 | 10 | 2021-11-15/2021-11-21 | 1.4086 |
| ('NVDA', 3) | 2023-05-22/2023-05-28 | 2023-07-31/2023-08-06 | 11 | 2023-06-12/2023-06-18 | 1.0910 |
| ('NVDA', 4) | 2024-01-29/2024-02-04 | 2025-01-20/2025-01-26 | 52 | 2024-06-10/2024-06-16 | 1.5092 |
4 rows
Using Your Own Data
get_bubble_episodes 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_episodes()
Parameters
get_bubble_episodes 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 sequence. Options are: “gsadf” (backward sequence, BSADF of PSY), “sadf” (forward ADF sequence of PWY). Defaults to “gsadf”. | "gsadf" |
lag_order | int | The number of lagged differences k in every ADF regression. Defaults to 0. | 0 |
minimum_window | int | None | The smallest window in observations. Defaults to None, floor((0.01 + 1.8 / √T)·T). | |
confidence | float | The confidence of the critical value per date. Defaults to 0.95. | 0.95 |
minimum_duration | int | None | The fewest observations an episode lasts. Defaults to None, round(log(T)). | None, round(log(T)) |
simulations | int | The number of simulated random walks for the critical values. Defaults to 2,000, as in PSY (2015). | 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 |
time_series | bool | Whether to return the statistic, its critical value and whether it is above it per date instead of the episodes. Defaults to False. | False |
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.
- Library Referenced against RiskLabAI’s get_bsadf_sequence
- Library Referenced against RiskLabAI’s get_bubble_episodes