From noreply at r-forge.r-project.org Wed Apr 8 17:00:21 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Apr 2015 17:00:21 +0200 (CEST) Subject: [Eventstudies-commits] r415 - pkg/vignettes Message-ID: <20150408150021.DA8A818788D@r-forge.r-project.org> Author: chiraganand Date: 2015-04-08 17:00:21 +0200 (Wed, 08 Apr 2015) New Revision: 415 Modified: pkg/vignettes/eventstudies.Rnw Log: Fixed market model, reduced event window to 5. Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2015-03-31 19:35:06 UTC (rev 414) +++ pkg/vignettes/eventstudies.Rnw 2015-04-08 15:00:21 UTC (rev 415) @@ -81,7 +81,7 @@ <>= es <- eventstudy(firm.returns = StockPriceReturns, event.list = SplitDates, - event.window = 10, + event.window = 5, type = "None", to.remap = TRUE, remap = "cumsum", @@ -90,7 +90,7 @@ @ This runs an event study using events listed in \emph{SplitDates}, and using -returns data for the firms in \emph{StockPriceReturns}. An event window of 10 +returns data for the firms in \emph{StockPriceReturns}. An event window of 5 days is analysed. Event studies with returns data typically do some kind of adjustment @@ -115,7 +115,7 @@ The object returned by eventstudy is of \texttt{class} `es'. It is a list with two components. Three of these are just a record of the way \texttt{eventstudy()} was run: the inference procedure adopted (``\texttt{bootstrap}'' -inference in this case), the window width (10 in this case) and the +inference in this case), the window width (5 in this case) and the method used for mapping the data (``\texttt{cumsum}''). The two new things are `\texttt{outcomes}' and `\texttt{result}'. @@ -144,7 +144,7 @@ Plot and print methods for the class `es' are supplied. The standard plot is illustrated in Figure \ref{f:esplot1}. In this case, we see the 95\% confidence interval is above 0 and below 0 and in no case can -the null of no-effect, compared with the starting date (10 days before +the null of no-effect, compared with the starting date (5 days before the stock split date), be rejected. In this first example, raw stock market returns was utilised in the @@ -166,14 +166,14 @@ improved statistical efficiency as $\textrm{Var}(\epsilon_j) < \textrm{Var}(r_j)$. -This is invoked by setting \texttt{type} to ``\texttt{marketResidual}'': +This is invoked by setting \texttt{type} to ``\texttt{marketModel}'': <>= data(OtherReturns) es.mm <- eventstudy(firm.returns = StockPriceReturns, event.list = SplitDates, - event.window = 10, - type = "marketResidual", + event.window = 5, + type = "marketModel", to.remap = TRUE, remap = "cumsum", inference = TRUE, @@ -182,7 +182,7 @@ ) @ -In addition to setting \texttt{type} to ``\texttt{marketResidual}'', we are now required +In addition to setting \texttt{type} to ``\texttt{marketModel}'', we are now required to supply data for the market index, $r_{Mt}$. In the above example, this is the data object `\texttt{NiftyIndex}' supplied from the \emph{OtherReturns} data object in the package. This is just a zoo vector with daily returns of @@ -230,7 +230,7 @@ <>= es.amm <- eventstudy(firm.returns = StockPriceReturns, event.list = SplitDates, - event.window = 10, + event.window = 5, type = "lmAMM", to.remap = TRUE, remap = "cumsum", @@ -256,10 +256,10 @@ interval at date 0 as a measure of efficiency. <>= -tmp <- rbind(es$result[10, ], - es.mm$result[10, ], - es.amm$result[10, ] - )[,c(1,3)] +tmp <- rbind(es$result[5, ], + es.mm$result[5, ], + es.amm$result[5, ] + )[, c(1, 3)] rownames(tmp) <- c("None", "MM", "AMM") print(tmp["MM", ] - tmp["None", ]) From noreply at r-forge.r-project.org Wed Apr 8 17:07:37 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Apr 2015 17:07:37 +0200 (CEST) Subject: [Eventstudies-commits] r416 - pkg/inst/tests Message-ID: <20150408150737.A0B501878AA@r-forge.r-project.org> Author: sargam_jain Date: 2015-04-08 17:07:37 +0200 (Wed, 08 Apr 2015) New Revision: 416 Added: pkg/inst/tests/test_functionality_inference.R pkg/inst/tests/test_userinput_inference.bootstrap.R pkg/inst/tests/test_userinput_remap.R Log: Test cases for inference and remap functions. Added: pkg/inst/tests/test_functionality_inference.R =================================================================== --- pkg/inst/tests/test_functionality_inference.R (rev 0) +++ pkg/inst/tests/test_functionality_inference.R 2015-04-08 15:07:37 UTC (rev 416) @@ -0,0 +1,52 @@ +library(testthat) +context("functionality") + +## 1. Test for class of arguments + + + +test_that("functionality for inference functions", { + library(eventstudies) + ## Data of Stock Prices + test.data0 <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17, + 35.89, 36.19, 37.1317, 36.7033, 37.7933, + 37.8533, 285.325, 292.6, 290.025, 286.2, + 290.075, 295.05, 289.325, 285.625, 293.7, + 298.5, 289.05, 704.5438, 708.35, 735.835, + 710.625, 711.65, 731.012, 727.575, + 715.0187, 724.2, 713.1875, 695.1812), + .Dim = c(11L, 3L), + .Dimnames = list( NULL, c("ITC", + "Reliance", "TCS")), + index = structure(c(12418, + 12419, 12422, 12423, 12424, + 12425, 12426, 12429, 12430, + 12431, 12432), + class = "Date"), + class = "zoo") + test.data0 <- diff(log(test.data0)) + + ## List of events + test.eventslist0 <- data.frame(name=c("ITC","Reliance","TCS", + "ITC","Reliance","Junk"), + when=as.Date(c("2004-01-02", + "2004-01-08", "2004-01-14", + "2005-01-15", "2004-01-01", + "2005-01-01"))) + test.eventslist0$name <- as.character(test.eventslist0$name) + + cat("\nTesting for class of arguments") + esConvertNormal0 <- phys2eventtime(z = test.data0, + events = test.eventslist0, + width = 1) + es.test.w0 <- window(esConvertNormal0$z.e, + start = -1, + end = +1) + + test.eventtime0 <- remap.cumsum(es.test.w0, is.pc = FALSE, + base = 0) + test.eventtime1 <- coredata(test.eventtime0) + + test.boot1 <- inference.bootstrap(es.w = test.eventtime1, + to.plot = FALSE) + Added: pkg/inst/tests/test_userinput_inference.bootstrap.R =================================================================== --- pkg/inst/tests/test_userinput_inference.bootstrap.R (rev 0) +++ pkg/inst/tests/test_userinput_inference.bootstrap.R 2015-04-08 15:07:37 UTC (rev 416) @@ -0,0 +1,75 @@ +library(testthat) +context("userinput") + +## 1. Test for normal values +## 2. Test for univariate zoo object: one firm data + + +test_that("userinput for inference functions", { + library(eventstudies) + ## Data of Stock Prices + test.data <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17, + 35.89, 36.19, 37.1317, 36.7033, 37.7933, + 37.8533, 285.325, 292.6, 290.025, 286.2, + 290.075, 295.05, 289.325, 285.625, 293.7, + 298.5, 289.05, 704.5438, 708.35, 735.835, + 710.625, 711.65, 731.012, 727.575, + 715.0187, 724.2, 713.1875, 695.1812), + .Dim = c(11L, 3L), + .Dimnames = list( NULL, c("ITC", + "Reliance", "TCS")), + index = structure(c(12418, + 12419, 12422, 12423, 12424, + 12425, 12426, 12429, 12430, + 12431, 12432), + class = "Date"), + class = "zoo") + test.data <- diff(log(test.data)) + ## List of events + test.eventslist <- data.frame(name=c("ITC","Reliance","TCS", + "ITC","Reliance","Junk"), + when=as.Date(c("2004-01-02", + "2004-01-08", "2004-01-14", + "2005-01-15", "2004-01-01", + "2005-01-01"))) + test.eventslist$name <- as.character(test.eventslist$name) + +### Testing function for normal values of width + + cat("\nTesting for normal input values") + esConvertNormal0 <- phys2eventtime(z = test.data, + events = test.eventslist, + width = 1) + es.test.w0 <- window(esConvertNormal0$z.e, + start = -1, + end = +1) + + test.eventtime0 <- remap.cumsum(es.test.w0, is.pc = FALSE, + base = 0) + + test.boot0 <- inference.bootstrap(es.w = test.eventtime0, + to.plot = FALSE) + + test.boot1 <- inference.wilcox(es.w = test.eventtime0, + to.plot = FALSE) + +### Testing function for univariate series: one firm + + cat("\nTesting for univariate series in zoo object") + esConvertNormal1 <- phys2eventtime(z = test.data, + events = test.eventslist, + width = 4) + es.test.w1 <- window(esConvertNormal1$z.e, + start = -4, + end = +4) + + test.eventtime1 <- remap.cumsum(es.test.w1, is.pc = FALSE, + base = 0) + + test.boot2 <- inference.bootstrap(es.w = test.eventtime1, + to.plot = FALSE) + + test.boot3 <- inference.wilcox(es.w = test.eventtime1, + to.plot = FALSE) + + }) Added: pkg/inst/tests/test_userinput_remap.R =================================================================== --- pkg/inst/tests/test_userinput_remap.R (rev 0) +++ pkg/inst/tests/test_userinput_remap.R 2015-04-08 15:07:37 UTC (rev 416) @@ -0,0 +1,78 @@ +library(testthat) +context("userinput") + +## 1. Testing remap.cumsum for univariate series i.e. only one firm +## 2. Testing remap.cumprod for univariate series i.e. only one firm +## 3. Testing remap.cumsum for percentage and absolute returns +## 4. Testing remap.cumprod for percentage and absolute returns + +test_that("userinput for remap.functions", { + library(eventstudies) + ## Data of Stock Prices + test.data <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17, + 35.89, 36.19, 37.1317, 36.7033, 37.7933, + 37.8533, 285.325, 292.6, 290.025, 286.2, + 290.075, 295.05, 289.325, 285.625, 293.7, + 298.5, 289.05, 704.5438, 708.35, 735.8375, + 710.625, 711.65, 731.025, 727.575, 715.187, + 724.2, 713.1875, 695.1812), + .Dim = c(11L, 3L), + .Dimnames = list( NULL, c("ITC", "Reliance", + "TCS")), index = structure(c(12418, + 12419, 12422, 12423, 12424, + 12425, 12426, 12429, 12430, + 12431, 12432), + class = "Date"), + class = "zoo") + test.data <- diff(log(test.data)) + ## List of events + test.eventslist <- data.frame(name=c("ITC","Reliance","TCS", + "ITC","Reliance","Junk"), + when=as.Date(c("2004-01-02", + "2004-01-08", "2004-01-14", + "2005-01-15", "2004-01-01", + "2005-01-01"))) + test.eventslist$name <- as.character(test.eventslist$name) + + ## Converting in the window format, as returned by phys2eventtime + + esConvertNormal0 <- phys2eventtime(z = test.data, + events = test.eventslist, + width = 2) + esConvertNormal1 <- phys2eventtime(z = test.data, + events = test.eventslist, + width = 1) + es.test.w0 <- window(esConvertNormal0$z.e, start = -4, end = +4) + es.test.w1 <- window(esConvertNormal1$z.e, start = -1, end = +1) + + ### Testing remap.cumsum for univariate series i.e. only one firm + + cat("\nTesting for univariate series in remap.cumsum") + es.test.remap0 <- remap.cumsum(es.test.w0, is.pc = FALSE, base = 0) + es.test.remap1 <- remap.cumsum(es.test.w1, is.pc = FALSE, base = 0) + + ### Testing remap.cumprod for univariate series i.e. only one firm + + cat("\nTesting for univariate series in remap.cumsum") + es.test.remap2 <- remap.cumprod(es.test.w0, is.pc = FALSE, + base = 100) + es.test.remap3 <- remap.cumprod(es.test.w1, is.pc = FALSE, + base = 100) + + ### Testing remap.cumsum for percentage and absolute returns + + cat("\nTesting for percentage and absolute returns in remap.cumsum") + + es.test.remap4 <- remap.cumsum(es.test.w0, is.pc = TRUE, base = 0) + + es.test.remap5 <- remap.cumsum(es.test.w0, is.pc = FALSE, base = 0) + + ### Testing remap.cumprod for percentage and absolute returns + + cat("\nTesting for percentage and absolute returns in remap.cumprod") + + es.test.remap4 <- remap.cumsum(es.test.w0, is.pc = TRUE, base = 100) + + es.test.remap5 <- remap.cumsum(es.test.w0, is.pc = FALSE, + base = 100) +}) From noreply at r-forge.r-project.org Wed Apr 8 17:23:15 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Apr 2015 17:23:15 +0200 (CEST) Subject: [Eventstudies-commits] r417 - pkg/R Message-ID: <20150408152315.2537B186041@r-forge.r-project.org> Author: sargam_jain Date: 2015-04-08 17:23:14 +0200 (Wed, 08 Apr 2015) New Revision: 417 Modified: pkg/R/eventstudy.R pkg/R/inference.bootstrap.R pkg/R/remap.cumsum.R Log: Changes in the code for univariate series. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2015-04-08 15:07:37 UTC (rev 416) +++ pkg/R/eventstudy.R 2015-04-08 15:23:14 UTC (rev 417) @@ -269,11 +269,15 @@ ### Remapping event frame if (to.remap == TRUE) { outputModel <- switch(remap, - cumsum = remap.cumsum(outputModel, is.pc = FALSE, base = 0), - cumprod = remap.cumprod(outputModel, is.pc = TRUE, - is.returns = TRUE, base = 100), - reindex = remap.event.reindex(outputModel) - ) + cumsum = remap.cumsum(outputModel, is.pc = FALSE, base = 0), + cumprod = remap.cumprod(outputModel, is.pc = TRUE, + is.returns = TRUE, base = 100), + reindex = remap.event.reindex(outputModel) + ) + car <- outputModel + if(inference == FALSE){ + outputModel <- ifelse(NCOL(outputModel) != 1, rowMeans(outputModel), mean(outputModel)) + } remapping <- remap } else { remapping <- "none" @@ -297,6 +301,10 @@ if (exists("outputResiduals")) { attr(final.result, which = "model.residuals") <- outputResiduals } + + if (exists("car")) { + attr(final.result, which = "CAR") <- car + } attr(final.result, which = "event.window") <- event.window attr(final.result, which = "inference") <- inference if (inference == TRUE) { Modified: pkg/R/inference.bootstrap.R =================================================================== --- pkg/R/inference.bootstrap.R 2015-04-08 15:07:37 UTC (rev 416) +++ pkg/R/inference.bootstrap.R 2015-04-08 15:23:14 UTC (rev 417) @@ -53,7 +53,7 @@ ylab = "Cumulative returns of response series", main = "Event study plot") { Ecar <- function(transposed, d) { - colMeans(transposed[d,], na.rm=TRUE) + colMeans(transposed[d, , drop=FALSE], na.rm=TRUE) } tmp <- t(as.matrix(es.w)) b <- boot(tmp, Ecar, R=boot.run) Modified: pkg/R/remap.cumsum.R =================================================================== --- pkg/R/remap.cumsum.R 2015-04-08 15:07:37 UTC (rev 416) +++ pkg/R/remap.cumsum.R 2015-04-08 15:23:14 UTC (rev 417) @@ -8,7 +8,7 @@ tmp <- tmp/100 } if(NCOL(z)==1){ - z <- tmp + z <- base+cumsum(tmp) } else { z[,i] <- base+cumsum(tmp) } @@ -18,8 +18,8 @@ firstValueZero <- function(x){ if(NCOL(x)==1){ - x[1] <- 0 - } else { + x[1] <- 0 + } else { x[1,] <- 0 } return(x) From noreply at r-forge.r-project.org Wed Apr 8 17:42:11 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Apr 2015 17:42:11 +0200 (CEST) Subject: [Eventstudies-commits] r418 - pkg/man Message-ID: <20150408154211.2D94B186C5E@r-forge.r-project.org> Author: chiraganand Date: 2015-04-08 17:42:10 +0200 (Wed, 08 Apr 2015) New Revision: 418 Modified: pkg/man/eventstudy.Rd Log: Updated man page. Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2015-04-08 15:23:14 UTC (rev 417) +++ pkg/man/eventstudy.Rd 2015-04-08 15:42:10 UTC (rev 418) @@ -112,11 +112,13 @@ from the output and \dQuote{outcomes} object is updated with \dQuote{edatamissing}.} - \item{Remapping is done if \dQuote{to.remap} is TRUE using - value of \dQuote{remap} argument.} + \item{Remapping is done if \dQuote{to.remap} is \sQuote{TRUE} using + the function specified in \dQuote{remap} argument.} - \item{Inference is done if \dQuote{inference} is TRUE using the - technique mentioned in \dQuote{inference.strategy}.} + \item{Means of returns are computed across various events.} + + \item{Inference is done if \dQuote{inference} is \sQuote{TRUE} using the + technique specified in \dQuote{inference.strategy}.} } \dQuote{firm.returns} can contain a single series also. To study a single @@ -230,6 +232,11 @@ model. For models which do not compute residuals, this attribute is not returned.} + \item{\dQuote{CAR}:}{ + a \sQuote{zoo} object contaning Cumulative Abnormal Returns as + returned by the function specified by \dQuote{remap} argument. + } + \item{\dQuote{inference}:}{ a \sQuote{character} providing information about which inference strategy was utilised to estimate the confidence intervals. From noreply at r-forge.r-project.org Wed Apr 8 17:47:11 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Apr 2015 17:47:11 +0200 (CEST) Subject: [Eventstudies-commits] r419 - pkg/man Message-ID: <20150408154711.D52DA187393@r-forge.r-project.org> Author: chiraganand Date: 2015-04-08 17:47:11 +0200 (Wed, 08 Apr 2015) New Revision: 419 Modified: pkg/man/remap.cumprod.Rd pkg/man/remap.cumsum.Rd Log: Improved description of z argument. Modified: pkg/man/remap.cumprod.Rd =================================================================== --- pkg/man/remap.cumprod.Rd 2015-04-08 15:42:10 UTC (rev 418) +++ pkg/man/remap.cumprod.Rd 2015-04-08 15:47:11 UTC (rev 419) @@ -11,8 +11,9 @@ } \arguments{ - \item{z}{a \pkg{zoo} object indexed by event time obtained from - \code{\link{phys2eventtime}}.} + \item{z}{a \pkg{zoo} object indexed by event time, typically by the + \dQuote{z.e} component obtained from \dQuote{phys2eventtime} + function.} \item{is.pc}{\sQuote{logical}, whether input is a percentage. Default value set to \sQuote{FALSE}.} Modified: pkg/man/remap.cumsum.Rd =================================================================== --- pkg/man/remap.cumsum.Rd 2015-04-08 15:42:10 UTC (rev 418) +++ pkg/man/remap.cumsum.Rd 2015-04-08 15:47:11 UTC (rev 419) @@ -12,8 +12,9 @@ } \arguments{ - \item{z}{a \pkg{zoo} object indexed by event time obtained from - \dQuote{phys2eventtime}.} + \item{z}{a \pkg{zoo} object indexed by event time, typically by the + \dQuote{z.e} component obtained from \dQuote{phys2eventtime} + function.} \item{is.pc}{\sQuote{logical}, whether input is a percentage. Default value set to \sQuote{FALSE}.} From noreply at r-forge.r-project.org Thu Apr 9 11:48:54 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 9 Apr 2015 11:48:54 +0200 (CEST) Subject: [Eventstudies-commits] r420 - pkg Message-ID: <20150409094854.DC617186901@r-forge.r-project.org> Author: chiraganand Date: 2015-04-09 11:48:54 +0200 (Thu, 09 Apr 2015) New Revision: 420 Modified: pkg/DESCRIPTION Log: Updated description, added contributors. Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2015-04-08 15:47:11 UTC (rev 419) +++ pkg/DESCRIPTION 2015-04-09 09:48:54 UTC (rev 420) @@ -1,11 +1,27 @@ Package: eventstudies +Version: 1.2 +Date: 2015-04-09 Type: Package Title: Event study analysis -Version: 1.2 -Date: 2014-05-02 -Author: Chirag Anand, Vikram Bahure, Vimal Balasubramaniam, Ajay Shah -Maintainer: Vikram Bahure -Depends: R (>= 2.12.0), zoo, xts, boot, testthat, sandwich -Description: An R package for conducting event studies and a platform for methodological research on event studies. +Authors at R: c( + person("Chirag", "Anand", role = c("aut", "cre"), + email = "anand.chirag at gmail.com"), + person("Vikram", "Bahure", role = "aut", + email = "economics.vikram at gmail.com"), + person("Vimal", "Balasubramaniam", role = "aut", + email = "vimsaa at gmail.com"), + person("Shekhar", "Harikumar", role = "ctb", + email = "shekhar.harikumar at gmail.com"), + person("Sargam", "Jain", role = "ctb", + email = "sargamjain13 at gmail.com"), + person("Ajay", "Shah", role = "aut", + email = "ajayshah at mayin.org") + ) +Maintainer: Chirag Anand +Depends: R (>= 3.0), zoo, xts, boot, testthat, sandwich +Description: An R package for conducting event studies and a platform + for methodological research on event studies. License: GPL-2 +URL: https://r-forge.r-project.org/projects/eventstudies +BugReports: https://r-forge.r-project.org/tracker/?atid=4491&group_id=1131&func=browse LazyLoad: yes