Measuring Post-Earnings-Announcement Drift in Python: An Honest Event-Study Skeleton

Post-earnings-announcement drift (PEAD) is the tendency of a stock’s cumulative abnormal returns to keep moving in the direction of an earnings surprise for weeks after the announcement. Measuring it honestly means choosing a defensible surprise definition, aligning the event window carefully, and checking for look-ahead bias, survivorship, overlapping events, and risk adjustment.

Method transparency: This post draws on the peer-reviewed papers linked in the text, the official yfinance API reference and its mirror, a GitHub issue tracker entry, and a one-time spot check of AAPL earnings timestamps. The snippet is a method illustration; yfinance column names (such as Reported EPS and EPS Estimate) vary by library version, so verify them before use.

Scope: Educational methodology only. This post reports no empirical results and offers no trading guidance.

What PEAD Is — and Why Measurement Is the Hard Part

A standard definition comes from Livnat & Mendenhall: “Post–earnings announcement drift is the tendency for a stock’s cumulative abnormal returns to drift in the direction of an earnings surprise for several weeks following an earnings announcement.” Note what that sentence quietly assumes: an “abnormal return,” an “earnings surprise,” and a “drift” — each of which you must construct before you can measure anything.

The cause is framed as an open question. Bernard & Thomas frame the question in their title — Delayed Price Response or Risk Premium — and the JSTOR abstract notes that “One class of explanations suggests that at least a portion of the price response to new information is delayed.” The other framing, per the paper’s title and keywords, is a risk premium, with “incomplete risk adjustment” among the keywords. On the gradual-response side, Chan, Jegadeesh & Lakonishok, whose momentum paper focuses on past earnings news, conclude that “The results suggest a market that responds only gradually to new information.”

Two readings, one measurement problem. This post builds the apparatus for measuring the pattern; it does not adjudicate the debate.

Step 1: Define the Earnings Surprise — and Own the Choice

There is no neutral surprise definition. The two families are:

  • Time-series surprises (SUE): actual earnings minus a forecast extrapolated from the firm’s own past earnings, typically standardized by earnings volatility or price.
  • Analyst-forecast surprises: actual earnings minus the consensus estimate, optionally scaled by price, by forecast dispersion, or by the standard deviation of estimates.

This is not a detail — it changes the quantity you are measuring. Livnat & Mendenhall show that the drift is “significantly larger when defining the earnings surprise using analysts’ forecasts and actual earnings from I/B/E/S than when using a time series model.” In other words, your surprise definition is a research-design choice, and the drift you report is conditional on it. Say so explicitly in any write-up.

For a quick prototype, yfinance’s earnings history exposes Reported EPS and EPS Estimate columns, which give you a convenient surprise proxy. The skeleton below does not use these columns; the note after it explains the gap. Treat it as an approximation and document the deviation: the library does not document whether its estimate column is a frozen, point-in-time consensus.

Step 2: Design the Event Window

Three decisions carry most of the methodological weight.

t=0 alignment. An earnings release stamped 4:05 p.m. Eastern lands after the close; one stamped 7:00 a.m. lands before. If you naively assign both to the same calendar date, after-hours announcements let you “observe” a price reaction before it happens — the classic look-ahead trap. The convention used here: a release at or after 16:00 Eastern maps to the next session, and a release before the open maps to the same session. The after-close cutoff was spot-checked only on AAPL releases stamped 16:00; before-open timing has not been checked against data, and releases during the session follow the same-session branch. Every day index is computed off that anchor. If you cannot recover the timestamp, your window is noisy by construction.

Estimation window vs. event window. The risk model’s parameters (beta, factor loadings) must be estimated on a window that ends before the event — the snippet sets the estimation window with EST_W = (-250, -20), which ends before the event window. Estimating beta on data that includes the event window contaminates your abnormal returns with the very effect you are trying to measure.

