phys2eventtime: Convert data from physical to event time

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/phys2eventtime.R

Description

‘phys2eventtime’ is used to convert data from physical to event time using information on events identified by the user.

Usage

1
phys2eventtime(z, events, width = 10)

Arguments

z

an object of class zoo or xts containing data to be converted into event time.

events

‘data.frame’ containing event identifiers. See ‘Details’.

width

an ‘integer’ specifying the event window within which data should be available to consider the outcome a 'success'. See ‘Details’.

Details

“events” object contains two columns: “name” consists of names of the event, and “when” is the respective event time. ‘class’ of ‘index’ of “z” and “when” should be same and one of the ‘date-time’ or ‘Date’ classes.

If an event date does not lie within the index of “z”, the function approximates to the nearest previous time using findInterval. Note that ‘findInterval’ assumes the index of ‘z’ is non-decreasing.

The argument “width” provides the user with an option to define successful events as those that have data within a window around the event. Window is defined as (-width, +width]. If “width” is 10 periods, those events with ‘NA’ within 10 periods before and after the event will be classified as “wdatamissing”, otherwise, the event “outcome” will be classified as “success”.

Currently this function requires “z” to have at least one column. It relies on ‘colnames’ of “z” for the series names, and matches it with the “events” object. One can use drop = FALSE with ‘[’ to achieve a single-column object.

Value

Returns a ‘list’ of two elements:

z.e

a zoo object containing data of successful events indexed with event time; “NULL” if there are no “success” in “outcomes”. ‘colnames’ of z.e are event numbers: row numbers of “events”.

outcomes

a character vector with outcome definition for each event.

Author(s)

Ajay Shah, Chirag Anand, Vikram Bahure, Vimal Balasubramaniam

See Also

findInterval

Examples

1
2
3
4
5
6
7
8
data(StockPriceReturns)
data(SplitDates)

result <- phys2eventtime(z = StockPriceReturns,
			 events = SplitDates,
			 width = 5)
print(result$z.e[as.character(-4:5)])
print(SplitDates[result$outcomes == "success", ])

Example output

Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: xts
            6          9         16         20         21         22
-4 -0.2635099 -0.3004760  0.5629614 -3.0258588  1.5792919  1.1497857
-3 -1.3716502  0.2371173  0.9424506  0.5193065  0.4169659  0.2203747
-2 -1.7308663 -0.8004330 -0.3120441  1.7712952  2.5546961 -2.3282760
-1  1.4252498  1.2530655  0.2986429  0.1056827 -3.2658856  1.3630564
0   0.5490435  3.0914034 -5.7438321  0.3997019 -4.2263578 -1.8147098
1   0.6108995  3.6200902 -2.5154039 -2.1377565 -4.7203309  3.8349805
2   1.0553156 -0.6854677 -0.3645647  0.6250020  2.0202707 -0.3968259
3  -0.7023049 -1.7424653  1.3603184 -0.1447420  5.8599870  1.6757415
4  -1.5686209 -0.5583042  0.7358913 -0.1895947  6.7800897 -2.5743996
5  -1.3111332 -0.9078920  1.1203105  1.0328261 -0.2166848 -2.6939367
                 name       when
6           HDFC.Bank 2011-07-14
9                HDFC 2010-08-18
16               ONGC 2011-02-08
20 Sun.Pharmaceutical 2010-11-25
21        Tata.Motors 2011-09-12
22         Tata.Power 2011-09-26

eventstudies documentation built on July 1, 2020, 10:26 p.m.