finds.backtesting.eventstudy

Evaluate event studies

  • Event studies: cumulative abnormal returns

Copyright 2022, Terence Lim

MIT License

class finds.backtesting.eventstudy.EventStudy(sql: SQL, bench: Benchmarks, stocks: Stocks, max_date: int, table: str = 'events')[source]

Bases: Structured

Class to support statistical tests of event studies

Parameters:
  • sql – connection to user database to store results

  • bench – Benchmark dataset of index returns for market adjustment

  • stocks – Stocks structured dataset containing stock returns

  • max_date – last date to run event study

  • table – physical name of table in user database to append summary results

__call__(label: str, df: DataFrame, left: int, right: int, post: int, date_field: str) DataFrame[source]

Construct event window market-adjusted returns where valid/available

Parameters:
  • label – Unique label (used for graph labels and table name)

  • df – Input DataFrame of stock identifiers and event dates

  • left – Start (inclusive) of announcement window around event date

  • right – End (inclusive) of announcement window around event date

  • post – End (inclusive) post-drift period

  • date_field – Name of date column in df

Notes: - populates ‘car’ attribute with cumulative arithmetic abnormal returns - populates ‘bhar’ attribute with abnormal cumulative product returns

fit(model: str = 'scar', rows: List[int] = [], rho: float | None = None) Dict[str, Dict][source]

Compute car, or bhar, and summary statistics of selected rows

Parameters:
  • model – name of predefined model to compute summary statistics

  • rows – Subset of rows to evaluate; empty list selects all rows

  • car – Whether to evaluate CAR (True) or BHAR (False)

  • rho – Average cross correlation of event returns. If None, then compute from max convolution of post-announcement returns

Returns:

Dict of summary statistics of full and subsamples

  • ’window’, ‘window-tvalue’ are CAR at end of event window

  • ’post’, ‘post-tvalue’ are CAR from event end till post-drift end

  • ’car’, ‘car-stderr’ are daily CAR from beginning of announcement

  • ’rows’ is number of input rows

  • ’days’ is number of unique dates (same announce dates are grouped)

  • ’effective’ is the number of days after correlation effects

TODO names of models:

  • “car” or “bhar”

  • unstandardized or ‘s’tandardized or ‘adj-s’tandardized (simple rho) or ‘conv-s’tandardized (with average rho from convolution max)

Notes:

  • Kolari and Pynnonen (2010) eqn[3] cross-sectionally adjusted Patell or BMP with avg correlation: multiply variance by 1 + (p*(n-1))

  • Kolari, Pape, Pynnonen (2018) eqn[15] adjusted by average overlap (tau) and average covariance ratio (correlation rho)

plot(model: str, drift: bool = False, ax: Any = None, loc: str = 'best', title: str = '', c: str = 'C0', vline: List[float] = [], fontsize: int = 10, hline: List[float] = [], width: float = 1.96)[source]

Plot cumulative abnormal returns, drift and confidence bands

Parameters:
  • model – Name of model to plot computed results

  • drift – Whether to start confidence bands at post-event drift start

  • ax – Axes to plot

  • loc – Legend location

  • title – Main title

  • c – Color

  • vline – List of x-axis points to plot vertical line

  • hline – List of y-axis points to plot horizontal line

  • width – Number of std errs for confidence bands

  • fontsize – Base font size

read(left: int, right: int, post: int) DataFrame[source]

Fetch daily cumulative abnormal returns series from user table

Parameters:
  • label – name suffix of table to retrieve from

  • left – offset of left announcement window

  • right – offet of right announcement window

  • post – offset of right post-announcement window

Returns:

DataFrame of car and bhar daily cumulative returns

read_summary(label: str = '', model: str = '')[source]

Load event study summary from database

Parameters:
  • label – Name of event to retrieve; if blank, retrieve all events

  • model – Name of model to retrieve; if blank, retrieve all models

Returns:

DataFrame of rows written

write() int[source]

Store daily cumulative returns in new user table

write_summary(overwrite=True) DataFrame[source]

Save event study summary to database

Parameters:

overwrite – Whether to overwrite, else append rows

Returns:

DataFrame of rows written