Skip to main content

A package to conduct financial event study with few lines of code.

Project description

Easy-Event-Study

Open In Colab

Conduct financial event-study in just few lines of Python code.

What you need to provide is just a dataframe with events (ticker, event_date) - the rest leave to the Easy-Event-Study that will automatically:

  1. load and create returns time-series for the specified tickers
  2. load factors for the specified estimation model
  3. estimate abnormal returns for each event in the study
  4. provide the statistics table for each event with estimate AR and CAR
  5. plot mean cumulitative abnormal returns with specified confidence level.

image

Example of the event study output

Installation

The package could be easily installed with pip:

pip install easy_es

Usage

In order to use the library, one needs to provide a dataframe with events with just 2 columns:

  • ticker - ticker name
  • event_date - date to consider as the event for the specified ticker
from easy_es import EventStudy
from easy_es.utils import plot_mean_car, calculate_car_stats

# Event file should have 2 columns: ticker and event_date
events = pd.read_csv('events_df.csv')

event_study = EventStudy(
    estimation_days=255,
    gap_days=50,
    window_after=10,
    window_before=10,
    min_estimation_days=100,
    estimator_type='ff3',
    n_cores=1   # Number of CPU cores to use in processing. Usefull when there are many events
)
event_res_df = event_study.run_study(events_df)

# Get overall CAR stats with p-values
calculate_car_stats(event_res_df=event_res_df, critical_value=0.95)

# Plot mean effect with confidence levels
plot_mean_car(event_res_df=event_res_df, critical_value=0.95)

One could also plot the results of two event studies on the same graph, using:

from easy_es.utils import plot_joint_mean_car

event_res_increase = event_study.run_study(events_df_increase)
event_res_decrease = event_study.run_study(events_df_decrease)

plot_joint_mean_car(
    event_res_increase, 
    event_res_decrease, 
    name_one='Increase', 
    name_two='Decrease'
)

image

Example of a joint mean CAR plot

Factors data

All daily factors are downloaded for the official Fama-French data library.

Returns data

Under the hood, Easy-Event-Study loads the returns data for the specified tickers and time-period using yfinance package.

Note: loading of returns might take a while depending on the size of the event-study. For example, for 400 tickers and 10 years - it takes around 10 mins.

Pre-loading the returns

Sometimes one needs to test several hypothesis with different combination of events. In order not to waste time on loading the returns data on every execution, one could do the following prior step before run_study:

## Load the returns. Dates should cover estimation and event windows
event_study.add_returns(
    list_of_tickers=events_df['ticker'].unique(),
    min_date='2010-01-01',  # Select min date to load returns from 
    max_date='2023-01-01'   # Select max date to load returns until
)

## Get event study result for two different subsets of events. 
event_res_one_df = event_study.run_study(events_df.head(100))
event_res_two_df = event_study.run_study(events_df.tail(100))

Dumping and re-loading the returns

One could also dump the returns and load it back for the future executions:

## Load the returns. Dates should cover estimation and event windows
event_study.add_returns(
    list_of_tickers=events_df['ticker'].unique(),
    min_date='2010-01-01',  # Select min date to load returns from 
    max_date='2023-01-01'   # Select max date to load returns until
)

event_study.returns_df.to_csv('returns_df.csv', index=False)

## Then load it back to the model in the future
event_study.add_returns(
    ret_df = pd.read_csv('returns_df.csv')
)

Methodology

image

Methodology schema

For each event, define:
  1. Estimation Period - when the parameters for the selected counterfactual model will be estimated.
  2. Gap Period - number of days to skip after estimation period
  3. Event window boundaries - number of days before and after an event to use in the calculations

Fit a selected model to estimate normal returns during the estimation period, and then construct abnormal returns (actual returns - normal return) during the event window.

Implemented models to estimate normal returns are:

  1. CAPM - $Ret_{i, t} = \alpha + \beta * (MktRet_{t} - RF_{t})$, where

    • $Ret_{i,t}$ - Return of company $i$ on day $t$.

    • $MktRet_{t}$ - Market return on day $t$.

    • $RF_{t}$ - Risk free rate on day $t$.

  2. Fama-French 3 factor model (aka FF3) - $Ret_{i, t} = \alpha + \beta * (MktRet_{t} - RF_{t}) + \gamma * SMB_{t} + \theta * HML_{t}$, where

    • $Ret_{i,t}$ - Return of company $i$ on day $t$

    • $MktRet_{t}$ - Market return on day $t$.

    • $RF_{t}$ - Risk free rate on day $t$.

    • $SMB_{t}$ - Small minus Big factor on day $t$.

    • $HML_{t}$ - High minus Low factor on day $t$.

  3. Fama-French 5 factor model (aka FF5) - $Ret_{i, t} = \alpha + \beta * (MktRet_{t} - RF_{t}) + \gamma * SMB_{t} + \theta * HML_{t} + \delta * CMA_{t} + \phi * RMW_{t}$, where

    • $Ret_{i,t}$ - Return of company $i$ on day $t$

    • $MktRet_{t}$ - Market return on day $t$.

    • $RF_{t}$ - Risk free rate on day $t$.

    • $SMB_{t}$ - Small minus Big factor on day $t$.

    • $HML_{t}$ - High minus Low factor on day $t$.

    • $CMA_{t}$ - Conservative Minus Aggressive factor on day $t$.

    • $RMW_{t}$ - Robust Minus Weak factor on day $t$.

  4. Market-Adjusted model (aka MAM) - $Ret_{i, t} = MktRet_{t}$, where

    • $Ret_{i,t}$ - Return of company $i$ on day $t$

    • $MktRet_{t}$ - Market return on day $t$.

Tests

To run the tests, run the following:

pytest tests/tests.py

The ground truth is obtained from an external EventStudy tool to verify that the difference between the results is close to zero.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy_event_study-0.1.3.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_event_study-0.1.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file easy_event_study-0.1.3.tar.gz.

File metadata

  • Download URL: easy_event_study-0.1.3.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for easy_event_study-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e41fabbb53fd6488384d21daee3e9f6337aa0642e0e56aaef5d488ccfbed7f48
MD5 240cc09a9c2ca6917c6d9f3972753955
BLAKE2b-256 73b23aba1824c56f8ec44072cda7c33c18cafb0d3a03d2dcd67061d63ad71bd5

See more details on using hashes here.

File details

Details for the file easy_event_study-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for easy_event_study-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d3acd6281830f38ef77a1ade1234a13345f4625c39a747fcfc5401ddd5da3c88
MD5 e2ddf1f060d0d08372453eed6ed4a4b4
BLAKE2b-256 07a8eb92b6f3dd2cddc68079dccb3f590f37cc8a036d78a93c80b5264df18b5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page