knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

The estduy2 package is an implementation of an event study methodology. The event study is a statistical toolbox that allows examining the impact of certain events on the stock valuation of companies. The idea of the event study is to compare the market valuation of companies during an event-free period (called the estimation period) and a period when an event happened (the event period).

In order to complete a full event study one has to:

The estudy2 package provides a set of functions to cover these steps. Functions' names are self-explanatory and functions should be called consecutively in the following order:

The package is designed to work with one of the data types, namely zoo, list, or data.frame depending on user preference.

The purpose of this vignette is to provide a brief introduction of how to use this package. The illustrative example is the analysis of the impact of the COVID-19 lockdown introduction on seven companies, which could profit from it.

Obtaining prices of companies' stocks

We select seven companies that could profit from COVID-19 lockdown, tickers of which are listed in the code snippet below. The starting and ending date are set to "2019-04-01" and "2020-04-01", respectively, in order to include both the estimation and the event periods. Then, prices of securities should be downloaded. The function get_prices_from_tickers downloads prices for companies' tickers between start and end date. Under the hood, this function is a wrapper around get.hist.quote from tseries. The function can return either Open or Close quote (quote argument). Also one has to choose the returning class among "list", "zoo", and "data.frame". Further in the vignette we use zoo objects. We download historical prices of companies with:

library(estudy2)
tickers <- c("AMZN", "ZM", "UBER", "NFLX", "SHOP", "FB", "UPWK")
prices <- get_prices_from_tickers(tickers, 
                                  start = as.Date("2019-04-01"),
                                  end = as.Date("2020-04-01"),
                                  quote = "Close",
                                  retclass = "zoo")

For using a single-index market model we also need to download prices of an index (proxy):

prices_indx <- get_prices_from_tickers("^GSPC",
                                       start = as.Date("2019-04-01"),
                                       end = as.Date("2020-04-01"),
                                       quote = "Close",
                                       retclass = "zoo")

Computing rates of returns from prices

Now we need to compute rates of returns form companies' prices. For this purpose the function get_rates_from_prices is used, which is an S3 generic function dispatched on prices argument allowing for list, zoo, and data.frame (the same classes which get_prices_from_tickers returns). The function computes rates of returns of given prices using either continuous or discrete compounding depending on compounding argument value. Furthermore, setting multi_day to TRUE allows for rates of returns between non-consecutive days (for instance, Friday - Monday rate of return). We calculate rates of returns of companies and the index by:

rates <- get_rates_from_prices(prices,
                               quote = "Close",
                               multi_day = TRUE,
                               compounding = "continuous")

rates_indx <- get_rates_from_prices(prices_indx, 
                                    quote = "Close",
                                    multi_day = TRUE,
                                    compounding = "continuous")

Applying a market model

To calculate expected rates of returns during the event period we need to train a market model based on date from the estimation period. apply_market_model goes over each company (column) in rates and calibrates a chosen model. The function returns a list of S3 returns class objects, which can be passed to parametric_tests and nonparametric_tests. For our case we use the single-index market model:

securities_returns <- apply_market_model(
  rates = rates,
  regressor = rates_indx,
  same_regressor_for_all = TRUE,
  market_model = "sim",
  estimation_method = "ols",
  estimation_start = as.Date("2019-04-01"),
  estimation_end = as.Date("2020-03-13")
)

Tests

The event study utilizes both parametric and nonparametric tests. Parametric tests are Brown and Warner (1980), Brown and Warner (1985), t-test, Patell (1976), Boehmer (1991), and Lamb (1995) tests. To avoid calling all these tests separately, one can call parametric_tests with all = TRUE. The same applies to nonparametric tests, i.e. simple binomial sign, binomial sign, Corrado (1992), rank, modified rank, and Wilcoxon signed rank tests can be called all at once by specifying all = TRUE in nonparametric_tests. These tests are also available separately. Both functions return data frames with statistics and significance for each date in the event period. See ?parametric_tests and ?nonparametric_tests for references and more details.

parametric_tests(list_of_returns = securities_returns,
                 event_start = as.Date("2020-03-16"),
                 event_end = as.Date("2020-03-20"))

nonparametric_tests(list_of_returns = securities_returns,
                    event_start = as.Date("2020-03-16"),
                    event_end = as.Date("2020-03-20"))

Using magrittr

One can notice that the result of the previous function is passed to the next function. In order to avoid naming all the intermediate objects or using a function composition, it possible to utilize a power of the pipe operator from magrittr. The above code can be rewritten with:

library(magrittr)

rates_indx <- get_prices_from_tickers("^GSPC",
                                      start = as.Date("2019-04-01"),
                                      end = as.Date("2020-04-01"),
                                      quote = "Close",
                                      retclass = "zoo") %>%
  get_rates_from_prices(quote = "Close",
                        multi_day = TRUE,
                        compounding = "continuous")

tickers <- c("AMZN", "ZM", "UBER", "NFLX", "SHOP", "FB", "UPWK")

param_tests <- get_prices_from_tickers(tickers,
                                             start = as.Date("2019-04-01"),
                                             end = as.Date("2020-04-01"),
                                             quote = "Close",
                                             retclass = "zoo") %>%
  get_rates_from_prices(quote = "Close",
                        multi_day = TRUE,
                        compounding = "continuous") %>%
  apply_market_model(regressor = rates_indx,
                     same_regressor_for_all = TRUE,
                     market_model = "sim",
                     estimation_method = "ols",
                     estimation_start = as.Date("2019-04-01"),
                     estimation_end = as.Date("2020-03-13")) %>%
  parametric_tests(event_start = as.Date("2020-03-16"),
                   event_end = as.Date("2020-03-20"))


irudnyts/estudy2 documentation built on April 21, 2022, 10:50 p.m.