Coder Social home page Coder Social logo

sipemu / eventstudy Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 150 KB

Event Study package is an open-source R project created to facilitate the computation of financial event study analysis.

Home Page: https://eventstudy.de/

License: GNU Affero General Public License v3.0

R 100.00%
eventstudy

eventstudy's Introduction

Event Study Analysis in R

Package is under active development! The API may change

Installation

CRAN

Not deployed yet.

GITHUB

install.packages("devtools")
devtools::install_github("sipemu/eventstudy")

Features

The EventStudy package includes several features that make it a versatile tool for performing event study analyses:

  • Flexible Models and Diagnostic Tests: You can apply standard models and perform diagnostic tests on them. The package is modular and adaptable, so you can easily extend it with your own models and tests.

  • Custom Models: With EventStudy, you can apply your market model. This means you can include external factors in your model that are specific to your study or industry.

  • Custom Test Statistics: You can apply your test statistics for abnormal returns (AR), average abnormal returns (AAR), cumulative abnormal returns (CAR), and cumulative average abnormal returns (CAAR). This gives you full control over how you want to measure the event's impact.

  • Result Extraction: You can extract the event study results for further analysis. For example, you might want to perform Cross-Sectional regression analysis. The package provides convenient functions for extracting confidence bands at each level and for each CAR and CAAR window.

  • Parallel Execution: If you are dealing with many events, the package supports parallel execution. This allows you to fully use your computer's processing power to speed up the calculations.

Implementation Status

Test Statistics

Single Firm:

  • T test for abnormal returns: $H_0: E[AR_{i, t}] = 0$
  • T test for cumulative abnormal return: $H_0: E[CAR_{i, t}] = 0$

Multiple Firms:

  • Cross-Sectional T Test $H_0: E[AAR_{t}] = 0$ and $H_0: E[CAAR] = 0$
  • Patell Z Test $H_0: E[AAR_{t}] = 0$ and $H_0: E[CAAR] = 0$

Example: Dieselgate

This example demonstrates using the EventStudy package by conducting an event study analysis of the "Dieselgate" scandal. The scandal erupted in 2015 and involved Volkswagen's admission that it had installed software on its diesel cars to cheat on emissions tests. This significant event substantially affected the stock prices of Volkswagen and other automotive companies.

The following code will guide you through performing an event study analysis, from the initial setup to the results extraction.

Initialisation

The first step is to load the necessary packages and data. This includes market data for the companies of interest and the index during the event study period.

library(tidyquant)
library(dplyr)
library(purrr)
library(readr)
library(DT)

library(EventStudy)

index_symbol = c("^GDAXI")
firm_symbols = c("VOW.DE", "PAH3.DE", "BMW.DE", "MBG.DE")

group <- c(rep("VW Group", 2), rep("Other", 2))
request_tbl <- cbind(c(1:4), firm_symbols, rep(index_symbol, 4), 
                     rep("18.09.2015", 4), 
                     group, rep(-10, 4), rep(10, 4), rep(-11, 4), rep(250, 4)) %>% 
  as_tibble()

names(request_tbl) <- c("event_id", "firm_symbol", "index_symbol", "event_date", 
                        "group", "event_window_start", "event_window_end", 
                        "shift_estimation_window", "estimation_window_length")

firm_symbols %>%
  tidyquant::tq_get(from = "2014-06-01", to = "2015-11-01") %>%
  dplyr::mutate(date = format(date, "%d.%m.%Y")) %>%
  dplyr::select(symbol, date, adjusted) -> firm_tbl

index_symbol %>%
  tidyquant::tq_get(from = "2014-06-01", to = "2015-11-01") %>%
  dplyr::mutate(date = format(date, "%d.%m.%Y")) %>%
  dplyr::select(symbol, date, adjusted) -> index_tbl

Finally, we define the data object used in the Event Study.

est_data = EventStudyTask$new(firm_tbl, index_tbl, request_tbl)

Define the Event Study

Next, we define the event study. This involves specifying the return calculation method, the market model, and the test statistics. We use logarithmic returns, the market model, and the default AR and CAR T-Tests in this example.

Define Parameters: Return calculation and test statistics

# Parametrization of the Event Study
log_return = LogReturn$new()
market_model = MarketModel$new()
# Define single-event test statistics
# Per default, AR and CAR T-tests are applied
single_event_tests = SingleEventStatisticsSet$new()
multiple_event_tests = MultiEventStatisticsSet$new()
# Setup parameter set
est_params = ParameterSet$new(return_calculation      = log_return, 
                             return_model            = market_model,
                             single_event_statistics = single_event_tests,
                             multi_event_statistics  = multiple_event_tests)

Execute the Event Study

Now, with everything set up, we can execute the event study. This involves preparing the event study, fitting the model, and calculating the statistics.

Step 1: Calculate returns

est_task = prepare_event_study(est_data, est_params)

Step 2: Fit the statistical model

est_task = fit_model(est_task, param_set)

Step 3: Calculate test statistics

est_task = calculate_statistics(est_task, param_set)

Extract Results

Finally, after the event study has been executed, we can extract and visualize the results. In this case, we plot the cumulative abnormal return (CAR) for the first event ID. The shaded area represents the confidence interval around the CAR.

library(ggplot2)
library(ggdist)

# Plot CAR statistic for the first event ID
est_task$data_tbl$CART[[1]] %>% 
  ggplot(aes(x=relative_index, y=car)) +
  stat_lineribbon(
    aes(ydist = car_t_dist),
    alpha = 1/2
  ) +
  scale_fill_brewer(palette = "Set2")

This example demonstrates the primary usage of the EventStudy package. However, the package is designed to be flexible and can be customized to suit different use cases. Refer to the package documentation for more detailed information on using the various features of the EventStudy package.

Roadmap

  1. Export results to Excel.
  2. Validation of statistics and models.
  3. CRAN readiness
  4. Diagnostics and resilient code.
  5. Tests, tests, tests, ...
  6. Create vignettes for
  • add custom models
  • add custom test statistics
  • extract results according to different research needs.
  1. More test statistics.
  2. Long-term Event Study.
  3. Volatility and volume Event Study with test statistics.
  4. Intraday Event Study

eventstudy's People

Contributors

sipemu avatar sm-datazoo avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.