‘phys2eventtime’ is used to convert data from physical to event time using information on events identified by the user.
phys2eventtime(z, events, width = 10)
an object of class zoo or xts containing data to be converted into event time.
‘data.frame’ containing event identifiers. See ‘Details’.
an ‘integer’ specifying the event window within which data should be available to consider the outcome a 'success'. See ‘Details’.
Returns a ‘list’ of two elements:
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”.
a character vector with outcome definition for each event.
“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.
# NOT RUN {
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", ])
# }
Run the code above in your browser using DataLab