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:

\[\operatorname{BSADF}(r_{2}) = \max \;\text{over}\; r_{1} \leq r_{2} - w + 1 \;\text{of ADF}(r_{1},\; r_{2}) \;(\text{the backward sequence}),\;\; \text{or ADF(0, } r_{2} \text{) (the forward sequence)}\] \[\operatorname{cv}(r_{2}) = \text{the} \;\text{confidence} \;\text{quantile} \;(95\% \;\text{by default}) \;\text{of the same statistic at}\; r_{2} \;\text{over} \;\text{simulations} \;\text{random walks}\; y_{t} = y_{t-1} + \frac{1}{T} + \epsilon_{t}\] \[\text{Bubble on } r_{2} \text{ when the statistic is above } cv (r_{2});\;\; \text{an episode is a run of such dates of at least minimum\_duration observations},\;\; \text{by default round}(\log(T)) (\delta \cdot \log(T) \;\text{with}\; \delta = 1 \;\text{in PSY},\; 2015)\]

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:

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.

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 sequence. Options are: “gsadf” (backward sequence, BSADF of PSY), “sadf” (forward ADF sequence of PWY). Defaults to “gsadf”."gsadf"
lag_orderintThe number of lagged differences k in every ADF regression. Defaults to 0.0
minimum_windowint | NoneThe smallest window in observations. Defaults to None, floor((0.01 + 1.8 / √T)·T).
confidencefloatThe confidence of the critical value per date. Defaults to 0.95.0.95
minimum_durationint | NoneThe fewest observations an episode lasts. Defaults to None, round(log(T)).None, round(log(T))
simulationsintThe number of simulated random walks for the critical values. Defaults to 2,000, as in PSY (2015).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
time_seriesboolWhether to return the statistic, its critical value and whether it is above it per date instead of the episodes. Defaults to False.False
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.
  • Library Referenced against RiskLabAI’s get_bsadf_sequence
  • Library Referenced against RiskLabAI’s get_bubble_episodes
Share