Indexing and aggregation. Decide between trading-day and calendar-day indexing and never mix them. Then decide how to aggregate: cumulative abnormal returns (CAR), which sum abnormal returns over the window, or buy-and-hold abnormal returns (BHAR), which compound them. They answer slightly different questions and diverge as the window lengthens. Pick one, state it, and keep it fixed across all event cohorts.

Python Skeleton: An Event Study with yfinance and pandas

Method illustration — event-study plumbing only. No results, magnitudes, or performance are reported or claimed.

The earnings-date fetch uses the documented Ticker.get_earnings_dates(limit=12, offset=0) API; the mirror reference states the “Default value 12 should return next 4 quarters and last 8 quarters. Increase if more history is needed.”

# Method illustration: event-study plumbing only. No results are reported or claimed.
import numpy as np
import pandas as pd
import yfinance as yf

TICKERS = ["AAPL", "MSFT"]   # plumbing examples only — not recommendations
BENCH, EST_W, EVT_W = "SPY", (-250, -20), (-1, 60)  # trading days relative to t0

def load_returns(t):
    px  = yf.Ticker(t).history(period="5y", auto_adjust=True)["Close"].rename("stock")
    mkt = yf.Ticker(BENCH).history(period="5y", auto_adjust=True)["Close"].rename("mkt")
    return np.log(pd.concat([px, mkt], axis=1).dropna()).diff().dropna()

def event_panel(ticker, dates):
    r, rows = load_returns(ticker), []
    for d in dates:                                   # d = announcement timestamp
        ts = pd.Timestamp(d)
        if ts.tzinfo is None:
            ts = ts.tz_localize(r.index.tz)
        after_close = ts.hour >= 16                   # AMC: reaction starts next session
        t0  = r.index.searchsorted(ts.normalize(), side="right" if after_close else "left")
        if t0 + EST_W[0] < 0:
            continue                                  # not enough history for the estimation window
        est = r.iloc[t0 + EST_W[0]: t0 + EST_W[1]]    # estimation window
        win = r.iloc[t0 + EVT_W[0]: t0 + EVT_W[1] + 1]
        if len(est) < 120 or len(win) != EVT_W[1] - EVT_W[0] + 1:
            continue                                  # skip thin windows; don't patch them
        beta = np.polyfit(est["mkt"], est["stock"], 1)[0]
        ar   = win["stock"] - beta * win["mkt"]       # market-model abnormal return
        rows.append(pd.DataFrame({"ticker": ticker,
                                  "event_day": range(EVT_W[0], EVT_W[1] + 1),
                                  "ar": ar.to_numpy()}))
    if not rows:
        return pd.DataFrame(columns=["ticker", "event_day", "ar"])
    return pd.concat(rows, ignore_index=True)

panels = []
for t in TICKERS:
    ed = yf.Ticker(t).get_earnings_dates(limit=32)    # default 12 = ~next 4 + last 8 quarters
    if ed is None:
        continue
    ed = ed[ed["Reported EPS"].notna()]               # announced quarters only; verify column names per version
    ed = ed[~ed.index.normalize().duplicated()]       # one row per release date (first in returned order)
    dates = ed.index.sort_values()
    panels.append(event_panel(t, dates))

if not panels:
    raise SystemExit("no usable events")
panel = pd.concat(panels, ignore_index=True)
car = panel.groupby("event_day")["ar"].mean().cumsum()  # equal-weight mean CAR; no clustering — illustrative

What each stage does. load_returns builds aligned log returns for the stock and the benchmark so both series share an index. event_panel anchors t=0 with searchsorted: a release at or after 16:00 Eastern maps to the next session, an earlier one to the same session — the alignment rule from Step 2. It then slices a pre-event estimation window, fits a one-factor market model by ordinary least squares, and subtracts beta times market return from the event-window return to obtain abnormal returns. Windows that are too short are skipped rather than padded or forward-filled, because a silently stretched window is a silent bias.

