# Introduction to estudy2

#### Iegor Rudnytskyi

#### 2021-08-16

## 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:

- Select companies of interest

- Select dates of the event and the estimation periods

- Obtain prices of companies’ stocks

- Compute rates of return

- Fit a market model to the data

- Test the expected returns against observed returns of companies

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:

- `get_prices_from_tickers` returns daily prices for given tickers

- `get_rates_from_prices` computes rates of returns from prices

- `apply_market_model` fits a market model to rates of returns data

- `parametric_tests` and `nonparametric_tests` performs parametric and nonparametric tests, respectively

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 9/11 terrorist attacks on World Trading Center on eight European insurance companies.

## Obtaining prices of companies’ stocks

We select eight European insurance companies, tickers of which are listed in the code snippet below. The starting and ending date are set to `"2000-01-01"` and `"2002-01-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("ALV.DE", "CS.PA", "G.MI", "HNR1.HA", "HSX.L", "MUV2.DE", "TOP.CO")
    prices <- get_prices_from_tickers(tickers,
                                      start = as.Date("2000-01-01"),
                                      end = as.Date("2002-01-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("^N100",
                                           start = as.Date("2000-01-01"),
                                           end = as.Date("2002-01-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("2001-03-26"),
        estimation_end = as.Date("2001-09-10")
    )

## 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("2001-09-11"),
                     event_end = as.Date("2001-09-28"))
    #>          date   weekday percentage         mean bw_1980_stat bw_1980_signif
    #> 1  2001-09-11   Tuesday        100 -0.095267547  -14.1375931            ***
    #> 2  2001-09-12 Wednesday        100 -0.031384102   -4.6573643            ***
    #> 3  2001-09-13  Thursday          0           NA           NA
    #> 4  2001-09-14    Friday        100 -0.037994921   -5.6384021            ***
    #> 5  2001-09-17    Monday        100  0.023717979    3.5197204            ***
    #> 6  2001-09-18   Tuesday        100 -0.004574035   -0.6787815
    #> 7  2001-09-19 Wednesday        100 -0.004380471   -0.6500568
    #> 8  2001-09-20  Thursday        100 -0.097628194  -14.4879104            ***
    #> 9  2001-09-21    Friday        100 -0.039622894   -5.8799914            ***
    #> 10 2001-09-24    Monday        100  0.031556552    4.6829556            ***
    #> 11 2001-09-25   Tuesday        100  0.041640460    6.1793958            ***
    #> 12 2001-09-26 Wednesday        100  0.022896229    3.3977737            ***
    #> 13 2001-09-27  Thursday        100  0.020423192    3.0307779            ***
    #> 14 2001-09-28    Friday        100  0.005078339    0.7536195
    #>    bw_1985_stat bw_1985_signif t_test_stat t_test_signif      pt_stat pt_signif
    #> 1   -12.8932767            ***  -4.8342919           *** -15.93199210       ***
    #> 2    -4.2474476            ***  -1.0197160                -3.02501512       ***
    #> 3            NA                         NA                         NA
    #> 4    -5.1421397            ***  -1.3785596                -6.04629140       ***
    #> 5     3.2099332            ***   0.9005395                 4.87549214       ***
    #> 6    -0.6190387                 -0.1608414                -0.72885915
    #> 7    -0.5928423                 -0.2072312                -0.01540181
    #> 8   -13.2127608            ***  -2.3475394             * -13.28950663       ***
    #> 9    -5.3624656            ***  -2.5106293            **  -6.18660223       ***
    #> 10    4.2707865            ***   1.8657907                 4.66791310       ***
    #> 11    5.6355179            ***   1.9867341             *   6.22810566       ***
    #> 12    3.0987196            ***   4.3498111           ***   3.48075345       ***
    #> 13    2.7640248            ***   1.8165741                 3.32642949       ***
    #> 14    0.6872899                  1.1444937                 1.02097492
    #>         bh_stat bh_signif    lmb_stat lmb_signif
    #> 1  -4.033246415       *** -12.8350529        ***
    #> 2  -0.757624918            -4.2061350        ***
    #> 3            NA                    NA
    #> 4  -1.443639802            -4.8579285        ***
    #> 5   1.271626024             3.1953793        ***
    #> 6  -0.159962572            -0.6010351
    #> 7  -0.005548115            -0.5838091
    #> 8  -2.800280643        ** -12.4856495        ***
    #> 9  -2.298184877         *  -5.2306013        ***
    #> 10  1.809375759             3.8950964        ***
    #> 11  2.231357971         *   5.5638463        ***
    #> 12  5.554167758       ***   3.0612478        ***
    #> 13  1.953042855         *   2.7451289        ***
    #> 14  1.228737963             0.6708057

    nonparametric_tests(list_of_returns = securities_returns,
                        event_start = as.Date("2001-09-11"),
                        event_end = as.Date("2001-09-28"))
    #>          date   weekday percentage  sign_stat sign_signif gsign_stat
    #> 1  2001-09-11   Tuesday        100 -2.6457513         *** -2.5877375
    #> 2  2001-09-12 Wednesday        100 -1.1338934             -1.0755080
    #> 3  2001-09-13  Thursday          0         NA                     NA
    #> 4  2001-09-14    Friday        100 -1.1338934             -1.0755080
    #> 5  2001-09-17    Monday        100  1.1338934              1.1928362
    #> 6  2001-09-18   Tuesday        100  0.3779645              0.4367214
    #> 7  2001-09-19 Wednesday        100 -0.3779645             -0.3193933
    #> 8  2001-09-20  Thursday        100 -2.6457513         *** -2.5877375
    #> 9  2001-09-21    Friday        100 -1.1338934             -1.0755080
    #> 10 2001-09-24    Monday        100  1.8898224           *  1.9489509
    #> 11 2001-09-25   Tuesday        100  0.3779645              0.4367214
    #> 12 2001-09-26 Wednesday        100  2.6457513         ***  2.7050657
    #> 13 2001-09-27  Thursday        100  1.1338934              1.1928362
    #> 14 2001-09-28    Friday        100 -0.3779645             -0.3193933
    #>    gsign_signif csign_stat csign_signif  rank_stat rank_signif mrank_stat
    #> 1           *** -2.2292016           ** -3.4115930         *** -3.4115930
    #> 2               -0.9553721              -1.0640921             -1.0640921
    #> 3                       NA                      NA                     NA
    #> 4               -0.9553721              -1.6083224             -1.6083224
    #> 5                0.9553721               1.1128291              1.1128291
    #> 6                0.3184574               0.6741958              0.6741958
    #> 7               -0.3184574              -0.2274395             -0.2274395
    #> 8           *** -2.2292016           ** -3.4115930         *** -3.4115930
    #> 9               -0.9553721              -1.7707792           * -1.7707792
    #> 10            *  1.5922868               2.2987639          **  2.2987639
    #> 11               0.3184574               1.3808829              1.3808829
    #> 12          ***  2.2292016           **  2.7211516         ***  2.7211516
    #> 13               0.6369147               1.4296199              1.4296199
    #> 14              -0.3184574               0.5604760              0.5604760
    #>    mrank_signif wlcx_stat wlcx_signif
    #> 1           ***         0         ***
    #> 2                       9
    #> 3                      NA
    #> 4                       5
    #> 5                      20
    #> 6                      16
    #> 7                      12
    #> 8           ***         0         ***
    #> 9             *         3          **
    #> 10           **        22           *
    #> 11                     22           *
    #> 12          ***        28         ***
    #> 13                     23           *
    #> 14                     18

## 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("^N100",
                                          start = as.Date("2000-01-01"),
                                          end = as.Date("2002-01-01"),
                                          quote = "Close",
                                          retclass = "zoo") %>%
        get_rates_from_prices(quote = "Close",
                              multi_day = TRUE,
                              compounding = "continuous")

    tickers <- c("ALV.DE", "CS.PA", "G.MI", "HNR1.HA", "HSX.L", "MUV2.DE", "TOP.CO")

    nine_eleven_param <- get_prices_from_tickers(tickers,
                                                 start = as.Date("2000-01-01"),
                                                 end = as.Date("2002-01-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("2001-03-26"),
                           estimation_end = as.Date("2001-09-10")) %>%
        parametric_tests(event_start = as.Date("2001-09-11"),
                         event_end = as.Date("2001-09-28"))