knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE )
The provided sample data and request files serve as an example to demonstrate the functionality of the EventStudyTools R-package.
These files contain data related to the addition of several well-known firms to the S&P 500 index during the late 1990s. Using this data, the R package helps you examine whether a company's stock value increases upon being added to the S&P 500 index. This research question has been previously addressed, such as in a 1997 study by Anthony W. Lynch and Richard R. Mendenhall, which found a positive effect of approximately 3.8% from the day after the announcement to the day before the effective date of the change.
With our R-package, you can conveniently explore this and similar research questions.
For performing an Event Study with our API you need:
http://api.eventstudytools.com
)You get an API key from our website EventStudyTools. In the first step we need to authenticate to the web API. There are three ways to handle this two parameters:
library(readr) library(EventStudy) apiUrl <- "http://api.eventstudytools.com" apiKey <- "Please insert your key here"
Option 1 and 2: You can save API key and URL in the options
object
# The URL is already set by default # options(EventStudy.URL = apiUrl) options(EventStudy.KEY = apiKey) # use EventStudy estAPIKey function estAPIKey(apiKey) # initialize object estSetup <- EventStudyAPI$new()
Option 2: Set the API Key and URL directly during the EventStudyAPI
R6-class
initialization
# Setup API Connection estSetup <- EventStudyAPI$new(apiUrl) estSetup$authentication(apiKey)
This API package is designed to conduct all analyses available on our website while allowing for the customization of all parameters. You can either set every parameter in R (details provided later) or perform a quick Event Study using default parameters, giving you flexibility and control over your analysis.
Our API offers different types of Event Studies:
arc
avc
avyc
Default parameters for all type of above Event Studies are:
arc
and avc
and GARCH(1, 1) Model for avyc
csv
log
later
The type of Event Study can be set by parameter:
estType <- "arc"
By default all data files must be named as follows. Furthermore, they have to be in the current directory:
01_RequestFile.csv
02_firmData.csv
03_MarketData.csv
You are also able to set custom file names and paths by defining it in a named vector:
dataFiles <- c("request_file" = "01_RequestFile.csv", "firm_data" = "02_firmData.csv", "market_data" = "03_MarketData.csv")
All results will be written by default into the directory ./results
. You can easily change this path by setting it as a parameter:
resultPath <- "results"
Attention
If the resultPath
do not exist, the R package will create this directory.
Finally, the Event Study is performed by:
estResult <- estSetup$performDefaultEventStudy(estType = estType, dataFiles = dataFiles, destDir = resultPath)
It will write all result files into the result directory. Furthermore, results will be parsed into a R object.
For performing an Event Study we need three files (file names can be chosen arbitrarily):
All files must be saved without header, semi-colon separated and dates has to be in following format: 30.04.1997. In next section we will describe the file structure based on the S&P 500 example Event Study more detailed. You always find more information (if necessary) on our website: EventStudyTools..
We added the S&P 500 example Event Study to this package. The three above mentioned files can be generated by following command:
getSP500ExampleFiles()
We named the request and data files in following manner:
01_RequestFile.csv
02_FirmData.csv
03_MarketData.csv
01_RequestFile.csv
{#event-definitions-01_requestfile.csv}This CSV file contains the event definitions and consists of 9 columns. The order must follow the sequence below, as the columns are unnamed in the CSV.
30.04.1997
]: Date of the eventIn the example below, we have an event window of [-2, 2] (an event window of length 5), an estimation window of length 120, and the estimation window ending 11 days before the event.
df <- read_delim("01_RequestFile.csv", col_names = F, delim = ";") names(df) <- c("Event ID", "Firm ID", "Market ID", "Event Date", "Grouping Variable", "Start Event Window", "End Event Window", "End of Estimation Window", "Estimation Window Length") knitr::kable(head(df), pad=0)
Attention
The first column (Event IDs) must be unique and numeric.
02_FirmData.csv
{#firm-data-02_firmdata.csv}The stock data for each firm defined in the request file. It contains 3 columns.
30.04.1997
]: Date of the closing price.The following table shows the first 20
entries of our example firm data.
library(readr) df <- readr::read_delim("02_FirmData.csv", col_names = F, delim = ";") names(df) <- c("Firm ID", "Date", "Closing Price") knitr::kable(head(df))
03_MarketData.csv
{#firm-data-03_marketdata.csv}This file is similary structured as 02_FirmData.csv
:
30.04.1997
]: Date of the closing price.The following table shows the first 20
entries of our example firm data.
library(readr) df <- readr::read_delim("03_MarketData.csv", col_names = F, delim = ";") names(df) <- c("Market ID", "Date", "Closing Price") knitr::kable(head(df))
You are also able to apply a Fama-French 3-Factor Model or a Fama-French Momentum-4-Factor Model. This will change the necessary data you need for performing an Event Study (e.g. by adding Fama-French Factors). You find more information at https://www.eventstudytools.com/instructions-axc.
Please cite our work in your publication.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.