Why dedupe is needed. The get_earnings_dates index can hold two entries for one release: the yfinance issue tracker documents a case where Yahoo lists two different March earnings times. Duplicates double-count one event and misalign its t=0. The snippet keeps one row per calendar date. That removes the double count but does not show which of two times was right, so reconcile against a second source before relying on it.

What the last line is not. The equal-weight mean CAR across events, unclustered and without any standard error, is a pedagogical convenience for plotting the skeleton — not an inference. It also does not condition on the surprise: it averages every event regardless of surprise sign, so it is a generic event-study CAR, not a PEAD estimate until events are split by surprise. There is no clustering on firm or date, no calendar-time portfolio, and no test statistic. Treat the output curve as plumbing verification, nothing more.

The Four Traps That Corrupt a PEAD Estimate

Look-ahead bias in earnings dates

Timezone handling is the first failure mode. The ts.hour >= 16 rule assumes Eastern time, the zone yfinance’s earnings index carried in the AAPL spot check; convert to Eastern before applying it if your timestamps arrive in UTC. Second, yfinance gives you reported dates, not the point-in-time consensus that drove prices on the day — yfinance does not document whether its estimate column is a frozen, point-in-time consensus. Third, the duplicate-date issue described above must be handled explicitly (see issue #1013); otherwise one release becomes two events with different t=0 anchors.

Survivorship

A ticker list pulled today consists of firms that survived to today. Delisted, renamed, and acquired firms are absent, and no adjustment after the fact restores them. Building a point-in-time universe with delisting records is a separate data task that this snippet does not perform. Until you have one, your sample is conditioned on survival, and that conditioning is a bias you cannot quantify from within the same dataset.

Overlapping events

Many firms report in the weeks after quarter-end, so their event windows fall on the same calendar dates. Their returns are correlated on those dates, which makes naive standard errors too small and significance look better than it is. Mitigations include clustering standard errors by firm and by date, non-overlapping windows, or switching to calendar-time portfolios that each month hold every stock inside its post-event window and track that portfolio’s return, so the position count varies. Any of these is preferable to treating each event as independent.

Risk adjustment is a choice, not a formality

A market-model residual is not a risk-free residual. Chan, Jegadeesh & Lakonishok report that “Market risk, size and book-to-market effects do not explain the drifts,” which is a statement about their specification — and Bernard & Thomas catalog the alternative reading under the keyword “incomplete risk adjustment.” If your risk model is misspecified, the mispricing you fail to remove masquerades as drift. The honest move is to run the same event window under at least two specifications — market model, and a multi-factor model — and report how sensitive the measured pattern is to that choice.

FAQ

Does the surprise definition really change the measured drift?

Yes, by construction. Livnat & Mendenhall compare analyst-based and time-series-based surprises and find the drift “significantly larger” with the former. A different surprise definition changes which events rank as large surprises, so the events in the sample change too. There is no definition-free estimate.

Is PEAD a market inefficiency or a risk premium?

Open in the paper’s framing. Bernard & Thomas organize the explanations into delayed price response versus risk premium; this post does not test which one holds. The distinction matters for interpretation more than for the calculation: the abnormal-return series this code computes is the same under either reading, but the two readings imply different conclusions about it.

Can I use yfinance earnings dates in a publishable event study?

For learning and prototyping, yes — the API is documented and the plumbing above can be rerun. For research, understand its limits: default history is short (the mirror of the reference notes the default of 12 returns the next four and last eight quarters), dates can duplicate, the library does not document a point-in-time consensus, and column names vary across library versions. Verify, dedupe, and cross-check against a primary source before relying on it.

What This Post Does Not Show

  • No drift magnitudes, percentage returns, t-statistics, or Sharpe values — none are reported here, and none were computed for this post.
  • No claim that this post’s author ran a backtest or tested the code hands-on; the code is a method illustration only.
  • No claim about the current size, persistence, or decay of PEAD.
  • Nothing in this post is investment advice, a trading strategy, or a ticker recommendation; the example tickers exist solely as plumbing.
← Back to all posts