From noreply at r-forge.r-project.org Fri Aug 2 18:43:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 2 Aug 2013 18:43:43 +0200 (CEST) Subject: [Eventstudies-commits] r105 - in pkg: R man vignettes Message-ID: <20130802164343.A15D11842E0@r-forge.r-project.org> Author: vimsaa Date: 2013-08-02 18:43:43 +0200 (Fri, 02 Aug 2013) New Revision: 105 Modified: pkg/R/AMM.R pkg/man/AMM.Rd pkg/man/eventstudy.Rd pkg/man/manyfirmsAMM.Rd pkg/vignettes/eventstudies.Rnw Log: manyfirmsAMM in AMM.R has been changed - it cannot be called by the eventstudy wrapper. I have commented out the example on eventstudy.Rd - this needs some mending. Likewise, the Rd file for AMM() has also been updated. Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-07-28 08:30:13 UTC (rev 104) +++ pkg/R/AMM.R 2013-08-02 16:43:43 UTC (rev 105) @@ -5,8 +5,7 @@ AMM <- function(amm.type = NULL, ...) { ## List of models currently supported - modelsList <- c("onefirm", - "firmExposures","manyfirms") + modelsList <- c("onefirm","firmExposures") if (is.null(amm.type) || length(amm.type) != 1) { stop("Argument amm.type not provided or incorrect") @@ -27,7 +26,7 @@ regressand <- NULL periodnames <- NULL - # parse the input arguments for the model + # parse the input arguments for the model modelArgs <- list(...) # assign values for (i in 1:length(modelArgs)) { @@ -78,22 +77,6 @@ result <- onefirmAMM(rj, X, nlags, verbose, dates) } - ##----------- - ## Many firms - ##----------- - if(amm.type == "manyfirms") { - # Checking required arguments - if (match("regressand", names(modelArgs), nomatch = -1) == -1) { - stop("Input regressand (firm data) is missing") - } - - X <- makeX(rM1, others, switch.to.innov, - rM1purge, nlags, dates, verbose) - result <- manyfirmsAMM(regressand, regressors=X, lags=nlags, - verbose = verbose, - dates = dates, periodnames = periodnames) - } - ##--------------- ## Firm exposures ##--------------- @@ -162,13 +145,13 @@ ######################## # Many firms AMM ######################## -manyfirmsAMM <-function(regressand,regressors, - lags,dates=NULL, periodnames=NULL,verbose=FALSE){ - ## Assigning value for coding usage - rawdates <- 1 +manyfirmsAMM <- +function(regressand,regressors, + lags,dates=NULL, periodnames=NULL,verbose=FALSE){ + require("doMC") + registerDoMC() if(is.null(dates)){ dates=c(start(regressors),end(regressors)) - rawdates <- NULL periodnames="Full" } nperiods <- length(periodnames) @@ -176,10 +159,10 @@ cat("Mistake in length of dates versus length of periods.\n") return(NULL) } - nfirms <- ncol(regressand) # Let's get "exposure' and 'sds'. Setting up structures:- + exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(regressors)) rownames(exposures) <- colnames(regressand) tmp <- NULL @@ -196,47 +179,26 @@ # Setup a list structure for an OLS that failed empty <- list(exposures=rep(NA,ncol(regressors)), s.exposures=rep(NA,ncol(regressors))) - this.resid.final <- list() - for(i in 1:NCOL(regressand)){ - if (verbose) {cat ("Working on", colnames(regressand)[i],"\n")} + + for(i in 1:ncol(regressand)){ + cat("Doing",colnames(regressand)[i]) + if (verbose) {cat ("Doing", colnames(regressand)[i])} rj <- regressand[,i] dataset <- cbind(rj, regressors) # This is the full time-series this.exp <- this.sds <- NULL for(j in 1:nperiods){ # now we chop it up t1 <- dates[j] t2 <- dates[j+1] - # if (j != nperiods) {t2 <- t2-1} # I don't know why I wrote this now :-( But this created problems. this <- window(dataset,start=t1, end=t2) fe <- firmExposures(this[,1],this[,-1],nlags=lags,verbose) if(is.null(fe)) {fe <- empty} this.exp <- c(this.exp, fe$exposures) this.sds <- c(this.sds, fe$s.exposures) -### Getting residual - if(j==1){ - this.resid <- xts(fe$residuals, - as.Date(fe$residuals,attr(fe$residuals,"names"))) - colnames(this.resid) <- paste(dates[j],"to",dates[j+1],sep=".") - } else { - tmp.resid <- xts(fe$residuals, - as.Date(fe$residuals,attr(fe$residuals,"names"))) - colnames(tmp.resid) <- paste(dates[j],"to",dates[j+1],sep=".") - this.resid <- merge(this.resid, tmp.resid, all=TRUE) - } } - exposures[i,] <- this.exp - sds[i,] <- this.sds - this.resid.final[[i]] <- this.resid + exposures[colnames(regressand)[i],] <- this.exp + sds[colnames(regressand)[i],] <- this.sds } - names(this.resid.final) <- colnames(regressand) - ## Merging all firms for no period break - if(is.null(rawdates)){ - final.resid <- do.call(merge,this.resid.final) - colnames(final.resid) <- colnames(regressand) - this.resid.final <- final.resid - } - - list(exposures=exposures, sds=sds, sig=exposures/sds, - residual=this.resid.final) + list(exposures=exposures, sds=sds, sig=exposures/sds) } ############################################### Modified: pkg/man/AMM.Rd =================================================================== --- pkg/man/AMM.Rd 2013-07-28 08:30:13 UTC (rev 104) +++ pkg/man/AMM.Rd 2013-08-02 16:43:43 UTC (rev 105) @@ -53,14 +53,6 @@ "2008-01-05","2009-01-03")), rM1=NIFTY_INDEX, others=INRUSD, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) - -## Many firms -mf <- AMM(amm.type="manyfirms",regressand=regressand, - verbose=TRUE, - dates= NULL, - rM1=NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) - } \keyword{AMM} \ No newline at end of file Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2013-07-28 08:30:13 UTC (rev 104) +++ pkg/man/eventstudy.Rd 2013-08-02 16:43:43 UTC (rev 105) @@ -56,14 +56,12 @@ \examples{ ## Performing event study -library(eventstudies) -data("StockPriceReturns") -data("SplitDates") +## library(eventstudies) +## data("StockPriceReturns") +## data("SplitDates") ## Event study without adjustment -es <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, width = 10, - type = "None", to.remap = TRUE, remap = "cumsum", to.plot = FALSE, - inference = TRUE, inference.strategy = "bootstrap") +## es <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, width = 10,type = "None", to.remap = TRUE, remap = "cumsum", to.plot = FALSE,inference = TRUE, inference.strategy = "bootstrap") } Modified: pkg/man/manyfirmsAMM.Rd =================================================================== --- pkg/man/manyfirmsAMM.Rd 2013-07-28 08:30:13 UTC (rev 104) +++ pkg/man/manyfirmsAMM.Rd 2013-08-02 16:43:43 UTC (rev 105) @@ -9,7 +9,7 @@ matrix of data obtained from \code{makeX}, and a matrix of LHS variables} \usage{ -manyfirmsAMM(regressand, regressors, nlags, dates = NULL, periodnames = NULL, verbose = FALSE) +manyfirmsAMM(regressand, regressors, lags, dates = NULL, periodnames = NULL, verbose = FALSE) } \arguments{ @@ -54,7 +54,7 @@ dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), verbose=FALSE) regressand <- cbind(Company_A,Company_B,Company_C) -res <- manyfirmsAMM(regressand,regressors,nlags=1, +res <- manyfirmsAMM(regressand,regressors,lags=1, dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")),periodnames=c("P1","P2","P3","P4"), verbose=FALSE) Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-07-28 08:30:13 UTC (rev 104) +++ pkg/vignettes/eventstudies.Rnw 2013-08-02 16:43:43 UTC (rev 105) @@ -196,14 +196,6 @@ "2008-01-05","2009-01-03")), rM1=NIFTY_INDEX, others=INRUSD, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -## Many firms -mf <- AMM(amm.type="manyfirm",regressand=regressand, - nlags=NA, - verbose=TRUE, - dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", - "2008-01-05","2009-01-03")), - rM1=NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) @ \subsection{Converting physical dates to event frame} From noreply at r-forge.r-project.org Sat Aug 3 10:04:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 3 Aug 2013 10:04:29 +0200 (CEST) Subject: [Eventstudies-commits] r106 - pkg/R Message-ID: <20130803080429.D10A2181205@r-forge.r-project.org> Author: chiraganand Date: 2013-08-03 10:04:29 +0200 (Sat, 03 Aug 2013) New Revision: 106 Modified: pkg/R/phys2eventtime.R Log: Vectorised timeshift function, removed the for loop for some performance gain. Modified: pkg/R/phys2eventtime.R =================================================================== --- pkg/R/phys2eventtime.R 2013-08-02 16:43:43 UTC (rev 105) +++ pkg/R/phys2eventtime.R 2013-08-03 08:04:29 UTC (rev 106) @@ -1,4 +1,4 @@ -library(zoo) +nlibrary(zoo) # Upon input # z is a zoo object containing input data. E.g. this could be all the @@ -16,36 +16,32 @@ # Just in case events$unit has been sent in as a factor -- events$unit <- as.character(events$unit) if(is.factor(events$when)) stop("Sorry you provided a factor as an index") - # Given a zoo time-series vector x, and an event date "when", + # Given a zoo time-series z, and an event date "when", # try to shift this vector into event time, where the event date # becomes 0 and all other dates shift correspondingly. # If this can't be done, then send back NULL with an error code. - timeshift <- function(x, when) { - location <- findInterval(when, index(x)) - if ((location <= 1) | (location >= length(x))) { + ## takes the event list as an argument and uses already existing + ## time-series variable z + timeshift <- function(x) { + firm.present <- match(x[1], colnames(z), nomatch = -1) != -1 + if (!firm.present) { + return(list(result=NULL, outcome="unitmissing")) + } + location <- match(as.Date(x[2]), index(z[,x[1]]), nomatch = -1) + if (location == -1 | location == 1 | !firm.present) { return(list(result=NULL, outcome="wrongspan")) } - remapped <- zoo(as.numeric(x), order.by=(-location+1):(length(x)-location)) - list(result=remapped, outcome="success") + remapped <- zoo(as.numeric(z[,x[1]]), order.by=(-location+1):(length(z[,x[1]])-location)) + return(list(result=remapped, outcome="success")) } + + answer <- apply(events, 1, timeshift) + answer <- unlist(answer, recursive = FALSE) + rownums <- grep("outcome", names(answer)) + outcomes <- as.character(do.call("c", answer[rownums])) + z.e <- do.call("cbind", answer[rownums[which(answer[rownums] == "success")] - 1]) + colnames(z.e) <- which(outcomes == "success") - # Main loop to build up a data object in event time -- - outcomes <- character(nrow(events)) - z.e <- zoo(1, order.by=as.integer(1)) # zoo::cbind() requires initialising z.e - for (eventnum in 1:nrow(events)) { - if (!(events$unit[eventnum] %in% colnames(z))) { - outcomes[eventnum] <- "unitmissing" - next - } - attempt <- timeshift(z[,events$unit[eventnum]], events$when[eventnum]) - if (attempt$outcome=="success") { - z.e <- cbind(z.e, attempt$result) - } - outcomes[eventnum] <- attempt$outcome - } - outcomes <- outcomes - z.e <- z.e[,-1, drop = FALSE] #get rid of that junk initialisation - colnames(z.e) <- which(outcomes=="success") ## Now worry about whether there's information within the event window ## (This entire cleaning+checking can be switched off by specifying width=0) badcolumns <- NULL From noreply at r-forge.r-project.org Sun Aug 4 10:16:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 4 Aug 2013 10:16:32 +0200 (CEST) Subject: [Eventstudies-commits] r107 - in pkg: R man vignettes Message-ID: <20130804081632.5375A183E7A@r-forge.r-project.org> Author: vikram Date: 2013-08-04 10:16:32 +0200 (Sun, 04 Aug 2013) New Revision: 107 Modified: pkg/R/AMM.R pkg/R/eventstudy.R pkg/R/remap.cumprod.R pkg/R/remap.cumsum.R pkg/R/remap.event.reindex.R pkg/man/onefirmAMM.Rd pkg/vignettes/eventstudies.Rnw Log: Modified AMM function to fit many firms, changed remap.cumsum to fit one column data; added no inference strategy ouput for one event date; Work in progress Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/R/AMM.R 2013-08-04 08:16:32 UTC (rev 107) @@ -5,7 +5,7 @@ AMM <- function(amm.type = NULL, ...) { ## List of models currently supported - modelsList <- c("onefirm","firmExposures") + modelsList <- c("onefirm","manyfirms","firmExposures") if (is.null(amm.type) || length(amm.type) != 1) { stop("Argument amm.type not provided or incorrect") @@ -23,8 +23,6 @@ switch.to.innov <- NULL verbose <- NULL dates <- NULL - regressand <- NULL - periodnames <- NULL # parse the input arguments for the model modelArgs <- list(...) @@ -49,7 +47,7 @@ # Checking remaining arguments if (match("nlags", names(modelArgs), nomatch = -1) == -1) { - nlags <- NA + nlags <- 1 } if (match("verbose", names(modelArgs), nomatch = -1) == -1) { verbose <- FALSE @@ -57,9 +55,6 @@ if (match("dates", names(modelArgs), nomatch = -1) == -1) { dates <- NULL } - if (match("periodnames", names(modelArgs), nomatch = -1) == -1) { - periodnames <- NULL - } ## Assign values @@ -75,8 +70,28 @@ X <- makeX(rM1, others, switch.to.innov, rM1purge, nlags, dates, verbose) result <- onefirmAMM(rj, X, nlags, verbose, dates) + result <- result$residuals } + ##----------- + ## Many firms + ##----------- + if(amm.type == "manyfirms") { + # Checking required arguments + if (match("rj", names(modelArgs), nomatch = -1) == -1) { + stop("Input rj (firm data) is missing") + } + + X <- makeX(rM1, others, switch.to.innov, + rM1purge, nlags, dates, verbose) + result <- xts() + for(i in 1:NCOL(rj)){ + tmp <- onefirmAMM(rj[,i], X, nlags, verbose, dates) + result <- merge(result,tmp$residuals) + } + colnames(result) <- colnames(rj) + } + ##--------------- ## Firm exposures ##--------------- @@ -98,11 +113,19 @@ ####################### # AMM for one firm ####################### -onefirmAMM <- function(rj,X,nlags=NA,verbose=FALSE,dates=NULL,residual=TRUE){ - exposures <- data.frame(matrix(NA,ncol=ncol(X),nrow=(length(dates)-1))) +onefirmAMM <- function(rj,X,nlags=1,verbose=FALSE,dates=NULL,residual=TRUE){ + ## Creating empty frames + if(is.null(dates)){ + dates.no <- c(start(rj),end(rj)) + } else{ + dates.no <- dates + } + exposures <- data.frame(matrix(NA,ncol=ncol(X),nrow=(length(dates.no)-1))) colnames(exposures) <- colnames(X) sds <- exposures periodnames <- NULL + + ## Getting firm exposure, amm residuals if(is.null(dates)){ res <- firmExposures(rj,X,verbose=verbose,nlags=nlags) exposures <- res$exposure Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/R/eventstudy.R 2013-08-04 08:16:32 UTC (rev 107) @@ -30,11 +30,11 @@ if (type == "AMM") { if(amm.type == "onefirm"){ tmp.outputModel <- AMM(rj = inputData, ...) - outputModel <- zoo(tmp.outputModel$residual,index(tmp.outputModel)) + outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } if(amm.type == "manyfirms"){ - tmp.outputModel <- AMM(regressand = inputData, ...) - outputModel <- zoo(tmp.outputModel$residual,index(tmp.outputModel)) + tmp.outputModel <- AMM(rj = inputData, ...) + outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } if(amm.type == "firmExposures"){ stop("amm.type firmExposures not used for event study analysis") @@ -51,11 +51,22 @@ if (type == "excessReturn") { outputModel <- excessReturn(data.object = inputData, ...) } - + ##Converting index outputModel to Date + index(outputModel) <- as.Date(index(outputModel)) + + ### Convert to event frame es <- phys2eventtime(z=outputModel, events=eventList, width=width) - colnames(es) <- eventList[which(es$outcomes=="success"),1] es.w <- window(es$z.e, start = -width, end = width) + ## Adding column names to event output + cn.names <- eventList[which(es$outcomes=="success"),1] + if(length(cn.names)==1){ + cat("Event date exists only for",cn.names,"\n") + inference <- FALSE + cat("No inference strategy for one column","\n") + } else { + colnames(es.w) <- cn.names + } ### Remapping event frame if (to.remap == TRUE) { Modified: pkg/R/remap.cumprod.R =================================================================== --- pkg/R/remap.cumprod.R 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/R/remap.cumprod.R 2013-08-04 08:16:32 UTC (rev 107) @@ -6,7 +6,7 @@ # is.returns is false in this case is.pc is ignored! # values are like 1.01 for 1% remap.cumprod <- function(z, is.pc=TRUE, is.returns=TRUE, base=100) { - for (i in 1:ncol(z)) { + for (i in 1:NCOL(z)) { tmp <- z[,i] if (is.returns) { if (is.pc) { @@ -15,7 +15,11 @@ tmp <- 1+tmp } tmp[1] <- base - z[,i] <- cumprod(tmp) + if(NCOL(z)==1){ + z <- cumprod(tmp) + } else { + z[,i] <- cumprod(tmp) + } } z } Modified: pkg/R/remap.cumsum.R =================================================================== --- pkg/R/remap.cumsum.R 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/R/remap.cumsum.R 2013-08-04 08:16:32 UTC (rev 107) @@ -1,12 +1,16 @@ # If is.pc then a value like "1" means 0.01 remap.cumsum <- function(z, is.pc=TRUE, base=0) { - for (i in 1:ncol(z)) { + for (i in 1:NCOL(z)) { tmp <- z[,i] if (is.pc) { tmp <- tmp/100 } - z[,i] <- base+cumsum(tmp) + if(NCOL(z)==1){ + z <- tmp + } else { + z[,i] <- base+cumsum(tmp) + } } z } Modified: pkg/R/remap.event.reindex.R =================================================================== --- pkg/R/remap.event.reindex.R 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/R/remap.event.reindex.R 2013-08-04 08:16:32 UTC (rev 107) @@ -5,8 +5,12 @@ # values are scaled accordingly. remap.event.reindex <- function(z) { eventvals <- as.numeric(window(z, start=0, end=0)) - for (i in 1:ncol(z)) { - z[,i] <- 100*z[,i]/eventvals[i] + for (i in 1:NCOL(z)) { + if(NCOL(z)==1){ + z <- 100*z[,i]/eventvals[i] + } else { + z[,i] <- 100*z[,i]/eventvals[i] + } } z } Modified: pkg/man/onefirmAMM.Rd =================================================================== --- pkg/man/onefirmAMM.Rd 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/man/onefirmAMM.Rd 2013-08-04 08:16:32 UTC (rev 107) @@ -56,7 +56,7 @@ # Run AMM for one firm across different periods onefirmAMM(rj=Company_A, X=rhs.dat, - nlags=NA, + nlags=1, verbose=TRUE, dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03"))) Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-03 08:04:29 UTC (rev 106) +++ pkg/vignettes/eventstudies.Rnw 2013-08-04 08:16:32 UTC (rev 107) @@ -328,7 +328,6 @@ stock.data <- all.data[,-cn.names] of <- AMM(amm.type="onefirm",rj=y3c3$Company_A, - nlags=NA, verbose=TRUE, dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), @@ -336,14 +335,9 @@ switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -mf <- AMM(amm.type="manyfirms",regressand=StockPriceReturns[,1:3], - nlags=NA, verbose=TRUE, dates= NULL, - rM1=all.data$nifty, others=all.data$inr, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -mf1 <- mf$residual -mf1 <- mf1[complete.cases(mf1),] -p1 <- phys2eventtime(z = mf1, events = SplitDates, width = 10) - +of.r <- AMM(amm.type="manyfirms", rj=stock.data[,1:5],verbose=TRUE, dates=NULL, + rM1=all.data$nifty, others=all.data$inr, switch.to.innov=TRUE, + rM1purge=TRUE, nlags=1) es.ammonefirm <- eventstudy(inputData = stock.data[,1:4], eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", @@ -351,7 +345,7 @@ inference.strategy = "bootstrap", type = "AMM", amm.type="manyfirms", rM1=all.data$nifty, others=all.data$inr, - nlags=NA, verbose=TRUE, + nlags=1, verbose=TRUE, dates= NULL, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) From noreply at r-forge.r-project.org Sun Aug 4 11:01:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 4 Aug 2013 11:01:45 +0200 (CEST) Subject: [Eventstudies-commits] r108 - in pkg: . R vignettes Message-ID: <20130804090145.491A31851DA@r-forge.r-project.org> Author: vikram Date: 2013-08-04 11:01:44 +0200 (Sun, 04 Aug 2013) New Revision: 108 Modified: pkg/DESCRIPTION pkg/NAMESPACE pkg/R/AMM.R pkg/R/phys2eventtime.R pkg/vignettes/eventstudies.Rnw Log: Minor modifications and corrections Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-08-04 08:16:32 UTC (rev 107) +++ pkg/DESCRIPTION 2013-08-04 09:01:44 UTC (rev 108) @@ -2,7 +2,7 @@ Type: Package Title: Event study and extreme event analysis Version: 1.1 -Author: Ajay Shah, Vimal Balasubramaniam, Vikram Bahure +Author: Ajay Shah, Vikram Bahure Maintainer: Vikram Bahure Depends: R (>= 2.12.0), zoo, xts, boot, testthat, sandwich, exactRankTests Description: Implementation of short and long term event study methodology Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2013-08-04 08:16:32 UTC (rev 107) +++ pkg/NAMESPACE 2013-08-04 09:01:44 UTC (rev 108) @@ -1,8 +1,7 @@ export(eventstudy, inference.bootstrap, inference.wilcox, phys2eventtime, remap.cumsum, remap.cumprod, remap.event.reindex, ees, eesPlot) export(marketResidual, - excessReturn - ) + excessReturn) export(AMM, onefirmAMM, manyfirmsAMM, Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-04 08:16:32 UTC (rev 107) +++ pkg/R/AMM.R 2013-08-04 09:01:44 UTC (rev 108) @@ -81,6 +81,9 @@ if (match("rj", names(modelArgs), nomatch = -1) == -1) { stop("Input rj (firm data) is missing") } + if(NCOL(rj)<2){ + stop("Less than two firms in inputData") + } X <- makeX(rM1, others, switch.to.innov, rM1purge, nlags, dates, verbose) Modified: pkg/R/phys2eventtime.R =================================================================== --- pkg/R/phys2eventtime.R 2013-08-04 08:16:32 UTC (rev 107) +++ pkg/R/phys2eventtime.R 2013-08-04 09:01:44 UTC (rev 108) @@ -1,4 +1,4 @@ -nlibrary(zoo) +library(zoo) # Upon input # z is a zoo object containing input data. E.g. this could be all the Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-04 08:16:32 UTC (rev 107) +++ pkg/vignettes/eventstudies.Rnw 2013-08-04 09:01:44 UTC (rev 108) @@ -338,6 +338,7 @@ of.r <- AMM(amm.type="manyfirms", rj=stock.data[,1:5],verbose=TRUE, dates=NULL, rM1=all.data$nifty, others=all.data$inr, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + es.ammonefirm <- eventstudy(inputData = stock.data[,1:4], eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", From noreply at r-forge.r-project.org Sun Aug 4 21:45:30 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 4 Aug 2013 21:45:30 +0200 (CEST) Subject: [Eventstudies-commits] r109 - in pkg: R man vignettes Message-ID: <20130804194531.252681852B6@r-forge.r-project.org> Author: vikram Date: 2013-08-04 21:45:30 +0200 (Sun, 04 Aug 2013) New Revision: 109 Modified: pkg/R/eventstudy.R pkg/man/onefirmAMM.Rd pkg/vignettes/eventstudies.Rnw Log: Modified for minor error in one firm data; code works fine; checking failure in test case Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-04 09:01:44 UTC (rev 108) +++ pkg/R/eventstudy.R 2013-08-04 19:45:30 UTC (rev 109) @@ -17,10 +17,6 @@ outputModel <- inputData } - ## else { - ## stop("inputData or \"None\" type missing") - ## } - if (is.levels == TRUE) { inputData <- diff(log(inputData)) * 100 } @@ -51,10 +47,12 @@ if (type == "excessReturn") { outputModel <- excessReturn(data.object = inputData, ...) } - ##Converting index outputModel to Date - index(outputModel) <- as.Date(index(outputModel)) - +### Converting index outputModel to Date + index(outputModel) <- as.Date(index(outputModel)) + ## Stop if there is only one firm: phys2eventtime breaks down + if(NCOL(outputModel)==1){stop("Event study does not work for one firm/column")} + ### Convert to event frame es <- phys2eventtime(z=outputModel, events=eventList, width=width) es.w <- window(es$z.e, start = -width, end = width) Modified: pkg/man/onefirmAMM.Rd =================================================================== --- pkg/man/onefirmAMM.Rd 2013-08-04 09:01:44 UTC (rev 108) +++ pkg/man/onefirmAMM.Rd 2013-08-04 19:45:30 UTC (rev 109) @@ -10,7 +10,7 @@ } \usage{ -onefirmAMM(rj, X, nlags = NA, verbose = FALSE, dates = NULL, residual = TRUE) +onefirmAMM(rj, X, nlags = 1, verbose = FALSE, dates = NULL, residual = TRUE) } \arguments{ Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-04 09:01:44 UTC (rev 108) +++ pkg/vignettes/eventstudies.Rnw 2013-08-04 19:45:30 UTC (rev 109) @@ -334,21 +334,27 @@ rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +of1 <- AMM(amm.type="onefirm",rj=y3c3$Company_A, + verbose=TRUE, + dates= NULL, + rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, + switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + of.r <- AMM(amm.type="manyfirms", rj=stock.data[,1:5],verbose=TRUE, dates=NULL, rM1=all.data$nifty, others=all.data$inr, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -es.ammonefirm <- eventstudy(inputData = stock.data[,1:4], - eventList = SplitDates, - width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = TRUE, inference = TRUE, - inference.strategy = "bootstrap", - type = "AMM", amm.type="manyfirms", - rM1=all.data$nifty, others=all.data$inr, - nlags=1, verbose=TRUE, - dates= NULL, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +es.amm <- eventstudy(inputData = stock.data, + eventList = SplitDates, + width = 10, to.remap = TRUE, remap = "cumsum", + to.plot = TRUE, inference = TRUE, + inference.strategy = "bootstrap", + type = "AMM", amm.type="manyfirms", + rM1=all.data$nifty, others=all.data$inr, + nlags=1, verbose=TRUE, + dates= NULL, + switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) @ From noreply at r-forge.r-project.org Sun Aug 4 22:01:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 4 Aug 2013 22:01:02 +0200 (CEST) Subject: [Eventstudies-commits] r110 - in pkg: . R Message-ID: <20130804200102.E5C741851FD@r-forge.r-project.org> Author: vimsaa Date: 2013-08-04 22:01:02 +0200 (Sun, 04 Aug 2013) New Revision: 110 Modified: pkg/DESCRIPTION pkg/R/AMM.R Log: Updated DESCRIPTION with foreach and doMC as dependencies. This gets rid of a R CMD check warning on global calls not being defined... Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-08-04 19:45:30 UTC (rev 109) +++ pkg/DESCRIPTION 2013-08-04 20:01:02 UTC (rev 110) @@ -4,7 +4,7 @@ Version: 1.1 Author: Ajay Shah, Vikram Bahure Maintainer: Vikram Bahure -Depends: R (>= 2.12.0), zoo, xts, boot, testthat, sandwich, exactRankTests +Depends: R (>= 2.12.0), zoo, xts, boot, testthat, sandwich, exactRankTests, doMC, foreach Description: Implementation of short and long term event study methodology License: GPL-2 LazyLoad: yes Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-04 19:45:30 UTC (rev 109) +++ pkg/R/AMM.R 2013-08-04 20:01:02 UTC (rev 110) @@ -174,8 +174,9 @@ manyfirmsAMM <- function(regressand,regressors, lags,dates=NULL, periodnames=NULL,verbose=FALSE){ - require("doMC") + # require("doMC") registerDoMC() + cat("All available cores will be used for this program.\n") if(is.null(dates)){ dates=c(start(regressors),end(regressors)) periodnames="Full" From noreply at r-forge.r-project.org Sun Aug 4 22:02:42 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 4 Aug 2013 22:02:42 +0200 (CEST) Subject: [Eventstudies-commits] r111 - pkg Message-ID: <20130804200242.3761D18444A@r-forge.r-project.org> Author: vimsaa Date: 2013-08-04 22:02:41 +0200 (Sun, 04 Aug 2013) New Revision: 111 Modified: pkg/DESCRIPTION Log: Small change in Description. Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-08-04 20:01:02 UTC (rev 110) +++ pkg/DESCRIPTION 2013-08-04 20:02:41 UTC (rev 111) @@ -2,7 +2,7 @@ Type: Package Title: Event study and extreme event analysis Version: 1.1 -Author: Ajay Shah, Vikram Bahure +Author: Ajay Shah, Chirag Anand, Vikram Bahure Maintainer: Vikram Bahure Depends: R (>= 2.12.0), zoo, xts, boot, testthat, sandwich, exactRankTests, doMC, foreach Description: Implementation of short and long term event study methodology From noreply at r-forge.r-project.org Tue Aug 6 07:32:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 6 Aug 2013 07:32:43 +0200 (CEST) Subject: [Eventstudies-commits] r112 - pkg/R Message-ID: <20130806053243.251F9184BB4@r-forge.r-project.org> Author: chiraganand Date: 2013-08-06 07:32:42 +0200 (Tue, 06 Aug 2013) New Revision: 112 Modified: pkg/R/phys2eventtime.R Log: Fixed the timeshift function to take the previous date if the exact event date is not found. Modified: pkg/R/phys2eventtime.R =================================================================== --- pkg/R/phys2eventtime.R 2013-08-04 20:02:41 UTC (rev 111) +++ pkg/R/phys2eventtime.R 2013-08-06 05:32:42 UTC (rev 112) @@ -27,8 +27,11 @@ if (!firm.present) { return(list(result=NULL, outcome="unitmissing")) } - location <- match(as.Date(x[2]), index(z[,x[1]]), nomatch = -1) - if (location == -1 | location == 1 | !firm.present) { + # take the previous date if + # the exact event date is not + # found + location <- findInterval(as.Date(x[2]), index(z[, x[1]])) + if ((location <= 1) | (location >= length(index(z)))) { return(list(result=NULL, outcome="wrongspan")) } remapped <- zoo(as.numeric(z[,x[1]]), order.by=(-location+1):(length(z[,x[1]])-location)) From noreply at r-forge.r-project.org Tue Aug 6 10:58:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 6 Aug 2013 10:58:43 +0200 (CEST) Subject: [Eventstudies-commits] r113 - in pkg: R man vignettes Message-ID: <20130806085843.4637A185AB2@r-forge.r-project.org> Author: vikram Date: 2013-08-06 10:58:42 +0200 (Tue, 06 Aug 2013) New Revision: 113 Modified: pkg/R/AMM.R pkg/R/eventstudy.R pkg/man/AMM.Rd pkg/vignettes/eventstudies.Rnw Log: Fixed global variable error with event study function; modified AMM function to give only residuals, only firm exposure or all output Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-06 05:32:42 UTC (rev 112) +++ pkg/R/AMM.R 2013-08-06 08:58:42 UTC (rev 113) @@ -5,7 +5,7 @@ AMM <- function(amm.type = NULL, ...) { ## List of models currently supported - modelsList <- c("onefirm","manyfirms","firmExposures") + modelsList <- c("all","residual","firmExposures") if (is.null(amm.type) || length(amm.type) != 1) { stop("Argument amm.type not provided or incorrect") @@ -58,26 +58,63 @@ ## Assign values - ##----------- - ## One firm - ##----------- - if(amm.type == "onefirm") { + ##---- + ## AMM + ##---- + if(amm.type == "residual") { + ## One firm + if(NCOL(rj)==1){ # Checking required arguments + if (match("rj", names(modelArgs), nomatch = -1) == -1) { + stop("Input rj (firm data) is missing") + } + + X <- makeX(rM1, others, switch.to.innov, + rM1purge, nlags, dates, verbose) + result <- onefirmAMM(rj, X, nlags, verbose, dates) + result <- result$residuals + } + + ## Many firms + if(NCOL(rj)>1){ + # Checking required arguments if (match("rj", names(modelArgs), nomatch = -1) == -1) { stop("Input rj (firm data) is missing") } - + if(NCOL(rj)<2){ + stop("Less than two firms in inputData") + } + X <- makeX(rM1, others, switch.to.innov, rM1purge, nlags, dates, verbose) - result <- onefirmAMM(rj, X, nlags, verbose, dates) - result <- result$residuals + result <- xts() + for(i in 1:NCOL(rj)){ + tmp <- onefirmAMM(rj[,i], X, nlags, verbose, dates) + result <- merge(result,tmp$residuals) + } + colnames(result) <- colnames(rj) + } } - ##----------- - ## Many firms - ##----------- - if(amm.type == "manyfirms") { + ##---- + ## All + ##---- + if(amm.type == "all") { + ## One firm + if(NCOL(rj)==1){ # Checking required arguments + if (match("rj", names(modelArgs), nomatch = -1) == -1) { + stop("Input rj (firm data) is missing") + } + + X <- makeX(rM1, others, switch.to.innov, + rM1purge, nlags, dates, verbose) + result <- onefirmAMM(rj, X, nlags, verbose, dates) + } + + ## Many firms + if(NCOL(rj)>1){ + # Checking required arguments if (match("rj", names(modelArgs), nomatch = -1) == -1) { stop("Input rj (firm data) is missing") } @@ -87,14 +124,15 @@ X <- makeX(rM1, others, switch.to.innov, rM1purge, nlags, dates, verbose) - result <- xts() + result <- list() for(i in 1:NCOL(rj)){ tmp <- onefirmAMM(rj[,i], X, nlags, verbose, dates) - result <- merge(result,tmp$residuals) + result[[i]] <- tmp } - colnames(result) <- colnames(rj) + names(result) <- colnames(rj) + } } - + ##--------------- ## Firm exposures ##--------------- @@ -174,9 +212,8 @@ manyfirmsAMM <- function(regressand,regressors, lags,dates=NULL, periodnames=NULL,verbose=FALSE){ - # require("doMC") + require("doMC") registerDoMC() - cat("All available cores will be used for this program.\n") if(is.null(dates)){ dates=c(start(regressors),end(regressors)) periodnames="Full" Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-06 05:32:42 UTC (rev 112) +++ pkg/R/eventstudy.R 2013-08-06 08:58:42 UTC (rev 113) @@ -24,18 +24,9 @@ ### Run models ## AMM if (type == "AMM") { - if(amm.type == "onefirm"){ - tmp.outputModel <- AMM(rj = inputData, ...) - outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) - } - if(amm.type == "manyfirms"){ - tmp.outputModel <- AMM(rj = inputData, ...) - outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) - } - if(amm.type == "firmExposures"){ - stop("amm.type firmExposures not used for event study analysis") - } - + amm.type <- "residual" + tmp.outputModel <- AMM(rj = inputData, ...) + outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } ## marketResidual Modified: pkg/man/AMM.Rd =================================================================== --- pkg/man/AMM.Rd 2013-08-06 05:32:42 UTC (rev 112) +++ pkg/man/AMM.Rd 2013-08-06 08:58:42 UTC (rev 113) @@ -11,8 +11,7 @@ } \arguments{ - \item{amm.type}{Type of AMM to be performed: On one firm "onefirm" or - just firm exposure "firmExposures"} + \item{amm.type}{If amm.type take following inputs: all, residual and firmExposures. If amm.type is residual it gives only AMM residual as output, if amm.type is firmExposures then it gives only firm exposure as output else if all output is needed then option all is used.} \item{...}{Accepts specific arguments for the model.} } \value{The function returns the exposures, HAC adjusted standard @@ -33,7 +32,6 @@ \author{Vikram Bahure} \seealso{ \code{\link{firmExposures}}, -\code{\link{manyfirmsAMM}} \code{\link{onefirmAMM}}} \examples{ @@ -47,7 +45,7 @@ regressand <- cbind(Company_A,Company_B,Company_C) ## One firm -of <- AMM(amm.type="onefirm",rj=Company_A, +of <- AMM(amm.type="residual",rj=Company_A, verbose=TRUE, dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-06 05:32:42 UTC (rev 112) +++ pkg/vignettes/eventstudies.Rnw 2013-08-06 08:58:42 UTC (rev 113) @@ -188,8 +188,8 @@ Company_C <- y3c3$Company_C regressand <- cbind(Company_A,Company_B,Company_C) -## One firm -of <- AMM(amm.type="onefirm",rj=Company_A, +## AMM output +of <- AMM(amm.type="all",rj=Company_A, nlags=NA, verbose=TRUE, dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", @@ -327,21 +327,21 @@ cn.names <- which(colnames(all.data)%in%c("nifty","inr")) stock.data <- all.data[,-cn.names] -of <- AMM(amm.type="onefirm",rj=y3c3$Company_A, +of <- AMM(amm.type="residual",rj=y3c3$Company_A, verbose=TRUE, dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -of1 <- AMM(amm.type="onefirm",rj=y3c3$Company_A, +of1 <- AMM(amm.type="all",rj=y3c3$Company_A, verbose=TRUE, dates= NULL, rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -of.r <- AMM(amm.type="manyfirms", rj=stock.data[,1:5],verbose=TRUE, dates=NULL, +of.r <- AMM(amm.type="residual", rj=stock.data[,1:5],verbose=TRUE, dates=NULL, rM1=all.data$nifty, others=all.data$inr, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) @@ -350,7 +350,7 @@ width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "bootstrap", - type = "AMM", amm.type="manyfirms", + type = "AMM", amm.type="residual", rM1=all.data$nifty, others=all.data$inr, nlags=1, verbose=TRUE, dates= NULL, From noreply at r-forge.r-project.org Tue Aug 6 13:08:14 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 6 Aug 2013 13:08:14 +0200 (CEST) Subject: [Eventstudies-commits] r114 - pkg/vignettes Message-ID: <20130806110814.8E51B185B22@r-forge.r-project.org> Author: vikram Date: 2013-08-06 13:08:14 +0200 (Tue, 06 Aug 2013) New Revision: 114 Modified: pkg/vignettes/eventstudies.Rnw Log: Added some code in vignette and minor modifications Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-06 08:58:42 UTC (rev 113) +++ pkg/vignettes/eventstudies.Rnw 2013-08-06 11:08:14 UTC (rev 114) @@ -115,7 +115,7 @@ \section{Software approach} \label{s:approach} The package offers the following functionalities: - \item Models for calculating returns. These include: + Models for calculating returns. These include: \begin{itemize} \item Excess returns model \item Market residual model @@ -189,14 +189,22 @@ regressand <- cbind(Company_A,Company_B,Company_C) ## AMM output -of <- AMM(amm.type="all",rj=Company_A, - nlags=NA, - verbose=TRUE, - dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", - "2008-01-05","2009-01-03")), - rM1=NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +## With no structural break dates: dates=NULL +result1 <- AMM(amm.type="all",rj=y3c3$Company_A, + verbose=TRUE, + dates= NULL, + rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, + switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +## With AMM different structural periods +result2 <- AMM(amm.type="all",rj=Company_A, + nlags=NA, + verbose=TRUE, + dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", + "2008-01-05","2009-01-03")), + rM1=NIFTY_INDEX, others=INRUSD, + switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + @ \subsection{Converting physical dates to event frame} The first step towards event study analysis is to convert the physical @@ -230,7 +238,7 @@ In this example, es.w contains the returns in event-time form for all the stocks. In this you only get variables for whom all data is -avaialable. +available. \subsection{Remapping event frame} In event study analysis the variable of interest is cumulative @@ -274,7 +282,7 @@ \subsubsection{Wilcoxon signed rank tests} It is a non-parametric inference test to compute confidence interval. <<>>= -result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) +result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) @ \begin{figure}[t] \begin{center} @@ -327,24 +335,6 @@ cn.names <- which(colnames(all.data)%in%c("nifty","inr")) stock.data <- all.data[,-cn.names] -of <- AMM(amm.type="residual",rj=y3c3$Company_A, - verbose=TRUE, - dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", - "2008-01-05","2009-01-03")), - rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) - -of1 <- AMM(amm.type="all",rj=y3c3$Company_A, - verbose=TRUE, - dates= NULL, - rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) - - -of.r <- AMM(amm.type="residual", rj=stock.data[,1:5],verbose=TRUE, dates=NULL, - rM1=all.data$nifty, others=all.data$inr, switch.to.innov=TRUE, - rM1purge=TRUE, nlags=1) - es.amm <- eventstudy(inputData = stock.data, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", From noreply at r-forge.r-project.org Tue Aug 6 17:46:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 6 Aug 2013 17:46:54 +0200 (CEST) Subject: [Eventstudies-commits] r115 - pkg/man Message-ID: <20130806154654.BBEB5180554@r-forge.r-project.org> Author: chiraganand Date: 2013-08-06 17:46:54 +0200 (Tue, 06 Aug 2013) New Revision: 115 Modified: pkg/man/phys2eventtime.Rd Log: Added explanation for taking previous date if an event date is not found. Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2013-08-06 11:08:14 UTC (rev 114) +++ pkg/man/phys2eventtime.Rd 2013-08-06 15:46:54 UTC (rev 115) @@ -6,7 +6,7 @@ } \description{ -Given a zoo time-series vector and an event date, it converts the physical date to the event date. The event date becomes zero and all other dates shift accordingly. +Given a zoo time-series and event dates, it converts the physical dates to event dates. The event date becomes zero and all other dates shift accordingly. } \usage{ @@ -16,12 +16,17 @@ \arguments{ \item{z}{Time series data for which event frame is to be generated.} - \item{events}{It is a data frame with two columns: unit and when. unit has column name of which response is to measured on the event date, while when has the event date.} + \item{events}{It is a data frame with two columns: unit and when. unit + has column name of which response is to measured on the event date, + while when has the event date. See details.} \item{width}{Width corresponds to the number of days on each side of the event date.For a given width, if there is any NA in the event window then the last observation is carried forward.} } +\details{ If an event date is not found, the function takes the previous + value of date in index(z) as the event date. } + \value{Output is in a list format. A zoo object indexed with event time and a vector which describes the status of each unit in the original data. } From noreply at r-forge.r-project.org Wed Aug 7 13:05:59 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 7 Aug 2013 13:05:59 +0200 (CEST) Subject: [Eventstudies-commits] r116 - pkg/vignettes Message-ID: <20130807110559.AB5D51811AF@r-forge.r-project.org> Author: renukasane Date: 2013-08-07 13:05:59 +0200 (Wed, 07 Aug 2013) New Revision: 116 Modified: pkg/vignettes/eventstudies.Rnw Log: Small modification to the vignette. Work in progress still. Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-06 15:46:54 UTC (rev 115) +++ pkg/vignettes/eventstudies.Rnw 2013-08-07 11:05:59 UTC (rev 116) @@ -31,8 +31,9 @@ of specific events on the value of the firm. The typical procedure for conducting an event study involves \citep{MacKinlay} \begin{itemize} - \item Defining the event of interest and the event window which is - larger than the specific period of interest. % Generally the event +\item Defining the event of interest and the event window. The event + window is larger than the specific period of + interest. % Generally the event % period itself is not included in the estimation period to prevent % the event from influencing the normal performance model parameter % estimates. @@ -44,13 +45,17 @@ on stock prices of information that is specific to the firm under question (e.g. stock split annoucement) and information that is likely to affect stock prices marketwide (e.g. interest rates) + \item Analysis of firm returns around the event date \end{itemize} -The \textbf{eventstudies} package makes possible BLAH. All functions -in this package are implemented in the R system for statistical -computing. The package, and R are available at no cost under the terms -of the general public license (GPL) from the comprehensive R archive -network (CRAN, \texttt{http://CRAN.R-project.org}). +The \textbf{eventstudies} package brings together the various aspects +of an event study analysis in one library. It provides for functions +to calculate returns, transform data into event-time, and conduct +inference on the unit of interest. All functions in this package are +implemented in the R system for statistical computing. The package, +and R are available at no cost under the terms of the general public +license (GPL) from the comprehensive R archive network (CRAN, +\texttt{http://CRAN.R-project.org}). This paper is organised as follows. A skeletal event study model is presented in Section \ref{s::model}. Section \ref{s:approach} @@ -61,19 +66,11 @@ inference in section \ref{ss:inference}. Section \ref{s:conclusion} conclues the paper. +\section{Skeletal event study model} \label{s:model} +In this section, we present a model to evaluate the impact of stock +splits on returns. -% In this package, there are three major functions -% \textit{phys2eventtime}, \textit{remap.cumsum} and -% \textit{inference.Ecar}. \textit{phys2eventtime} changes the -% physical dates to event time frame on which event study analysis can -% be done with ease. \textit{remap.cumsum} -% can be used to convert returns to cumulative sum or product in the -% event time frame. \textit{inference.Ecar} generates bootstrap -% inference for the event time response of the variable. - -\section{Skeletal event study model} \label{s:model} - Let day-0 identify the stock split date under scrutiny and let days t = ... -3,-2,-1 represent trading days leading up to the event. If the return on the firm with the stock split $R_o$ is statistically @@ -111,33 +108,41 @@ statistical significance is that abnormal returns are normally distributed. - \section{Software approach} \label{s:approach} The package offers the following functionalities: - - Models for calculating returns. These include: - \begin{itemize} - \item Excess returns model - \item Market residual model - \item Augmented market model (AMM) - \end{itemize} - -\begin{itemize} +\begin{enumerate} + \item Models for calculating returns. These include: + \begin{itemize} + \item \texttt{excessReturn}: estimation of excess return i.e. $R_j - + R_m$ where $R_j$ is the return of firm $j$ and $R_m$ is the market + return. + \item \texttt{marketResidual}: estimation of market residual after + extracting market returns from firm returns. + \item \texttt{AMM}: estimation of market residual after extracting + market returns and currency returns from firm returns. + \end{itemize} \item Coverting the data-set to an event frame. This requires: \begin{itemize} \item A time series object of stock price returns \item Event dates object with two columns, \textit{unit} and \textit{when}, the date of occurrence of the event. \end{itemize} - \item Procedures for inference. These include: \begin{itemize} \item Bootstrapping \item Wilcoxon signed rank test \end{itemize} -\end{itemize} +\end{enumerate} +The first argument of the first two models is the \texttt{data.oject} +which is a time-series of stock returns. The second argument is +\texttt{market.name}, a column name indicating market returns. + +The output from these two models is another time-series object which +is used for converting to event time. + + \section{Example: Performing Eventstudy analysis} \label{s:example} @@ -147,6 +152,8 @@ Exchange (BSE), from 2001 to 2013. We have stock split dates for each firm from 2000 onwards. +\subsection{Basic data files} + We first create a \textit{zoo} object for stock price returns for the thirty firms. For event dates, a data frame with two columns \textit{unit} and \textit{when} is formed. \textit{unit} has name of @@ -163,6 +170,8 @@ head(SplitDates) @ +\subsection{Calculating returns} + \subsection{Using the market model} <<>>= data(StockPriceReturns) @@ -170,6 +179,7 @@ er.result <- excessReturn(market.name="nifty", data.object=StockPriceReturns) + @ <<>>= @@ -196,6 +206,8 @@ rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + + ## With AMM different structural periods result2 <- AMM(amm.type="all",rj=Company_A, nlags=NA, @@ -206,6 +218,9 @@ switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) @ + + + \subsection{Converting physical dates to event frame} The first step towards event study analysis is to convert the physical dates to event time frame. The event date and the returns on that From noreply at r-forge.r-project.org Wed Aug 7 14:13:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 7 Aug 2013 14:13:28 +0200 (CEST) Subject: [Eventstudies-commits] r117 - in pkg: R data man vignettes Message-ID: <20130807121328.A0CCB185160@r-forge.r-project.org> Author: vikram Date: 2013-08-07 14:13:22 +0200 (Wed, 07 Aug 2013) New Revision: 117 Modified: pkg/R/AMM.R pkg/data/StockPriceReturns.rda pkg/man/StockPriceReturns.Rd pkg/vignettes/eventstudies.Rnw Log: Using only one data-set for all examples for consistency Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-07 11:05:59 UTC (rev 116) +++ pkg/R/AMM.R 2013-08-07 12:13:22 UTC (rev 117) @@ -171,6 +171,7 @@ res <- firmExposures(rj,X,verbose=verbose,nlags=nlags) exposures <- res$exposure sds <- res$s.exposure + m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) if(residual==TRUE){ m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) } @@ -178,9 +179,9 @@ tmp <- window(rj,start=dates[1],end=dates[1+1]) rhs <- window(X,start=dates[1],end=dates[1+1]) res <- firmExposures(rj=tmp, - X=rhs, - verbose=verbose, - nlags=nlags) + X=rhs, + verbose=verbose, + nlags=nlags) exposures[1,] <- res$exposure periodnames <- c(periodnames,paste(dates[1],dates[1+1],sep=" TO ")) sds[1,] <- res$s.exposure Modified: pkg/data/StockPriceReturns.rda =================================================================== (Binary files differ) Modified: pkg/man/StockPriceReturns.Rd =================================================================== --- pkg/man/StockPriceReturns.Rd 2013-08-07 11:05:59 UTC (rev 116) +++ pkg/man/StockPriceReturns.Rd 2013-08-07 12:13:22 UTC (rev 117) @@ -7,7 +7,7 @@ \title{It is the data-set used for event-study analysis.} \description{ -It has stock price returns for index constituents of Bombay Stock Exchange (BSE). +It has stock price returns for index constituents of Bombay Stock Exchange (BSE), nifty index and INR/USD returns. } \usage{data(StockPriceReturns)} Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-07 11:05:59 UTC (rev 116) +++ pkg/vignettes/eventstudies.Rnw 2013-08-07 12:13:22 UTC (rev 117) @@ -190,32 +190,34 @@ %AMM model <<>>= # Create RHS before running AMM() -data("y3c3") -NIFTY_INDEX <- y3c3$NIFTY_INDEX -INRUSD <- y3c3$INRUSD -Company_A <- y3c3$Company_A -Company_B <- y3c3$Company_B -Company_C <- y3c3$Company_C -regressand <- cbind(Company_A,Company_B,Company_C) +nifty.index <- StockPriceReturns$nifty +inrusd <- StockPriceReturns$inr ## AMM output -## With no structural break dates: dates=NULL -result1 <- AMM(amm.type="all",rj=y3c3$Company_A, - verbose=TRUE, - dates= NULL, - rM1=y3c3$NIFTY_INDEX, others=y3c3$INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +## For Full period: dates=NULL +amm.residual <- AMM(amm.type="residual",rj=StockPriceReturns[,1:3], + verbose=TRUE, + dates= NULL, + rM1=nifty.index, others=inrusd, + switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +amm.output <- AMM(amm.type="all",rj=StockPriceReturns[,1:3], + verbose=TRUE, + dates= NULL, + rM1=nifty.index, others=inrusd, + switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -## With AMM different structural periods -result2 <- AMM(amm.type="all",rj=Company_A, - nlags=NA, - verbose=TRUE, - dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", - "2008-01-05","2009-01-03")), - rM1=NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) +## ## With AMM different structural periods +## structural.break.dates <- c(start(StockPriceReturns),as.Date("2007-01-06"), +## end(StockPriceReturns)) +## amm.output.different.periods <- AMM(amm.type = "all",rj = StockPriceReturns[,1], +## nlags = NA, +## verbose =TRUE, +## dates = structural.break.dates, +## rM1 = nifty.index, others = inrusd, +## switch.to.innov = TRUE, rM1purge = TRUE, +## nlags = 1) @ @@ -342,13 +344,8 @@ type = "excessReturn", market.name = "nifty") ## Event study using augmented market model (AMM) and bootstrap -data(inr) -inrusd <- zoo(diff(log(inr))*100,index(inr)) -all.data <- merge(StockPriceReturns,inrusd, all = FALSE) -all.data <- window(all.data, start="2004-01-01") -all.data <- all.data[-which(is.na(all.data$nifty)),] -cn.names <- which(colnames(all.data)%in%c("nifty","inr")) -stock.data <- all.data[,-cn.names] +cn.names <- which(colnames(StockPriceReturns)%in%c("nifty","inr")) +stock.data <- StockPriceReturns[,-cn.names] es.amm <- eventstudy(inputData = stock.data, eventList = SplitDates, @@ -356,7 +353,7 @@ to.plot = TRUE, inference = TRUE, inference.strategy = "bootstrap", type = "AMM", amm.type="residual", - rM1=all.data$nifty, others=all.data$inr, + rM1=StockPriceReturns$nifty, others=StockPriceReturns$inr, nlags=1, verbose=TRUE, dates= NULL, switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) From noreply at r-forge.r-project.org Wed Aug 7 14:47:06 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 7 Aug 2013 14:47:06 +0200 (CEST) Subject: [Eventstudies-commits] r118 - in pkg: man vignettes Message-ID: <20130807124706.7BE96185111@r-forge.r-project.org> Author: vikram Date: 2013-08-07 14:47:05 +0200 (Wed, 07 Aug 2013) New Revision: 118 Modified: pkg/man/AMM.Rd pkg/vignettes/eventstudies.Rnw Log: minor changes in vignette Modified: pkg/man/AMM.Rd =================================================================== --- pkg/man/AMM.Rd 2013-08-07 12:13:22 UTC (rev 117) +++ pkg/man/AMM.Rd 2013-08-07 12:47:05 UTC (rev 118) @@ -16,7 +16,7 @@ } \value{The function returns the exposures, HAC adjusted standard errors, the number of lags used, and the residuals from the fitted - model. Default is NULL. + model. Default is NULL. \item{exposures}{This contains the exposure estimates for the firm j} Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-07 12:13:22 UTC (rev 117) +++ pkg/vignettes/eventstudies.Rnw 2013-08-07 12:47:05 UTC (rev 118) @@ -244,13 +244,12 @@ <<>>= es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10) str(es) -head(es$outcomes) +es$outcomes es.w <- window(es$z.e, start=-10, end=10) -SplitDates[1:3,] +colnames(es.w) <- SplitDates[which(es$outcomes=="success"),1] +SplitDates[1,] StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] -StockPriceReturns[SplitDates[2,2],SplitDates[2,1]] -StockPriceReturns[SplitDates[3,2],SplitDates[3,1]] -es.w[,1:3] +es.w[,1] @ In this example, es.w contains the returns in event-time form for all @@ -263,7 +262,7 @@ convert the returns to cumulative returns. <<>>= es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) -es.cs[,1:3] +es.cs[,1] @ \subsection{Inference procedures} From noreply at r-forge.r-project.org Thu Aug 8 07:31:58 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 8 Aug 2013 07:31:58 +0200 (CEST) Subject: [Eventstudies-commits] r119 - pkg/vignettes Message-ID: <20130808053158.8EFDA185061@r-forge.r-project.org> Author: renukasane Date: 2013-08-08 07:31:57 +0200 (Thu, 08 Aug 2013) New Revision: 119 Modified: pkg/vignettes/eventstudies.Rnw Log: Slightly updated version - still work in progress. Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-07 12:47:05 UTC (rev 118) +++ pkg/vignettes/eventstudies.Rnw 2013-08-08 05:31:57 UTC (rev 119) @@ -110,39 +110,57 @@ \section{Software approach} \label{s:approach} The package offers the following functionalities: -\begin{enumerate} - \item Models for calculating returns. These include: +\begin{itemize} + \item Models for calculating returns + \item Coverting data to event-frame and remapping event-frame + \item Procedures for inference +\end{itemize} + +\subsection*{Models for calculating returns} + \begin{itemize} \item \texttt{excessReturn}: estimation of excess return i.e. $R_j - R_m$ where $R_j$ is the return of firm $j$ and $R_m$ is the market return. \item \texttt{marketResidual}: estimation of market residual after - extracting market returns from firm returns. - \item \texttt{AMM}: estimation of market residual after extracting - market returns and currency returns from firm returns. + extracting market returns from firm returns. + + The first argument of the two functions is the \texttt{data.oject} + which is a time-series of stock returns. The second argument is + \texttt{market.name}, a column name indicating market returns. + + \item \texttt{AMM}: estimation of the Augmented market model which + gives the market residual after extracting market returns and + currency returns from firm returns. The function allows for + specifying the type of the AMM model as well. \end{itemize} - \item Coverting the data-set to an event frame. This requires: + + The output from these models is another time-series object which is + used for converting to event time. + + \subsection*{Coverting the data-set to an event frame} + These include: \begin{itemize} - \item A time series object of stock price returns - \item Event dates object with two columns, \textit{unit} and - \textit{when}, the date of occurrence of the event. + \item \texttt{phys2eventtime}: conversion to an event frame. This + requires a time series object of stock price returns and an + object with two columns \textit{unit} and \textit{when}, the date + of occurrence of the event. + + \item \texttt{remap.cumsum}: conversion of returns to cumulative + returns \end{itemize} - \item Procedures for inference. These include: + + \subsection*{Procedures for inference} + These include: \begin{itemize} - \item Bootstrapping - \item Wilcoxon signed rank test + \item \texttt{inference.bootstrap}: estimation of bootstrap to + generate the distribution of cumulative returns series. + \item \texttt{inference.wilcox}: estimation of wilcox inference to + generate the distribution of cumulative returns series. \end{itemize} \end{enumerate} - -The first argument of the first two models is the \texttt{data.oject} -which is a time-series of stock returns. The second argument is -\texttt{market.name}, a column name indicating market returns. - -The output from these two models is another time-series object which -is used for converting to event time. - - + \section{Example: Performing Eventstudy analysis} \label{s:example} @@ -150,41 +168,40 @@ on the stock price of the firm. The data-set consist of the returns series of the thirty index companies, as of 2013, of the Bombay Stock Exchange (BSE), from 2001 to 2013. We have stock split dates for each -firm from 2000 onwards. +firm from 2000 onwards. -\subsection{Basic data files} - We first create a \textit{zoo} object for stock price returns for the -thirty firms. For event dates, a data frame with two columns -\textit{unit} and \textit{when} is formed. \textit{unit} has name of -the response series (firm name as in column name of time series -object) along with event date in \textit{when}. \textit{unit} should -be in \textit{character} format and \textit{when} in \textit{Date} -format. +thirty firms. This is called \textit{StockPriceReturns}. The column +\texttt{nifty} is the market return and \texttt{inr} the INR-USD +exchange rate. <<>>= library(eventstudies) data(StockPriceReturns) str(StockPriceReturns) -data(SplitDates) -head(SplitDates) +head(StockPriceReturns) @ \subsection{Calculating returns} -\subsection{Using the market model} +The function \texttt{excessReturn} calculates the excess returns while +\texttt{marketResidual} calculates the market model. It requires the +user to specify the \texttt{market.name} and \texttt{data.object}. The +result is stored in \texttt{er.result}. + <<>>= data(StockPriceReturns) # Excess return er.result <- excessReturn(market.name="nifty", data.object=StockPriceReturns) +head(er.result) - @ - <<>>= # Extracting market residual mm.result <- marketResidual(data.object=StockPriceReturns, market.name="nifty") +head(mm.result) + @ %AMM model @@ -208,29 +225,31 @@ switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) -## ## With AMM different structural periods -## structural.break.dates <- c(start(StockPriceReturns),as.Date("2007-01-06"), -## end(StockPriceReturns)) -## amm.output.different.periods <- AMM(amm.type = "all",rj = StockPriceReturns[,1], -## nlags = NA, -## verbose =TRUE, -## dates = structural.break.dates, -## rM1 = nifty.index, others = inrusd, -## switch.to.innov = TRUE, rM1purge = TRUE, -## nlags = 1) @ +\subsection{Conversion to event frame} -\subsection{Converting physical dates to event frame} -The first step towards event study analysis is to convert the physical -dates to event time frame. The event date and the returns on that -date are indexed to 0. Post-event dates are indexed to positive, and -pre-event dates as negative. This is done using the -\textit{phys2eventtime} function. +Before the data is converted to event frame, we need to know the dates +of interest. This is done with a data frame with two columns +\textit{unit} and \textit{when}. \textit{unit} has name of +the response series (firm name as in column name of time series +object) along with event date in \textit{when}. \textit{unit} should +be in \textit{character} format and \textit{when} in \textit{Date} +format. -The output for \textit{phys2eventtime} is a list. The first element of +<<>>= +data(SplitDates) +head(SplitDates) +@ + + +The event date and the returns on that date are indexed to +0. Post-event dates are indexed to positive, and pre-event dates as +negative. This is done using the \texttt{phys2eventtime} function. + +The output for \texttt{phys2eventtime} is a list. The first element of a list is a time series object which is converted to event time and the second element is \textit{outcomes} which shows if there was any \textit{NA} in the dataset. If the outcome is \textit{success} @@ -256,10 +275,9 @@ the stocks. In this you only get variables for whom all data is available. -\subsection{Remapping event frame} In event study analysis the variable of interest is cumulative -returns. The \textit{remap.cumsum} function is used to -convert the returns to cumulative returns. +returns. The \texttt{remap.cumsum} function is used to convert the +returns to cumulative returns. <<>>= es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) es.cs[,1] From noreply at r-forge.r-project.org Thu Aug 8 13:42:17 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 8 Aug 2013 13:42:17 +0200 (CEST) Subject: [Eventstudies-commits] r120 - in pkg: R data man vignettes Message-ID: <20130808114217.23A21185B36@r-forge.r-project.org> Author: vikram Date: 2013-08-08 13:42:16 +0200 (Thu, 08 Aug 2013) New Revision: 120 Modified: pkg/R/AMM.R pkg/R/eventstudy.R pkg/R/excessReturn.R pkg/R/marketResidual.R pkg/data/StockPriceReturns.rda pkg/data/inr.rda pkg/man/excessReturn.Rd pkg/man/firmExposures.Rd pkg/man/makeX.Rd pkg/man/manyfirmsAMM.Rd pkg/man/marketResidual.Rd pkg/man/onefirmAMM.Rd pkg/vignettes/eventstudies.Rnw Log: Changed market residual function, excess return function to match with AMM arguments; Work in progress Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/R/AMM.R 2013-08-08 11:42:16 UTC (rev 120) @@ -15,9 +15,9 @@ } # NULLify all the values before use - rj <- NULL - rM1 <- NULL - rM1purge <- NULL + firm.returns <- NULL + market.returns <- NULL + market.returns.purge <- NULL nlags <- NULL others <- NULL switch.to.innov <- NULL @@ -32,14 +32,14 @@ } # Checking required arguments - if (match("rM1", names(modelArgs), nomatch = -1) == -1) { - stop("Input rM1 (stock market index) is missing") + if (match("market.returns", names(modelArgs), nomatch = -1) == -1) { + stop("Input market.returns (stock market index) is missing") } if (match("others", names(modelArgs), nomatch = -1) == -1) { stop("Input 'others' (time series of other regressor or interest) is missing") } - if (match("rM1purge", names(modelArgs), nomatch = -1) == -1) { - stop("Input rM1purge is missing") + if (match("market.returns.purge", names(modelArgs), nomatch = -1) == -1) { + stop("Input market.returns.purge is missing") } if (match("switch.to.innov", names(modelArgs), nomatch = -1) == -1) { stop("Input switch.to.innov is missing") @@ -63,36 +63,36 @@ ##---- if(amm.type == "residual") { ## One firm - if(NCOL(rj)==1){ + if(NCOL(firm.returns)==1){ # Checking required arguments - if (match("rj", names(modelArgs), nomatch = -1) == -1) { - stop("Input rj (firm data) is missing") + if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { + stop("Input firm.returns (firm data) is missing") } - X <- makeX(rM1, others, switch.to.innov, - rM1purge, nlags, dates, verbose) - result <- onefirmAMM(rj, X, nlags, verbose, dates) + X <- makeX(market.returns, others, switch.to.innov, + market.returns.purge, nlags, dates, verbose) + result <- onefirmAMM(firm.returns, X, nlags, verbose, dates) result <- result$residuals } ## Many firms - if(NCOL(rj)>1){ + if(NCOL(firm.returns)>1){ # Checking required arguments - if (match("rj", names(modelArgs), nomatch = -1) == -1) { - stop("Input rj (firm data) is missing") + if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { + stop("Input firm.returns (firm data) is missing") } - if(NCOL(rj)<2){ + if(NCOL(firm.returns)<2){ stop("Less than two firms in inputData") } - X <- makeX(rM1, others, switch.to.innov, - rM1purge, nlags, dates, verbose) + X <- makeX(market.returns, others, switch.to.innov, + market.returns.purge, nlags, dates, verbose) result <- xts() - for(i in 1:NCOL(rj)){ - tmp <- onefirmAMM(rj[,i], X, nlags, verbose, dates) + for(i in 1:NCOL(firm.returns)){ + tmp <- onefirmAMM(firm.returns[,i], X, nlags, verbose, dates) result <- merge(result,tmp$residuals) } - colnames(result) <- colnames(rj) + colnames(result) <- colnames(firm.returns) } } @@ -101,35 +101,35 @@ ##---- if(amm.type == "all") { ## One firm - if(NCOL(rj)==1){ + if(NCOL(firm.returns)==1){ # Checking required arguments - if (match("rj", names(modelArgs), nomatch = -1) == -1) { - stop("Input rj (firm data) is missing") + if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { + stop("Input firm.returns (firm data) is missing") } - X <- makeX(rM1, others, switch.to.innov, - rM1purge, nlags, dates, verbose) - result <- onefirmAMM(rj, X, nlags, verbose, dates) + X <- makeX(market.returns, others, switch.to.innov, + market.returns.purge, nlags, dates, verbose) + result <- onefirmAMM(firm.returns, X, nlags, verbose, dates) } ## Many firms - if(NCOL(rj)>1){ + if(NCOL(firm.returns)>1){ # Checking required arguments - if (match("rj", names(modelArgs), nomatch = -1) == -1) { - stop("Input rj (firm data) is missing") + if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { + stop("Input firm.returns (firm data) is missing") } - if(NCOL(rj)<2){ + if(NCOL(firm.returns)<2){ stop("Less than two firms in inputData") } - X <- makeX(rM1, others, switch.to.innov, - rM1purge, nlags, dates, verbose) + X <- makeX(market.returns, others, switch.to.innov, + market.returns.purge, nlags, dates, verbose) result <- list() - for(i in 1:NCOL(rj)){ - tmp <- onefirmAMM(rj[,i], X, nlags, verbose, dates) + for(i in 1:NCOL(firm.returns)){ + tmp <- onefirmAMM(firm.returns[,i], X, nlags, verbose, dates) result[[i]] <- tmp } - names(result) <- colnames(rj) + names(result) <- colnames(firm.returns) } } @@ -138,14 +138,14 @@ ##--------------- if (amm.type=="firmExposures") { # Checking required arguments - if (match("rj", names(modelArgs), nomatch = -1) == -1) { - stop("Input rj (firm data) is missing") + if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { + stop("Input firm.returns (firm data) is missing") } - X <- makeX(rM1, others, switch.to.innov, - rM1purge, nlags, dates, verbose) + X <- makeX(market.returns, others, switch.to.innov, + market.returns.purge, nlags, dates, verbose) - result <- firmExposures(rj, X, nlags, verbose) + result <- firmExposures(firm.returns, X, nlags, verbose) } return(result) @@ -154,10 +154,10 @@ ####################### # AMM for one firm ####################### -onefirmAMM <- function(rj,X,nlags=1,verbose=FALSE,dates=NULL,residual=TRUE){ +onefirmAMM <- function(firm.returns,X,nlags=1,verbose=FALSE,dates=NULL,residual=TRUE){ ## Creating empty frames if(is.null(dates)){ - dates.no <- c(start(rj),end(rj)) + dates.no <- c(start(firm.returns),end(firm.returns)) } else{ dates.no <- dates } @@ -168,7 +168,7 @@ ## Getting firm exposure, amm residuals if(is.null(dates)){ - res <- firmExposures(rj,X,verbose=verbose,nlags=nlags) + res <- firmExposures(firm.returns,X,verbose=verbose,nlags=nlags) exposures <- res$exposure sds <- res$s.exposure m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) @@ -176,9 +176,9 @@ m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) } }else{ - tmp <- window(rj,start=dates[1],end=dates[1+1]) + tmp <- window(firm.returns,start=dates[1],end=dates[1+1]) rhs <- window(X,start=dates[1],end=dates[1+1]) - res <- firmExposures(rj=tmp, + res <- firmExposures(firm.returns=tmp, X=rhs, verbose=verbose, nlags=nlags) @@ -188,9 +188,9 @@ m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) colnames(m.residuals) <- paste(dates[1],"to",dates[1+1],sep=".") for(i in 2:(length(dates)-1)){ - tmp <- window(rj,start=dates[i],end=dates[i+1]) + tmp <- window(firm.returns,start=dates[i],end=dates[i+1]) rhs <- window(X,start=dates[i],end=dates[i+1]) - res <- firmExposures(rj=tmp, + res <- firmExposures(firm.returns=tmp, X=rhs, verbose=verbose, nlags=nlags) @@ -248,8 +248,8 @@ for(i in 1:ncol(regressand)){ cat("Doing",colnames(regressand)[i]) if (verbose) {cat ("Doing", colnames(regressand)[i])} - rj <- regressand[,i] - dataset <- cbind(rj, regressors) # This is the full time-series + firm.returns <- regressand[,i] + dataset <- cbind(firm.returns, regressors) # This is the full time-series this.exp <- this.sds <- NULL for(j in 1:nperiods){ # now we chop it up t1 <- dates[j] @@ -269,10 +269,10 @@ ############################################### # Estimating one firm's exposure in one period. ############################################### -firmExposures <- function(rj, X, nlags=NA, verbose=FALSE) { +firmExposures <- function(firm.returns, X, nlags=NA, verbose=FALSE) { do.ols <- function(nlags) { - tmp <- cbind(rj, X[,1]) # Assume 1st is stock index, and no lags are required there. - labels <- c("rj","rM1") + tmp <- cbind(firm.returns, X[,1]) # Assume 1st is stock index, and no lags are required there. + labels <- c("firm.returns","market.returns") if (NCOL(X) > 1) { for (i in 2:NCOL(X)) { for (j in 0:nlags) { @@ -287,7 +287,7 @@ } colnames(tmp) <- labels # So the OLS results will look nice - lm(rj ~ ., data=as.data.frame(tmp)) + lm(firm.returns ~ ., data=as.data.frame(tmp)) } if (is.na(nlags)) { @@ -295,7 +295,7 @@ bestlag <- 0 bestm <- NULL bestAIC <- Inf - for (trylag in 0:min(10,log10(length(rj)))) { + for (trylag in 0:min(10,log10(length(firm.returns)))) { thism <- do.ols(trylag) thisAIC <- AIC(thism, k=log(length(thism$fitted.values))) if (verbose) {cat(trylag, " lags, SBC = ", thisAIC, "\n")} @@ -317,11 +317,11 @@ # Compute a series of exposure measures, and their standard errors. beta <- m$coefficients Sigma <- vcovHAC(m) - # First the rM1 - exposures <- beta[2] # no lags for rM1 + # First the market.returns + exposures <- beta[2] # no lags for market.returns s.exposures <- sqrt(Sigma[2,2]) # From here on, there's a block of 1+nlags coeffs for each - # of the non-rM1 regressors. + # of the non-market.returns regressors. if (NCOL(X) > 1) { for (i in 2:NCOL(X)) { n.block1 <- 2 + ((i-2)*(1+nlags)) # Just 2 for the 1st case. @@ -364,8 +364,8 @@ # --------------------------------------------------------------------------- # The workhorse called by makeX to return a nice matrix of RHS # variables to be used in an analysis. -do.one.piece <- function(rM1, others, switch.to.innov, rM1purge, nlags, verbose=FALSE) { - thedates <- index(rM1) +do.one.piece <- function(market.returns, others, switch.to.innov, market.returns.purge, nlags, verbose=FALSE) { + thedates <- index(market.returns) if (verbose) { cat(" Doing work for period from ", as.character(head(thedates,1)), " to ", @@ -392,8 +392,8 @@ } } if (NCOL(innov) > 1) {colnames(innov) <- colnames(others)} - rM1.purged <- rM1 - if (rM1purge) { + market.returns.purged <- market.returns + if (market.returns.purge) { firstpass <- TRUE for (i in 1:NCOL(innov)) { for (j in 0:nlags) { @@ -408,41 +408,41 @@ } } if (NCOL(z) > 1) {colnames(z) <- labels} - m <- lm(rM1 ~ ., as.data.frame(cbind(rM1, z))) + m <- lm(market.returns ~ ., as.data.frame(cbind(market.returns, z))) if (verbose) { - cat(" Model explaining rM1:\n") + cat(" Model explaining market.returns:\n") print(summary(m)) } how.many.NAs <- nlags + max(otherlags) - rM1.purged <- zoo(c(rep(NA,how.many.NAs),m$residuals), + market.returns.purged <- zoo(c(rep(NA,how.many.NAs),m$residuals), order.by=thedates) } # if (verbose) {cat(" Finished do.one.piece()\n")} - list(rM1.purged=rM1.purged, innov=innov) + list(market.returns.purged=market.returns.purged, innov=innov) } # A function that calls do.one.piece, and works through several # different periods to provide the right RHS matrix. -makeX <- function(rM1, others, +makeX <- function(market.returns, others, switch.to.innov=rep(TRUE, NCOL(others)), - rM1purge=TRUE, + market.returns.purge=TRUE, nlags=5, dates=NULL, verbose=FALSE) { if (verbose) {cat("0. Checking args\n")} - stopifnot(all.equal(index(rM1), index(others)), + stopifnot(all.equal(index(market.returns), index(others)), length(switch.to.innov)==NCOL(others)) if (!is.null(dates)) { stopifnot(class(dates) == "Date") } if (verbose) {cat("1. Checking dates.\n")} if (is.null(dates)) { - dates <- c(start(rM1),end(rM1)) + dates <- c(start(market.returns),end(market.returns)) } - if(head(dates,1)!=head(index(rM1),1)){ + if(head(dates,1)!=head(index(market.returns),1)){ stop("Start date provided and the start date of the dataset do not match \n") } - if(tail(dates,1)!=tail(index(rM1),1)){ + if(tail(dates,1)!=tail(index(market.returns),1)){ stop("End date provided and the end date of the dataset do not match \n") } if (verbose) {cat("2. Run through all the pieces --\n")} @@ -453,21 +453,21 @@ if (verbose) { cat(" Focusing down from date = ", as.character(t1), " to ", as.character(t2), "\n") } - tmp.rM1 <- window(rM1, start=t1, end=t2) + tmp.market.returns <- window(market.returns, start=t1, end=t2) tmp.others <- window(others, start=t1, end=t2) - a <- do.one.piece(tmp.rM1, tmp.others, switch.to.innov, rM1purge, nlags, verbose) + a <- do.one.piece(tmp.market.returns, tmp.others, switch.to.innov, market.returns.purge, nlags, verbose) if (i > 1) { - res.rM1 <- c(res.rM1, a$rM1.purged) + res.market.returns <- c(res.market.returns, a$market.returns.purged) res.innov <- rbind(res.innov, a$innov) } else { - res.rM1 <- a$rM1.purged + res.market.returns <- a$market.returns.purged res.innov <- a$innov } } if (verbose) {cat("2. Make a clean X and send it back --\n")} - X <- cbind(res.rM1, res.innov) - if (NCOL(res.innov) == 1) {colnames(X) <- c("rM1","z")} - else {colnames(X) <- c("rM1", colnames(res.innov))} + X <- cbind(res.market.returns, res.innov) + if (NCOL(res.innov) == 1) {colnames(X) <- c("market.returns","z")} + else {colnames(X) <- c("market.returns", colnames(res.innov))} X } Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/R/eventstudy.R 2013-08-08 11:42:16 UTC (rev 120) @@ -1,4 +1,4 @@ -eventstudy <- function(inputData = NULL, +eventstudy <- function(firm.returns = NULL, eventList, width = 10, is.levels = FALSE, @@ -13,30 +13,30 @@ main = "Event study plot", ...) { # type = "marketResidual", "excessReturn", "AMM", "None" - if (type == "None" && !is.null(inputData)) { - outputModel <- inputData + if (type == "None" && !is.null(firm.returns)) { + outputModel <- firm.returns } if (is.levels == TRUE) { - inputData <- diff(log(inputData)) * 100 + firm.returns <- diff(log(firm.returns)) * 100 } ### Run models ## AMM if (type == "AMM") { amm.type <- "residual" - tmp.outputModel <- AMM(rj = inputData, ...) + tmp.outputModel <- AMM(amm.type, ...) outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } ## marketResidual if (type == "marketResidual") { - outputModel <- marketResidual(data.object = inputData, ...) + outputModel <- marketResidual(firm.returns, ...) } ## excessReturn if (type == "excessReturn") { - outputModel <- excessReturn(data.object = inputData, ...) + outputModel <- excessReturn(firm.returns, ...) } ### Converting index outputModel to Date Modified: pkg/R/excessReturn.R =================================================================== --- pkg/R/excessReturn.R 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/R/excessReturn.R 2013-08-08 11:42:16 UTC (rev 120) @@ -7,12 +7,8 @@ # Output: # Value: Excess market return -excessReturn <- function(data.object, market.name=NULL){ - if(is.null(market.name)==TRUE){ - stop("Column name for market index not provided") - } - cn.names <- colnames(data.object) - cn.names <- cn.names[-which(cn.names%in%market.name)] - ma.ret <- data.object[,cn.names]-data.object[,market.name] +excessReturn <- function(firm.returns, market.returns){ + ## Getting market return + ma.ret <- firm.returns-market.returns return(ma.ret) } Modified: pkg/R/marketResidual.R =================================================================== --- pkg/R/marketResidual.R 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/R/marketResidual.R 2013-08-08 11:42:16 UTC (rev 120) @@ -2,55 +2,40 @@ # Market model adjustment ######################### ## Argument: -## 1. data.object: Single time series object with all the variables -## 2. market.name: Column name of market index in the data +## 1. firm.returns: Firm returns of which market residual is to computed +## 2. market.returns: Market Index returns ## Output: ## Value: Market residual after extracting market returns from the firm return -marketResidual <- function(data.object, market.name=NULL){ -### Checking arguments - if(is.null(market.name)==TRUE){ - stop("Column name of market index not provided") - } - cn.names <- colnames(data.object) - cn.names <- cn.names[-which(cn.names%in%market.name)] - ## Market residual - formula <- paste(cn.names[1],"~",market.name,sep=" ") - tmp <- marketResidual.onefirm(mm.formula = formula, - data.object = data.object, - firm.name = cn.names[1]) - ## tmp <- tmp[complete.cases(tmp),] - if(length(cn.names)>1){ - for(i in 2:length(cn.names)){ - ## Getting formula - formula <- paste(cn.names[i],"~",market.name,sep=" ") - ## Market residual - tmp.resid <- marketResidual.onefirm(mm.formula = formula, - data.object = data.object, - firm.name = cn.names[i]) - ## tmp.resid <- tmp.resid[complete.cases(tmp.resid),] - tmp <- merge(tmp,tmp.resid,all=TRUE) +marketResidual <- function(firm.returns, market.returns){ + ## Checking + if(NCOL(firm.returns)>1){ + result <- mm.residual(firm.returns[,1], market.returns) + for(i in 2:NCOL(firm.returns)){ + res <- mm.residual(firm.returns[,i], market.returns) + result <- cbind(result,res) } + colnames(result) <- colnames(firm.returns) + } else { + result <- mm.residual(firm.returns, market.returns) } - colnames(tmp) <- cn.names - return(tmp) + result <- zoo(result) + return(result) } -marketResidual.onefirm <- function(mm.formula=NULL,data.object,firm.name){ -### Market residual one firm +mm.residual <- function(firm.returns, market.returns){ ## Storing NA observations - na.date <- data.object[which(complete.cases(data.object[,firm.name])==FALSE), - firm.name] -### Checking arguments - if(is.null(mm.formula)==TRUE){ - print("Formula for market residual model not provided") - } - ## Extracting market residuals - reg <- lm(as.formula(mm.formula),data=data.object) - resid <- xts(reg$residuals,as.Date(attr(reg$residuals,"names"))) - suppressWarnings(tot.resid <- rbind(resid, - xts(rep(NA,NROW(na.date)), - index(na.date)))) + na.date <- firm.returns[which(complete.cases(firm.returns)==FALSE)] + firm <- firm.returns + market <- market.returns + mm.data <- merge(firm,market,all=TRUE) + colnames(mm.data) <- c("firm","market") + reg <- lm(firm ~ market, data = mm.data) + resid <- xts(reg$residuals,as.Date(attr(reg$residuals,"names"))) + suppressWarnings(tot.resid <- rbind(resid, + xts(rep(NA,NROW(na.date)), + index(na.date)))) + colnames(tot.resid) <- "firm.residual" return(tot.resid) -} +} Modified: pkg/data/StockPriceReturns.rda =================================================================== (Binary files differ) Modified: pkg/data/inr.rda =================================================================== (Binary files differ) Modified: pkg/man/excessReturn.Rd =================================================================== --- pkg/man/excessReturn.Rd 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/man/excessReturn.Rd 2013-08-08 11:42:16 UTC (rev 120) @@ -6,12 +6,11 @@ \description{ This function estimates excess return. If the the firm return is rj and market return is rM then output will be rj less rM. } -\usage{excessReturn(data.object, market.name=NULL) -} +\usage{excessReturn(firm.returns, market.returns) \arguments{ - \item{data.object}{This is a time series object with firm return and market return} - \item{market.name}{It is the market (index) column name in the data object} + \item{firm.returns}{Firm returns of which excess return from market is to be calculated} + \item{market.returns}{Market index returns} } \value{Excess market return} @@ -20,8 +19,9 @@ \examples{ data(StockPriceReturns) -er.result <- excessReturn(market.name="nifty", - data.object=StockPriceReturns) +data(nifty.index) +er.result <- excessReturn(firm.returns = StockPriceReturns, + market.returns = nifty.index) } Modified: pkg/man/firmExposures.Rd =================================================================== --- pkg/man/firmExposures.Rd 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/man/firmExposures.Rd 2013-08-08 11:42:16 UTC (rev 120) @@ -60,11 +60,11 @@ # firmExposures data("firmExposuresData") rj <- firmExposuresData$Company_A -rM1 <- firmExposuresData$NIFTY_INDEX +market.returns <- firmExposuresData$NIFTY_INDEX rM2 <- firmExposuresData$usdinr rM3 <- firmExposuresData$baa -X <- makeX(rM1, others=rM2, - switch.to.innov=FALSE, rM1purge=FALSE, verbose=FALSE) +X <- makeX(market.returns, others=rM2, + switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE) a <- firmExposures(rj, X, nlags=0, verbose=FALSE) print(a) } Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/man/makeX.Rd 2013-08-08 11:42:16 UTC (rev 120) @@ -11,11 +11,11 @@ } \usage{ -makeX(rM1, others, switch.to.innov = rep(TRUE, NCOL(others)), rM1purge = TRUE, nlags = 5, dates = NULL, verbose = FALSE) +makeX(market.returns, others, switch.to.innov = rep(TRUE, NCOL(others)), market.returns.purge = TRUE, nlags = 5, dates = NULL, verbose = FALSE) } \arguments{ - \item{rM1}{This is generally fixed to the stock market index. The + \item{market.returns}{This is generally fixed to the stock market index. The first column vector of this matrix contains this variable. } @@ -29,13 +29,13 @@ 'others' is switched from raw values to AR residuals. } - \item{rM1purge}{whether or not the effects of all these 'others' are - purged from 'rM1' (i.e., is it replaced by residuals of a model - explaining rM1 using all these 'others'). + \item{market.returns.purge}{whether or not the effects of all these 'others' are + purged from 'market.returns' (i.e., is it replaced by residuals of a model + explaining market.returns using all these 'others'). } \item{nlags}{The number of lag terms present in this model explaining - rM1 using all these 'others'. + market.returns using all these 'others'. } \item{dates}{Specified break dates (either from structural breaks in @@ -64,12 +64,12 @@ \examples{ # makeX data("firmExposuresData") -rj <- firmExposuresData$Company_A -rM1 <- firmExposuresData$NIFTY_INDEX +firm.returns <- firmExposuresData$Company_A +market.returns <- firmExposuresData$NIFTY_INDEX rM2 <- firmExposuresData$usdinr rM3 <- firmExposuresData$baa -X <- makeX(rM1, others=rM2, - switch.to.innov=FALSE, rM1purge=FALSE, verbose=FALSE) +X <- makeX(market.returns, others=rM2, + switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE) } \keyword{makeX} Modified: pkg/man/manyfirmsAMM.Rd =================================================================== --- pkg/man/manyfirmsAMM.Rd 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/man/manyfirmsAMM.Rd 2013-08-08 11:42:16 UTC (rev 120) @@ -49,8 +49,8 @@ Company_A <- y3c3$Company_A Company_B <- y3c3$Company_B Company_C <- y3c3$Company_C -regressors <- makeX(rM1=NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1, +regressors <- makeX(market.returns=NIFTY_INDEX, others=INRUSD, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), verbose=FALSE) regressand <- cbind(Company_A,Company_B,Company_C) Modified: pkg/man/marketResidual.Rd =================================================================== --- pkg/man/marketResidual.Rd 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/man/marketResidual.Rd 2013-08-08 11:42:16 UTC (rev 120) @@ -6,12 +6,12 @@ \description{ This function extracts market return using regression from the firm return to get the residual return } -\usage{marketResidual(data.object, market.name=NULL) +\usage{marketResidual(firm.returns, market.returns) } \arguments{ - \item{data.object}{Single time series object with firm/firms and stock index data} - \item{market.name}{Column name of the market index in the data} + \item{firm.returns}{Single time series object with all firm returns} + \item{market.returns}{Market index returns} } \value{ Market residual after extracting market returns from the firm return @@ -21,8 +21,9 @@ \examples{ data(StockPriceReturns) +data(nifty.index) # Extracting market residual -mm.result <- marketResidual(data.object=StockPriceReturns, market.name="nifty") +mm.result <- marketResidual(firm.returns=StockPriceReturns, market.name=nifty.index) } Modified: pkg/man/onefirmAMM.Rd =================================================================== --- pkg/man/onefirmAMM.Rd 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/man/onefirmAMM.Rd 2013-08-08 11:42:16 UTC (rev 120) @@ -3,18 +3,18 @@ \title{A function that estimates exposure for a single firm over multiple periods} -\description{This function typically utilises an rj vector +\description{This function typically utilises an firm.returns vector and an X matrix of explanatory variables obtained out of using the makeX function. This would compute the exposure for all columns in X for the specified time periods. } \usage{ -onefirmAMM(rj, X, nlags = 1, verbose = FALSE, dates = NULL, residual = TRUE) +onefirmAMM(firm.returns, X, nlags = 1, verbose = FALSE, dates = NULL, residual = TRUE) } \arguments{ - \item{rj}{A vector of data for one firm + \item{firm.returns}{A vector of data for one firm } \item{X}{A matrix of explanatory variables obtained from the makeX function. The first variable is always the @@ -49,12 +49,12 @@ INRUSD <- y3c3$INRUSD Company_A <- y3c3$Company_A rhs.dat <- makeX(NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), verbose=FALSE) # Run AMM for one firm across different periods -onefirmAMM(rj=Company_A, +onefirmAMM(firm.returns=Company_A, X=rhs.dat, nlags=1, verbose=TRUE, Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-08 05:31:57 UTC (rev 119) +++ pkg/vignettes/eventstudies.Rnw 2013-08-08 11:42:16 UTC (rev 120) @@ -190,16 +190,16 @@ result is stored in \texttt{er.result}. <<>>= -data(StockPriceReturns) # Excess return -er.result <- excessReturn(market.name="nifty", - data.object=StockPriceReturns) +er.result <- excessReturn(firm.returns = StockPriceReturns, + market.returns = nifty.index) head(er.result) @ <<>>= # Extracting market residual -mm.result <- marketResidual(data.object=StockPriceReturns, market.name="nifty") +mm.result <- marketResidual(firm.returns = StockPriceReturns, + market.returns = nifty.index) head(mm.result) @ @@ -207,25 +207,29 @@ %AMM model <<>>= # Create RHS before running AMM() -nifty.index <- StockPriceReturns$nifty -inrusd <- StockPriceReturns$inr +data(nifty.index) +data(inr) +inrusd <- diff(log(inr))*100 +all.data <- merge(StockPriceReturns,nifty.index,inrusd,all=TRUE) +StockPriceReturns <- all.data[,-which(colnames(all.data)%in%c("nifty.index", + "inr"))] +nifty.index <- all.data$nifty.index +inrusd <- all.data$inr ## AMM output ## For Full period: dates=NULL -amm.residual <- AMM(amm.type="residual",rj=StockPriceReturns[,1:3], +amm.residual <- AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], verbose=TRUE, dates= NULL, - rM1=nifty.index, others=inrusd, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + market.returns=nifty.index, others=inrusd, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) -amm.output <- AMM(amm.type="all",rj=StockPriceReturns[,1:3], +amm.output <- AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], verbose=TRUE, dates= NULL, - rM1=nifty.index, others=inrusd, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + market.returns=nifty.index, others=inrusd, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) - - @ @@ -340,40 +344,41 @@ <<>>= ## Event study without adjustment -es.na <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, +es.na <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "wilcoxon", type = "None") ## Event study using market residual and bootstrap -es.mm <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, +es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "bootstrap", - type = "marketResidual", market.name = "nifty") + type = "marketResidual", market.returns = nifty.index) ## Event study using excess return and bootstrap -es.er <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, +es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "bootstrap", - type = "excessReturn", market.name = "nifty") + type = "excessReturn", market.returns = nifty.index) ## Event study using augmented market model (AMM) and bootstrap cn.names <- which(colnames(StockPriceReturns)%in%c("nifty","inr")) stock.data <- StockPriceReturns[,-cn.names] -es.amm <- eventstudy(inputData = stock.data, +es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "bootstrap", type = "AMM", amm.type="residual", - rM1=StockPriceReturns$nifty, others=StockPriceReturns$inr, + market.returns=nifty.index, + others=inrusd, nlags=1, verbose=TRUE, dates= NULL, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) @ From noreply at r-forge.r-project.org Fri Aug 9 09:36:24 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 9 Aug 2013 09:36:24 +0200 (CEST) Subject: [Eventstudies-commits] r121 - in pkg: data man Message-ID: <20130809073624.E2FC51858F2@r-forge.r-project.org> Author: vikram Date: 2013-08-09 09:36:24 +0200 (Fri, 09 Aug 2013) New Revision: 121 Added: pkg/data/nifty.index.rda pkg/man/nifty.index.Rd Log: Added Nifty index in data folder along documentation Added: pkg/data/nifty.index.rda =================================================================== (Binary files differ) Property changes on: pkg/data/nifty.index.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/man/nifty.index.Rd =================================================================== --- pkg/man/nifty.index.Rd (rev 0) +++ pkg/man/nifty.index.Rd 2013-08-09 07:36:24 UTC (rev 121) @@ -0,0 +1,16 @@ +\name{nifty.index} +\alias{nifty.index} +\docType{data} +\title{ +NSE Nifty index from 2004 to 2012 +} +\description{ +A sample of Nifty index return from 1990 to 2012. It is stored as an tim series object object. +} +\usage{data(nifty.index)} +\format{ It is an time series object containing daily data from 2003 to 2012. The format is: chr 'nifty.index.rda' +} +\examples{ +data(nifty.index) +} +\keyword{datasets} From noreply at r-forge.r-project.org Fri Aug 9 13:13:42 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 9 Aug 2013 13:13:42 +0200 (CEST) Subject: [Eventstudies-commits] r122 - in pkg: R man vignettes Message-ID: <20130809111342.74CC3180922@r-forge.r-project.org> Author: chiraganand Date: 2013-08-09 13:13:42 +0200 (Fri, 09 Aug 2013) New Revision: 122 Modified: pkg/R/eventstudy.R pkg/man/eventstudy.Rd pkg/vignettes/eventstudies.Rnw Log: Fixed AMM function to handle firm.returns argument; fixed vignette example, and modified documentation. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-09 07:36:24 UTC (rev 121) +++ pkg/R/eventstudy.R 2013-08-09 11:13:42 UTC (rev 122) @@ -25,7 +25,7 @@ ## AMM if (type == "AMM") { amm.type <- "residual" - tmp.outputModel <- AMM(amm.type, ...) + tmp.outputModel <- AMM(amm.type, firm.returns = firm.returns, ...) outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } @@ -84,5 +84,5 @@ result <- es.w } - return(result) + return(list(result, es$outcomes)) } Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2013-08-09 07:36:24 UTC (rev 121) +++ pkg/man/eventstudy.Rd 2013-08-09 11:13:42 UTC (rev 122) @@ -38,6 +38,10 @@ \item{main}{If to.plot is TRUE then the plot generated will take this as main title} \item{...}{Accepts specific arguments for the model.} } + +\details{If type = "AMM", then the default output is "residual". + } + \value{ Output is mean estimate of abnormal returns and confidence interval using particular inference strategy } @@ -65,4 +69,4 @@ } -\keyword{eventstudy} \ No newline at end of file +\keyword{eventstudy} Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-09 07:36:24 UTC (rev 121) +++ pkg/vignettes/eventstudies.Rnw 2013-08-09 11:13:42 UTC (rev 122) @@ -373,10 +373,10 @@ width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "bootstrap", - type = "AMM", amm.type="residual", + type = "AMM", market.returns=nifty.index, others=inrusd, - nlags=1, verbose=TRUE, + verbose=TRUE, dates= NULL, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) From noreply at r-forge.r-project.org Fri Aug 9 14:35:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 9 Aug 2013 14:35:27 +0200 (CEST) Subject: [Eventstudies-commits] r123 - pkg/inst/tests Message-ID: <20130809123527.62E2C184678@r-forge.r-project.org> Author: chiraganand Date: 2013-08-09 14:35:27 +0200 (Fri, 09 Aug 2013) New Revision: 123 Modified: pkg/inst/tests/test_marketresiduals.R Log: Modified market residuals test case because of new API Modified: pkg/inst/tests/test_marketresiduals.R =================================================================== --- pkg/inst/tests/test_marketresiduals.R 2013-08-09 11:13:42 UTC (rev 122) +++ pkg/inst/tests/test_marketresiduals.R 2013-08-09 12:35:27 UTC (rev 123) @@ -4,10 +4,12 @@ library(eventstudies) load(system.file("data", "StockPriceReturns.rda", package = "eventstudies")) +load(system.file("data", "nifty.index.rda", package = "eventstudies")) -mm.result <- marketResidual(data.object=StockPriceReturns[,c("BHEL","nifty")], - market.name="nifty") -mm.result <- mm.result[complete.cases(mm.result),] +mm.result <- marketResidual(firm.returns=StockPriceReturns[,c("BHEL")], + market.returns=nifty.index) +mm.result <- xts(mm.result[complete.cases(mm.result),]) +colnames(mm.result) <- "BHEL" # Calculating manually result <- lm(BHEL ~ nifty, data=StockPriceReturns) From noreply at r-forge.r-project.org Fri Aug 9 14:54:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 9 Aug 2013 14:54:27 +0200 (CEST) Subject: [Eventstudies-commits] r124 - in pkg: inst/tests man Message-ID: <20130809125427.CB9AA184678@r-forge.r-project.org> Author: chiraganand Date: 2013-08-09 14:54:27 +0200 (Fri, 09 Aug 2013) New Revision: 124 Modified: pkg/inst/tests/test_AMM.R pkg/inst/tests/test_marketresiduals.R pkg/man/AMM.Rd pkg/man/marketResidual.Rd Log: Fixed test cases and examples according to the new variables for market returns and firm returns. Modified: pkg/inst/tests/test_AMM.R =================================================================== --- pkg/inst/tests/test_AMM.R 2013-08-09 12:35:27 UTC (rev 123) +++ pkg/inst/tests/test_AMM.R 2013-08-09 12:54:27 UTC (rev 124) @@ -3,64 +3,65 @@ test_that("test.AMM", { load(system.file("data", "firmExposuresData.rda", package = "eventstudies")) - rj <- firmExposuresData$Company_A - rM1 <- firmExposuresData$NIFTY_INDEX - rM2 <- firmExposuresData$usdinr + firm.returns <- firmExposuresData$Company_A + market.returns <- firmExposuresData$NIFTY_INDEX + inrusd <- firmExposuresData$usdinr rM3 <- firmExposuresData$baa cat("\nDoing Testcase P2") - X <- makeX(rM1, others=rM2, - switch.to.innov=FALSE, rM1purge=FALSE, verbose=FALSE) - a <- firmExposures(rj, X, nlags=0, verbose=FALSE) + X <- makeX(market.returns, others=inrusd, + switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE) + a <- firmExposures(firm.returns, X, nlags=0, verbose=FALSE) expect_that(c(a$exposures, a$s.exposures), equals(structure(c(0.716160223601197,-0.673093436292401, 0.152101606133946,1.02143820457251), - .Names = c("rM1", "z", "rM1", "z")), tolerance=1e-1)) + .Names = c("market.returns", "z", "market.returns", "z")), tolerance=1e-1)) cat("\nDoing Testcase P3") - X <- makeX(rM1, others=rM2, - switch.to.innov=TRUE, rM1purge=FALSE, verbose=FALSE) - a <- firmExposures(rj, X, nlags=0, verbose=FALSE) + X <- makeX(market.returns, others=inrusd, + switch.to.innov=TRUE, market.returns.purge=FALSE, verbose=FALSE) + a <- firmExposures(firm.returns, X, nlags=0, verbose=FALSE) expect_that(c(a$exposures, a$s.exposures), equals(structure(c(0.716160223601197,-0.673093436292401, 0.152100337597009,1.02146106755333), - .Names = c("rM1", "z", "rM1", "z")), tolerance=1e-1)) + .Names = c("market.returns", "z", "market.returns", "z")), tolerance=1e-1)) cat("\nDoing Testcase P4") - a <- firmExposures(rj, X, nlags=1, verbose=FALSE) + a <- firmExposures(firm.returns, X, nlags=1, verbose=FALSE) expect_that(c(a$exposures, a$s.exposures), equals(structure(c( 0.736264286484902, -1.450805, 0.177929844631439, 1.646730), - .Names = c("rM1","z", "rM1", "z")),tolerance=1e-1)) + .Names = c("market.returns","z", "market.returns", "z")),tolerance=1e-1)) cat("\nDoing Testcase P5") - X <- makeX(rM1, others=rM2, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1, verbose=FALSE) - a <- firmExposures(rj, X, nlags=1, verbose=FALSE) + X <- makeX(market.returns, others=inrusd, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, verbose=FALSE) + a <- firmExposures(firm.returns, X, nlags=1, verbose=FALSE) expect_that(c(a$exposures, a$s.exposures), equals(structure(c(0.7365566,-2.340171, 0.1653025, 1.1436666), - .Names = c("rM1", "z", "rM1", "z")),tolerance=1e-1)) + .Names = c("market.returns", "z", "market.returns", "z")),tolerance=1e-1)) cat("\nDoing Testcase P6") - X <- makeX(rM1, others=cbind(rM2, rM3), - switch.to.innov=c(FALSE, FALSE), rM1purge=FALSE, verbose=FALSE) - a <- firmExposures(rj, X, nlags=0, verbose=FALSE) + X <- makeX(market.returns, others=cbind(inrusd, rM3), + switch.to.innov=c(FALSE, FALSE), market.returns.purge=FALSE, verbose=FALSE) + a <- firmExposures(firm.returns, X, nlags=0, verbose=FALSE) expect_that(c(a$exposures, a$s.exposures), equals(structure(c(0.7230599,-0.7642377, 0.207374104922771,0.173380799334299, 1.01806122963342,0.467821650129292), - .Names = c("rM1", "rM2", "rM3", "rM1", "rM2", "rM3")),tolerance=1e-1)) + .Names = c("market.returns", "inrusd", "rM3", "market.returns", "inrusd", "rM3")),tolerance=1e-1)) cat("\nDoing Testcase P7") - X <- makeX(rM1, others=cbind(rM2, rM3), - switch.to.innov=c(TRUE, TRUE), rM1purge=TRUE, nlags=1, verbose=FALSE) - a <- firmExposures(rj, X, nlags=1, verbose=FALSE) + X <- makeX(market.returns, others=cbind(inrusd, rM3), + switch.to.innov=c(TRUE, TRUE), market.returns.purge=TRUE, nlags=1, verbose=FALSE) + a <- firmExposures(firm.returns, X, nlags=1, verbose=FALSE) + expect_that(c(a$exposures, a$s.exposures), equals(structure(c(0.7482719,-1.9468851,-0.4802211, 0.1740678,1.2455112,0.6146619), - .Names = c("rM1", "rM2", "rM3", "rM1", "rM2", "rM3")),tolerance=1e-1)) + .Names = c("market.returns", "inrusd", "rM3", "market.returns", "inrusd", "rM3")),tolerance=1e-1)) ################################################################################ # # @@ -79,7 +80,7 @@ Company_C <- y3c3$Company_C regressors <- makeX(NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), verbose=FALSE) @@ -92,34 +93,34 @@ expect_that(as.data.frame(res), - equals(structure(list(rM1.P1 = c(0.756294904326272, 0.359467326140834,0.914021428042946), + equals(structure(list(market.returns.P1 = c(0.756294904326272, 0.359467326140834,0.914021428042946), z.P1 = c(-2.23264294525560, -1.05654919420689,0.296635483126946), - rM1.P2 = c(1.02094561445355, 0.988758963378838,0.879236409569888), + market.returns.P2 = c(1.02094561445355, 0.988758963378838,0.879236409569888), z.P2 = c(-4.72831391695047, -2.0508684999854,-1.02215809586573), - rM1.P3 = c(1.20585808099744, 0.676388278572118,0.530718379431386), + market.returns.P3 = c(1.20585808099744, 0.676388278572118,0.530718379431386), z.P3 = c(-1.32677083522489, -2.74055730512260, -1.50032216697694), - rM1.P4 = c(1.11331096371784, 0.437117737120777,0.663182186702262), + market.returns.P4 = c(1.11331096371784, 0.437117737120777,0.663182186702262), z.P4 = c(-2.05336868436562, -1.60350865767951,-0.466253391408585), - rM1.P1 = c(0.143617135793294, 0.263130891045529,0.154272220123111), + market.returns.P1 = c(0.143617135793294, 0.263130891045529,0.154272220123111), z.P1 = c(1.20226371286803, 1.22122136357895,1.02442932195400), - rM1.P2 = c(0.203037609116444, 0.123122376136099,0.121880488983820), + market.returns.P2 = c(0.203037609116444, 0.123122376136099,0.121880488983820), z.P2 = c(1.118400430819, 0.798694545623495,1.29755067543957), - rM1.P3 = c(0.230304109532112, 0.289262660515515,0.164866239494693), + market.returns.P3 = c(0.230304109532112, 0.289262660515515,0.164866239494693), z.P3 = c(1.17618117392934, 0.795008683829453,0.650736332270758), - rM1.P4 = c(0.231338818884745, 0.213858364836974,0.207154237634752), + market.returns.P4 = c(0.231338818884745, 0.213858364836974,0.207154237634752), z.P4 = c(0.771450066857429, 0.415931231130697,0.696448914066602), - rM1.P1 = c(5.26604920888266, 1.36611602200152,5.9247311493511), + market.returns.P1 = c(5.26604920888266, 1.36611602200152,5.9247311493511), z.P1 = c(-1.85703263049467, -0.865157804896683,0.289561687438957), - rM1.P2 = c(5.02835715460001, 8.0307007906172,7.21392256382075), + market.returns.P2 = c(5.02835715460001, 8.0307007906172,7.21392256382075), z.P2 = c(-4.2277468665565, -2.56777576762391,-0.787759673062059), - rM1.P3 = c(5.23593818385294, 2.33831866638673,3.21908464133114), + market.returns.P3 = c(5.23593818385294, 2.33831866638673,3.21908464133114), z.P3 = c(-1.12803270842405, -3.44720423923131,-2.30557614900882), - rM1.P4 = c(4.81246929972659, 2.04395903547657,3.20139329165723), + market.returns.P4 = c(4.81246929972659, 2.04395903547657,3.20139329165723), z.P4 = c(-2.66170005367969, -3.85522542589652,-0.669472493949494)), - .Names = c("rM1.P1", "z.P1", "rM1.P2","z.P2", "rM1.P3", "z.P3", - "rM1.P4", "z.P4", "rM1.P1", "z.P1","rM1.P2", "z.P2", "rM1.P3", "z.P3", - "rM1.P4", "z.P4", "rM1.P1", "z.P1", "rM1.P2", "z.P2", "rM1.P3", - "z.P3", "rM1.P4", "z.P4"), + .Names = c("market.returns.P1", "z.P1", "market.returns.P2","z.P2", "market.returns.P3", "z.P3", + "market.returns.P4", "z.P4", "market.returns.P1", "z.P1","market.returns.P2", "z.P2", "market.returns.P3", "z.P3", + "market.returns.P4", "z.P4", "market.returns.P1", "z.P1", "market.returns.P2", "z.P2", "market.returns.P3", + "z.P3", "market.returns.P4", "z.P4"), row.names = c("Company_A","Company_B", "Company_C"), class = "data.frame"), check.attributes=FALSE)) }) Modified: pkg/inst/tests/test_marketresiduals.R =================================================================== --- pkg/inst/tests/test_marketresiduals.R 2013-08-09 12:35:27 UTC (rev 123) +++ pkg/inst/tests/test_marketresiduals.R 2013-08-09 12:54:27 UTC (rev 124) @@ -6,13 +6,17 @@ load(system.file("data", "StockPriceReturns.rda", package = "eventstudies")) load(system.file("data", "nifty.index.rda", package = "eventstudies")) +alldata <- merge(StockPriceReturns, nifty.index, all = TRUE) +StockPriceReturns <- alldata[,-which(colnames(alldata) %in% "nifty.index")] +nifty.index <- alldata$nifty.index + mm.result <- marketResidual(firm.returns=StockPriceReturns[,c("BHEL")], market.returns=nifty.index) mm.result <- xts(mm.result[complete.cases(mm.result),]) colnames(mm.result) <- "BHEL" # Calculating manually -result <- lm(BHEL ~ nifty, data=StockPriceReturns) +result <- lm(BHEL ~ nifty.index, data=StockPriceReturns) resid.res <- xts(result$resid,as.Date(attr(result$resid,"names"))) colnames(resid.res) <- "BHEL" Modified: pkg/man/AMM.Rd =================================================================== --- pkg/man/AMM.Rd 2013-08-09 12:35:27 UTC (rev 123) +++ pkg/man/AMM.Rd 2013-08-09 12:54:27 UTC (rev 124) @@ -45,12 +45,12 @@ regressand <- cbind(Company_A,Company_B,Company_C) ## One firm -of <- AMM(amm.type="residual",rj=Company_A, +of <- AMM(amm.type="residual",firm.returns=Company_A, verbose=TRUE, dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", "2008-01-05","2009-01-03")), - rM1=NIFTY_INDEX, others=INRUSD, - switch.to.innov=TRUE, rM1purge=TRUE, nlags=1) + market.returns=NIFTY_INDEX, others=INRUSD, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) } -\keyword{AMM} \ No newline at end of file +\keyword{AMM} Modified: pkg/man/marketResidual.Rd =================================================================== --- pkg/man/marketResidual.Rd 2013-08-09 12:35:27 UTC (rev 123) +++ pkg/man/marketResidual.Rd 2013-08-09 12:54:27 UTC (rev 124) @@ -23,8 +23,8 @@ data(StockPriceReturns) data(nifty.index) # Extracting market residual -mm.result <- marketResidual(firm.returns=StockPriceReturns, market.name=nifty.index) +mm.result <- marketResidual(firm.returns=StockPriceReturns, market.returns=nifty.index) } -\keyword{marketResidual} \ No newline at end of file +\keyword{marketResidual} From noreply at r-forge.r-project.org Fri Aug 9 20:13:17 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 9 Aug 2013 20:13:17 +0200 (CEST) Subject: [Eventstudies-commits] r125 - in pkg: inst/tests man vignettes Message-ID: <20130809181317.1F947184678@r-forge.r-project.org> Author: vikram Date: 2013-08-09 20:13:16 +0200 (Fri, 09 Aug 2013) New Revision: 125 Modified: pkg/inst/tests/test_inr_inference.R pkg/man/eventstudy.Rd pkg/man/excessReturn.Rd pkg/man/firmExposures.Rd pkg/vignettes/eventstudies.Rnw Log: Modified test inr test case for new inr data; corrected documentation for new changes in the function Modified: pkg/inst/tests/test_inr_inference.R =================================================================== --- pkg/inst/tests/test_inr_inference.R 2013-08-09 12:54:27 UTC (rev 124) +++ pkg/inst/tests/test_inr_inference.R 2013-08-09 18:13:16 UTC (rev 125) @@ -19,13 +19,27 @@ event_time_data <- phys2eventtime(inr_returns,eventslist,width=10) w <- window(event_time_data$z.e,start=-10,end=10) -expect_that(inference.bootstrap(w)[,2], - equals(c(-0.00215361156303362, -0.00040191670837042, 0.00171845148444985, - 0.00143799970419951, 0.00149260146357282, -0.00284892904228684, - 0.0013220811191847, -0.000634983205805195, 0.00115930378269389, - -0.000508755768685365, -0.00190621828611177, 0.000128303517790052, - -0.000547070723466092, 0.000463708708964017, -0.00108666428087325, - -0.00121321855159642, 0.00216769754166339, -0.000166340225607797, - 0.00117626759805196, 0.000207307545758795, 0.000602629204764948 - ))) +expect_that(inference.bootstrap(w, to.plot=FALSE)[,2], + equals(c(-0.000015327455, + -0.002526819039, + 0.001190000495, + 0.001193534934, + 0.001846733711, + -0.000105473215, + -0.001659771669, + 0.001644517771, + -0.001325235918, + 0.001546368579, + -0.000809734240, + -0.001499191073, + -0.000289413740, + -0.000003273428, + -0.000416661873, + -0.001150000190, + -0.000759748390, + 0.002306711019, + -0.0004872993296, + 0.001122457470, + 0.000635889955))) }) + Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2013-08-09 12:54:27 UTC (rev 124) +++ pkg/man/eventstudy.Rd 2013-08-09 18:13:16 UTC (rev 125) @@ -7,7 +7,7 @@ } \usage{ -eventstudy(inputData = NULL, +eventstudy(firm.returns = NULL, eventList, width = 10, is.levels = FALSE, @@ -23,7 +23,7 @@ } \arguments{ - \item{inputData}{Data on which event study is to be performed} + \item{firm.returns}{Data on which event study is to be performed} \item{eventList}{A data frame with event dates. It has two columns 'unit' and 'when'. The first column 'unit' consists of column names of the event stock and 'when' is the respective event date} \item{width}{It studies the performance of observations before and after the event} \item{type}{This argument gives an option to use different market model adjustment like "marketResidual", "excessReturn", "AMM" and "None"} @@ -65,7 +65,7 @@ ## data("SplitDates") ## Event study without adjustment -## es <- eventstudy(inputData = StockPriceReturns, eventList = SplitDates, width = 10,type = "None", to.remap = TRUE, remap = "cumsum", to.plot = FALSE,inference = TRUE, inference.strategy = "bootstrap") +## es <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10,type = "None", to.remap = TRUE, remap = "cumsum", to.plot = FALSE,inference = TRUE, inference.strategy = "bootstrap") } Modified: pkg/man/excessReturn.Rd =================================================================== --- pkg/man/excessReturn.Rd 2013-08-09 12:54:27 UTC (rev 124) +++ pkg/man/excessReturn.Rd 2013-08-09 18:13:16 UTC (rev 125) @@ -3,10 +3,10 @@ \title{A function that estimates excess return} -\description{ This function estimates excess return. If the the firm return is rj and market return is rM then output will be rj less rM. +\description{ This function estimates excess return. If the the firm return is rj and market return is market.returns then output will be firm.returns less market.returns. } -\usage{excessReturn(firm.returns, market.returns) +\usage{excessReturn(firm.returns, market.returns)} \arguments{ \item{firm.returns}{Firm returns of which excess return from market is to be calculated} Modified: pkg/man/firmExposures.Rd =================================================================== --- pkg/man/firmExposures.Rd 2013-08-09 12:54:27 UTC (rev 124) +++ pkg/man/firmExposures.Rd 2013-08-09 18:13:16 UTC (rev 125) @@ -4,18 +4,18 @@ \title{A function that estimates exposure for a single firm in a single period} -\description{This function typically utilises an rj vector +\description{This function typically utilises an firm.returns vector and an X matrix of explanatory variables obtained using the makeX function. This would compute the exposure for all columns in X. } \usage{ -firmExposures(rj, X, nlags = NA, verbose = FALSE) +firmExposures(firm.returns, X, nlags = NA, verbose = FALSE) } \arguments{ - \item{rj}{A vector of data for one firm} + \item{firm.returns}{A vector of data for one firm} \item{X}{A matrix of explanatory variables obtained from the makeX function. The first variable is always the @@ -42,7 +42,7 @@ j} \item{s.exposures}{This contains the HAC adjusted standard error -of the exposures estimated for the firm rj.} +of the exposures estimated for the firm firm.returns.} \item{nlags}{Specifies the lag length provided by the user} @@ -59,13 +59,13 @@ \examples{ # firmExposures data("firmExposuresData") -rj <- firmExposuresData$Company_A +firm.returns <- firmExposuresData$Company_A market.returns <- firmExposuresData$NIFTY_INDEX rM2 <- firmExposuresData$usdinr rM3 <- firmExposuresData$baa X <- makeX(market.returns, others=rM2, switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE) -a <- firmExposures(rj, X, nlags=0, verbose=FALSE) +a <- firmExposures(firm.returns, X, nlags=0, verbose=FALSE) print(a) } Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-09 12:54:27 UTC (rev 124) +++ pkg/vignettes/eventstudies.Rnw 2013-08-09 18:13:16 UTC (rev 125) @@ -158,7 +158,7 @@ \item \texttt{inference.wilcox}: estimation of wilcox inference to generate the distribution of cumulative returns series. \end{itemize} -\end{enumerate} +%\end{enumerate} \section{Example: Performing Eventstudy analysis} @@ -178,6 +178,7 @@ <<>>= library(eventstudies) data(StockPriceReturns) +data(nifty.index) str(StockPriceReturns) head(StockPriceReturns) @ @@ -193,14 +194,14 @@ # Excess return er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = nifty.index) -head(er.result) +head(er.result[,1:3]) @ <<>>= # Extracting market residual mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = nifty.index) -head(mm.result) +head(mm.result[,1:3]) @ @@ -365,9 +366,6 @@ type = "excessReturn", market.returns = nifty.index) ## Event study using augmented market model (AMM) and bootstrap -cn.names <- which(colnames(StockPriceReturns)%in%c("nifty","inr")) -stock.data <- StockPriceReturns[,-cn.names] - es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", From noreply at r-forge.r-project.org Mon Aug 12 11:45:00 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 12 Aug 2013 11:45:00 +0200 (CEST) Subject: [Eventstudies-commits] r126 - pkg/vignettes Message-ID: <20130812094500.5683018106D@r-forge.r-project.org> Author: renukasane Date: 2013-08-12 11:45:00 +0200 (Mon, 12 Aug 2013) New Revision: 126 Modified: pkg/vignettes/eventstudies.Rnw Log: Vignette - work in progress. Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-09 18:13:16 UTC (rev 125) +++ pkg/vignettes/eventstudies.Rnw 2013-08-12 09:45:00 UTC (rev 126) @@ -112,12 +112,15 @@ The package offers the following functionalities: \begin{itemize} \item Models for calculating returns - \item Coverting data to event-frame and remapping event-frame + \item Procedures for coverting data to event-time and remapping + event-frame \item Procedures for inference \end{itemize} \subsection*{Models for calculating returns} - +The package offers three models for calculating returns. These include +the excess return model, the standard market model, and the augmented +market model. The models are accessed using the following functions: \begin{itemize} \item \texttt{excessReturn}: estimation of excess return i.e. $R_j - R_m$ where $R_j$ is the return of firm $j$ and $R_m$ is the market @@ -125,42 +128,44 @@ \item \texttt{marketResidual}: estimation of market residual after extracting market returns from firm returns. - The first argument of the two functions is the \texttt{data.oject} - which is a time-series of stock returns. The second argument is - \texttt{market.name}, a column name indicating market returns. - \item \texttt{AMM}: estimation of the Augmented market model which gives the market residual after extracting market returns and currency returns from firm returns. The function allows for specifying the type of the AMM model as well. \end{itemize} + The two common arguments for these functions are + \texttt{firm.returns} which is a time-series of stock returns, and + \texttt{market.returns}, which is a time-series of market + returns. The type of AMM model is specified with the option + \texttt{amm.type}. + The output from these models is another time-series object which is used for converting to event time. - \subsection*{Coverting the data-set to an event frame} - These include: - \begin{itemize} - \item \texttt{phys2eventtime}: conversion to an event frame. This - requires a time series object of stock price returns and an - object with two columns \textit{unit} and \textit{when}, the date - of occurrence of the event. - - \item \texttt{remap.cumsum}: conversion of returns to cumulative - returns - \end{itemize} +\subsection*{Coverting the data-set to an event time} +The conversion of the returns data to event-time, and to cumulative +returns is done using the following functions: +\begin{itemize} + \item \texttt{phys2eventtime}: conversion to an event frame. This + requires a time series object of stock price returns and an + object with two columns \textit{unit} and \textit{when}, the date + of occurrence of the event. - \subsection*{Procedures for inference} - These include: - \begin{itemize} - \item \texttt{inference.bootstrap}: estimation of bootstrap to - generate the distribution of cumulative returns series. - \item \texttt{inference.wilcox}: estimation of wilcox inference to - generate the distribution of cumulative returns series. - \end{itemize} -%\end{enumerate} + \item \texttt{remap.cumsum}: conversion of returns to cumulative + returns. The input for this function is the time-series data in + event-time that results from using \texttt{phys2eventtime}. +\end{itemize} - +\subsection*{Procedures for inference} +Two procedures for inference are provided. These include: +\begin{itemize} + \item \texttt{inference.bootstrap}: estimation of bootstrap to + generate the distribution of cumulative returns series. + \item \texttt{inference.wilcox}: estimation of wilcox inference to + generate the distribution of cumulative returns series. +\end{itemize} + \section{Example: Performing Eventstudy analysis} \label{s:example} @@ -170,10 +175,9 @@ Exchange (BSE), from 2001 to 2013. We have stock split dates for each firm from 2000 onwards. -We first create a \textit{zoo} object for stock price returns for the -thirty firms. This is called \textit{StockPriceReturns}. The column -\texttt{nifty} is the market return and \texttt{inr} the INR-USD -exchange rate. +Our data consists of a \textit{zoo} object for stock price returns for +the thirty firms. This is called \textit{StockPriceReturns} and +another zoo object, \textit{nifty.index}, of the market returns. <<>>= library(eventstudies) @@ -181,14 +185,15 @@ data(nifty.index) str(StockPriceReturns) head(StockPriceReturns) +head(nifty.index) @ \subsection{Calculating returns} The function \texttt{excessReturn} calculates the excess returns while -\texttt{marketResidual} calculates the market model. It requires the -user to specify the \texttt{market.name} and \texttt{data.object}. The -result is stored in \texttt{er.result}. +\texttt{marketResidual} calculates the market model. The two inputs +are \texttt{firm.returns} and \texttt{market.returns}. The results are +stored in \texttt{er.result} and \texttt{mm.result} respectively. <<>>= # Excess return @@ -205,6 +210,17 @@ @ +The \texttt{AMM} model requires a time-series of the exchange rate +along with firm returns and market returns. This is done by loading +the \textit{inr} data, which is the INR-USD exchange rate for the same +period. The complete data-set consisting of stock returns, market +returns, and exchange rate is first created. + +The inputs into the \texttt{AMM} model also include +\texttt{firm.returns} and \texttt{market.returns}. Currency returns +can be specified using \texttt{others}. Two types of the AMM model are +supported: \textit{residual} and \textit{all}. + %AMM model <<>>= # Create RHS before running AMM() @@ -233,26 +249,39 @@ @ - \subsection{Conversion to event frame} -Before the data is converted to event frame, we need to know the dates -of interest. This is done with a data frame with two columns -\textit{unit} and \textit{when}. \textit{unit} has name of -the response series (firm name as in column name of time series -object) along with event date in \textit{when}. \textit{unit} should -be in \textit{character} format and \textit{when} in \textit{Date} -format. +Before the returns data is converted to event-time, we need to know +the dates of interest. These are stored in a data frame, +\texttt{SplitDates} with two columns \textit{unit} and +\textit{when}. \textit{unit} has the name of the response series (firm +name for example) along with event date in +\textit{when}. \textit{unit} should be in \textit{character} format +and \textit{when} in \textit{Date} format. <<>>= data(SplitDates) head(SplitDates) @ +For conversion to event time, the event date and the returns on that +date are indexed to 0. Post-event dates are indexed as positive, and +pre-event dates as negative. This is done using the +\texttt{phys2eventtime} function. The function requires a returns +series, \textit{StockPriceReturns}, a data-frame with event unit +and time, \textit{SplitDates}, and the \texttt{width} for creating the +event-frame. -The event date and the returns on that date are indexed to -0. Post-event dates are indexed to positive, and pre-event dates as -negative. This is done using the \texttt{phys2eventtime} function. +<<>>= +es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10) +str(es) +es$outcomes +es.w <- window(es$z.e, start=-10, end=10) +colnames(es.w) <- SplitDates[which(es$outcomes=="success"),1] +SplitDates[1,] +StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] +es.w[,1] +@ The output for \texttt{phys2eventtime} is a list. The first element of a list is a time series object which is converted to event @@ -265,24 +294,13 @@ the span of data for the unit or \textit{unitmissing} if a unit named in events is not in \textit{z}. -<<>>= -es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10) -str(es) -es$outcomes -es.w <- window(es$z.e, start=-10, end=10) -colnames(es.w) <- SplitDates[which(es$outcomes=="success"),1] -SplitDates[1,] -StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] -es.w[,1] -@ +In the example described here, es.w contains the returns in event-time +form for all the stocks. It contains variables for whom all data is +available. -In this example, es.w contains the returns in event-time form for all -the stocks. In this you only get variables for whom all data is -available. +Once the returns are converted to event-time, \texttt{remap.cumsum} +function is used to convert the returns to cumulative returns. -In event study analysis the variable of interest is cumulative -returns. The \texttt{remap.cumsum} function is used to convert the -returns to cumulative returns. <<>>= es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) es.cs[,1] @@ -290,18 +308,19 @@ \subsection{Inference procedures} \subsubsection{Bootstrap inference} -After converting to event frame and estimating the interest variable, + +After converting to event frame and estimating the interest variable, we need to check the stability of the result and derive other estimates like standard errors and confidence intervals. For this, we generate the sampling distribution for the estimate using bootstrap inference. A detailed explanation of the methodology is presented in -Patnaik, Shah and Singh (2013). -This specific approach used here is based on -\citet{davison1986efficient}. The \textit{inference.bootstrap} function -does the bootstrap to generate distribution of $\bar{CR}$. The -bootstrap generates confidence interval at 2.5\% and 97.5\% for the -estimate. +Patnaik, Shah and Singh (2013). This specific approach used here is based on +\citet{davison1986efficient}. +The \textit{inference.bootstrap} function does the bootstrap to +generate distribution of $\bar{CR}$. The bootstrap generates +confidence interval at 2.5\% and 97.5\% for the estimate. + <<>>= result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) @ @@ -318,8 +337,9 @@ \label{fig:one} \end{figure} -\subsubsection{Wilcoxon signed rank tests} -It is a non-parametric inference test to compute confidence interval. +\subsubsection{Wilcoxon signed rank test} +We next compute the Wilcoxon signed rank test, which is a +non-parametric inference test to compute confidence interval. <<>>= result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) @ @@ -337,12 +357,11 @@ \end{figure} \subsection{General eventstudy function} -This function is wrapper around all the internal functions. This -function gives an option to compute returns like excess return, market -residual and augmented market model. It also gives you an option to -choose inference procedure from bootstrap and wilcoxon to generate -confidence interval. +\texttt{eventstudy} is a wrapper around all the internal +functions. Several examples of the use of this function are provided +below. + <<>>= ## Event study without adjustment es.na <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, From noreply at r-forge.r-project.org Mon Aug 12 13:44:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 12 Aug 2013 13:44:36 +0200 (CEST) Subject: [Eventstudies-commits] r127 - in pkg: R vignettes Message-ID: <20130812114436.53A0F184F80@r-forge.r-project.org> Author: vikram Date: 2013-08-12 13:44:36 +0200 (Mon, 12 Aug 2013) New Revision: 127 Modified: pkg/R/AMM.R pkg/vignettes/eventstudies.Rnw Log: Corrected the excess return, AMM output; modified AMM function to change dates from POSIXct to Date format Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-12 09:45:00 UTC (rev 126) +++ pkg/R/AMM.R 2013-08-12 11:44:36 UTC (rev 127) @@ -87,13 +87,15 @@ X <- makeX(market.returns, others, switch.to.innov, market.returns.purge, nlags, dates, verbose) - result <- xts() - for(i in 1:NCOL(firm.returns)){ + tmp.result <- onefirmAMM(firm.returns[,1], X, nlags, verbose, dates) + result <- tmp.result$residuals + for(i in 2:NCOL(firm.returns)){ tmp <- onefirmAMM(firm.returns[,i], X, nlags, verbose, dates) result <- merge(result,tmp$residuals) } colnames(result) <- colnames(firm.returns) } + index(result) <- as.Date(index(result)) } ##---- Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-12 09:45:00 UTC (rev 126) +++ pkg/vignettes/eventstudies.Rnw 2013-08-12 11:44:36 UTC (rev 127) @@ -184,8 +184,8 @@ data(StockPriceReturns) data(nifty.index) str(StockPriceReturns) -head(StockPriceReturns) -head(nifty.index) +#head(StockPriceReturns) +#head(nifty.index) @ \subsection{Calculating returns} @@ -199,6 +199,7 @@ # Excess return er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = nifty.index) +er.result <- er.result[rowSums(is.na(er.result))!=NCOL(er.result),] head(er.result[,1:3]) @ @@ -206,6 +207,7 @@ # Extracting market residual mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = nifty.index) +mm.result <- mm.result[rowSums(is.na(mm.result))!=NCOL(mm.result),] head(mm.result[,1:3]) @ @@ -236,13 +238,13 @@ ## AMM output ## For Full period: dates=NULL amm.residual <- AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], - verbose=TRUE, + verbose=FALSE, dates= NULL, market.returns=nifty.index, others=inrusd, - switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=0) amm.output <- AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], - verbose=TRUE, + verbose=FALSE, dates= NULL, market.returns=nifty.index, others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) @@ -393,7 +395,7 @@ type = "AMM", market.returns=nifty.index, others=inrusd, - verbose=TRUE, + verbose=FALSE, dates= NULL, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) From noreply at r-forge.r-project.org Mon Aug 12 14:15:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 12 Aug 2013 14:15:56 +0200 (CEST) Subject: [Eventstudies-commits] r128 - pkg/vignettes Message-ID: <20130812121556.27920183ECF@r-forge.r-project.org> Author: vikram Date: 2013-08-12 14:15:55 +0200 (Mon, 12 Aug 2013) New Revision: 128 Modified: pkg/vignettes/eventstudies.Rnw Log: Minor modifications in vignette Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-12 11:44:36 UTC (rev 127) +++ pkg/vignettes/eventstudies.Rnw 2013-08-12 12:15:55 UTC (rev 128) @@ -375,14 +375,14 @@ ## Event study using market residual and bootstrap es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = TRUE, inference = TRUE, + to.plot = FALSE, inference = TRUE, inference.strategy = "bootstrap", type = "marketResidual", market.returns = nifty.index) ## Event study using excess return and bootstrap es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = TRUE, inference = TRUE, + to.plot = FALSE, inference = TRUE, inference.strategy = "bootstrap", type = "excessReturn", market.returns = nifty.index) @@ -390,13 +390,11 @@ es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = TRUE, inference = TRUE, + to.plot = FALSE, inference = TRUE, inference.strategy = "bootstrap", type = "AMM", - market.returns=nifty.index, - others=inrusd, - verbose=FALSE, - dates= NULL, + market.returns = nifty.index, + others=inrusd, verbose=FALSE, dates= NULL, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) @ From noreply at r-forge.r-project.org Mon Aug 12 14:19:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 12 Aug 2013 14:19:52 +0200 (CEST) Subject: [Eventstudies-commits] r129 - pkg/vignettes Message-ID: <20130812121952.B9B00183ECF@r-forge.r-project.org> Author: vikram Date: 2013-08-12 14:19:52 +0200 (Mon, 12 Aug 2013) New Revision: 129 Modified: pkg/vignettes/eventstudies.Rnw Log: Minor modifications in vignette Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-12 12:15:55 UTC (rev 128) +++ pkg/vignettes/eventstudies.Rnw 2013-08-12 12:19:52 UTC (rev 129) @@ -378,6 +378,7 @@ to.plot = FALSE, inference = TRUE, inference.strategy = "bootstrap", type = "marketResidual", market.returns = nifty.index) +es.mm ## Event study using excess return and bootstrap es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, From noreply at r-forge.r-project.org Mon Aug 12 14:41:47 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 12 Aug 2013 14:41:47 +0200 (CEST) Subject: [Eventstudies-commits] r130 - in pkg: data vignettes Message-ID: <20130812124147.839BC185489@r-forge.r-project.org> Author: vikram Date: 2013-08-12 14:41:46 +0200 (Mon, 12 Aug 2013) New Revision: 130 Modified: pkg/data/nifty.index.rda pkg/vignettes/eventstudies.Rnw Log: Updated Nifty data, now we have nifty data from 2001-01-01 to 2012-12-31 Modified: pkg/data/nifty.index.rda =================================================================== (Binary files differ) Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-12 12:19:52 UTC (rev 129) +++ pkg/vignettes/eventstudies.Rnw 2013-08-12 12:41:46 UTC (rev 130) @@ -226,7 +226,6 @@ %AMM model <<>>= # Create RHS before running AMM() -data(nifty.index) data(inr) inrusd <- diff(log(inr))*100 all.data <- merge(StockPriceReturns,nifty.index,inrusd,all=TRUE) From noreply at r-forge.r-project.org Thu Aug 15 14:01:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 15 Aug 2013 14:01:35 +0200 (CEST) Subject: [Eventstudies-commits] r131 - pkg/vignettes Message-ID: <20130815120135.93EE9184599@r-forge.r-project.org> Author: renukasane Date: 2013-08-15 14:01:35 +0200 (Thu, 15 Aug 2013) New Revision: 131 Added: pkg/vignettes/es.bib Modified: pkg/vignettes/eventstudies.Rnw Log: Revised version, not complete. Added: pkg/vignettes/es.bib =================================================================== --- pkg/vignettes/es.bib (rev 0) +++ pkg/vignettes/es.bib 2013-08-15 12:01:35 UTC (rev 131) @@ -0,0 +1,17 @@ + at Article{MacKinlay1997, + author = {A. Craig MacKinlay}, + title = {Event Studies in Economics and Finance}, + journal = {Journal of Economic Literature}, + year = 1997, + volume = {XXXV}, + pages = {13-39}} + + + at Article{Corrado2011, + author = {Charles J. Corrado}, + title = {Event studies: A methodology review}, + journal = {Accounting and Finance}, + year = 2011, + volume = 51, + pages = {207-234}} + Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-12 12:41:46 UTC (rev 130) +++ pkg/vignettes/eventstudies.Rnw 2013-08-15 12:01:35 UTC (rev 131) @@ -8,7 +8,8 @@ \usepackage{parskip} \usepackage{amsmath} \title{Introduction to the \textbf{eventstudies} package in R} -\author{Ajay Shah, Vimal Balasubramaniam and Vikram Bahure} +\author{Ajay Shah, Vimal Balasubramaniam, Vikram Bahure and Renuka + Sane} \begin{document} %\VignetteIndexEntry{eventstudies: A package with functionality to do Event Studies} %\VignetteDepends{} @@ -16,11 +17,13 @@ %\VignettePackage{eventstudies} \maketitle \begin{abstract} -The structure of the package and its implementation of event study -methodology is explained in this paper. In addition to converting -physical dates to event time frame, functions for re-indexing the -event time returns and bootstrap inference estimation. The methods and -functions are elucidated by employing data-set of SENSEX firms. + Event study analysis is a ubiquitous tool in the study of the impact + of events on the value of a firm. There is, however, no single + repository to undertake such an analysis with + R. \textbf{eventstudies} provides the toolbox to carry out an + event-study analysis. It contains functions to calculate measures of + firm returns, convert a data-set to event time and procedures for + inference. \end{abstract} \SweaveOpts{engine=R,pdf=TRUE} @@ -29,47 +32,41 @@ Event study methodology has been primarily used to evaluate the impact of specific events on the value of the firm. The typical procedure for -conducting an event study involves \citep{MacKinlay} +conducting an event study involves \citep{MacKinlay1997}: \begin{itemize} \item Defining the event of interest and the event window. The event - window is larger than the specific period of + window should be larger than the specific period of interest. % Generally the event % period itself is not included in the estimation period to prevent % the event from influencing the normal performance model parameter % estimates. - \item Determining the selection criteria for the inclusion of firms, - in the study \item Determining a measure of abnormal returns, the most common being the \textit{constant mean return model} and the \textit{market model}. This is important to disentangle the effects on stock prices of information that is specific to the firm under - question (e.g. stock split annoucement) and information that is - likely to affect stock prices marketwide (e.g. interest rates) - \item Analysis of firm returns around the event date + question (e.g. stock split announcement) and information that is + likely to affect stock prices market-wide (e.g. interest rates). + \item Analysis of firm returns around the event date. \end{itemize} The \textbf{eventstudies} package brings together the various aspects of an event study analysis in one library. It provides for functions -to calculate returns, transform data into event-time, and conduct -inference on the unit of interest. All functions in this package are -implemented in the R system for statistical computing. The package, -and R are available at no cost under the terms of the general public -license (GPL) from the comprehensive R archive network (CRAN, +to calculate returns, transform data into event-time, and inference +procedures. All functions in this package are implemented in the R +system for statistical computing. The package, and R are available at +no cost under the terms of the general public license (GPL) from the +comprehensive R archive network (CRAN, \texttt{http://CRAN.R-project.org}). This paper is organised as follows. A skeletal event study model is -presented in Section \ref{s::model}. Section \ref{s:approach} -discusses the software approach used in this package. The -functionalities of the package are discussed in Section -\ref{s:package-func}: the construction of the data-set in section -\ref{ss:construction}, estimation in section \ref{ss:estimation} and -inference in section \ref{ss:inference}. Section \ref{s:conclusion} -conclues the paper. +presented in Section \ref{s:model}. Section \ref{s:approach} discusses +the software approach used in this package. Section \ref{s:example} +shows an example. \section{Skeletal event study model} \label{s:model} In this section, we present a model to evaluate the impact of stock -splits on returns. +splits on returns \citep{Corrado2011}. Let day-0 identify the stock split date under scrutiny and let days t = ... -3,-2,-1 represent trading days leading up to the event. If @@ -98,7 +95,7 @@ \[ A_0 = R_0- E(R_0|RM_0) = R_0 - a - b RM_0 \] A series of abnormal returns from previous periods are also calculated -for comparison, and to determine statistical signficance. +for comparison, and to determine statistical significance. \[ A_t = R_t- E(R_t|RM_t) = R_t - a - b RM_t \] @@ -109,85 +106,98 @@ distributed. \section{Software approach} \label{s:approach} -The package offers the following functionalities: + +\textbf{eventstudies} offers the following functionalities: \begin{itemize} \item Models for calculating returns - \item Procedures for coverting data to event-time and remapping + \item Procedures for converting data to event-time and remapping event-frame \item Procedures for inference \end{itemize} -\subsection*{Models for calculating returns} -The package offers three models for calculating returns. These include -the excess return model, the standard market model, and the augmented -market model. The models are accessed using the following functions: - \begin{itemize} - \item \texttt{excessReturn}: estimation of excess return i.e. $R_j - - R_m$ where $R_j$ is the return of firm $j$ and $R_m$ is the market - return. - \item \texttt{marketResidual}: estimation of market residual after - extracting market returns from firm returns. - - \item \texttt{AMM}: estimation of the Augmented market model which - gives the market residual after extracting market returns and - currency returns from firm returns. The function allows for - specifying the type of the AMM model as well. - \end{itemize} +\subsection{Models for calculating returns} +Firm returns can be calculated using the following functions: +\begin{itemize} +\item \texttt{excessReturn}: estimation of excess returns i.e. $R_j - + R_m$ where $R_j$ is the return of firm $j$ and $R_m$ is the market + return. +\item \texttt{marketResidual}: estimation of market residual after + extracting market returns from firm returns. - The two common arguments for these functions are - \texttt{firm.returns} which is a time-series of stock returns, and - \texttt{market.returns}, which is a time-series of market - returns. The type of AMM model is specified with the option - \texttt{amm.type}. - - The output from these models is another time-series object which is - used for converting to event time. +\item \texttt{AMM}: estimation of the Augmented market model which + gives the market residual after extracting market returns and + currency returns from firm returns. The function allows for + specifying the type of the AMM model as well. +\end{itemize} + +The two common arguments for these functions are +\texttt{firm.returns} which is a time-series of stock returns, and +\texttt{market.returns}, which is a time-series of market +returns. The type of AMM model is specified with the option +\texttt{amm.type}. -\subsection*{Coverting the data-set to an event time} +The output from these models is also a time-series object. This +becomes the input for converting to event time. + +\subsection{Converting the data-set to an event time} The conversion of the returns data to event-time, and to cumulative returns is done using the following functions: \begin{itemize} - \item \texttt{phys2eventtime}: conversion to an event frame. This - requires a time series object of stock price returns and an - object with two columns \textit{unit} and \textit{when}, the date - of occurrence of the event. +\item \texttt{phys2eventtime}: conversion to an event frame. This + requires a time series object of stock price returns and an object + with two columns \textit{unit} and \textit{when}, the firms and the + date on which the event occurred respectively. \item \texttt{remap.cumsum}: conversion of returns to cumulative returns. The input for this function is the time-series data in - event-time that results from using \texttt{phys2eventtime}. + event-time that is the output from \texttt{phys2eventtime}. \end{itemize} -\subsection*{Procedures for inference} -Two procedures for inference are provided. These include: +\subsection{Procedures for inference} +Procedures for inference include: \begin{itemize} \item \texttt{inference.bootstrap}: estimation of bootstrap to - generate the distribution of cumulative returns series. + generate the distribution of cumulative returns series. \item \texttt{inference.wilcox}: estimation of wilcox inference to generate the distribution of cumulative returns series. -\end{itemize} + \end{itemize} + + The arguments for both these include \texttt{es.w}, the cumulative + returns in event-time. The argument \texttt{to.plot} plots the + confidence interval around returns series. -\section{Example: Performing Eventstudy analysis} +\section{Example: Performing eventstudy analysis} \label{s:example} We demonstrate the package with a study of the impact of stock splits -on the stock price of the firm. The data-set consist of the returns -series of the thirty index companies, as of 2013, of the Bombay Stock -Exchange (BSE), from 2001 to 2013. We have stock split dates for each -firm from 2000 onwards. +on the stock prices of firms. We use the returns series of the +thirty index companies, as of 2013, of the Bombay Stock Exchange +(BSE), from 2001 to 2013. We have stock split dates for each firm +from 2000 onwards. Our data consists of a \textit{zoo} object for stock price returns for the thirty firms. This is called \textit{StockPriceReturns} and -another zoo object, \textit{nifty.index}, of the market returns. +another zoo object, \textit{nifty.index}, of market returns. <<>>= library(eventstudies) data(StockPriceReturns) data(nifty.index) str(StockPriceReturns) -#head(StockPriceReturns) -#head(nifty.index) +head(StockPriceReturns) +head(nifty.index) @ +The dates of interest and the firms on which the event occurred are +stored in a data frame, \textit{SplitDates} with two columns +\textit{unit}, the name of the firms, and \textit{when}, the date of +the occurrence of the event. \textit{unit} should be in +\textit{character} format and \textit{when} in \textit{Date} format. + +<<>>= +data(SplitDates) +head(SplitDates) +@ \subsection{Calculating returns} The function \texttt{excessReturn} calculates the excess returns while @@ -252,26 +262,13 @@ \subsection{Conversion to event frame} -Before the returns data is converted to event-time, we need to know -the dates of interest. These are stored in a data frame, -\texttt{SplitDates} with two columns \textit{unit} and -\textit{when}. \textit{unit} has the name of the response series (firm -name for example) along with event date in -\textit{when}. \textit{unit} should be in \textit{character} format -and \textit{when} in \textit{Date} format. - -<<>>= -data(SplitDates) -head(SplitDates) -@ - For conversion to event time, the event date and the returns on that date are indexed to 0. Post-event dates are indexed as positive, and -pre-event dates as negative. This is done using the +pre-event dates as negative. The conversion is done using the \texttt{phys2eventtime} function. The function requires a returns -series, \textit{StockPriceReturns}, a data-frame with event unit -and time, \textit{SplitDates}, and the \texttt{width} for creating the -event-frame. +series, \textit{StockPriceReturns}, a data-frame with event unit and +time, \textit{SplitDates}, and the width for creating the +event-frame. <<>>= es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10) @@ -285,16 +282,16 @@ @ The output for \texttt{phys2eventtime} is a list. The first element of -a list is a time series object which is converted to event -time and the second element is \textit{outcomes} which shows if there -was any \textit{NA} in the dataset. If the outcome is \textit{success} -then all is well in the given window as specified by the -width. It gives \textit{wdatamissing} if there are too many -\textit{NAs} within the crucial event -window or \textit{wrongspan} if the event date is not placed within -the span of data for the unit or \textit{unitmissing} if a unit named -in events is not in \textit{z}. +a list is a time series object which is converted to event time. +The second element shows the \textit{outcome} of the conversion. If +the outcome is \textit{success} then all is well with the given window +as specified by the width. If there are too many NAs within the event +window, the outcome is \textit{wdatamissing}. The outcome for the +event date not being within the span of data for the unit is +\textit{wrongspan} while the outcome if a unit named in events is not +in the returns data is \textit{unitmissing}. + In the example described here, es.w contains the returns in event-time form for all the stocks. It contains variables for whom all data is available. @@ -310,17 +307,17 @@ \subsection{Inference procedures} \subsubsection{Bootstrap inference} -After converting to event frame and estimating the interest variable, -we need to check the stability of the result and derive other -estimates like standard errors and confidence intervals. For this, -we generate the sampling distribution for the estimate using bootstrap -inference. A detailed explanation of the methodology is presented in -Patnaik, Shah and Singh (2013). This specific approach used here is based on -\citet{davison1986efficient}. +After converting to event frame and estimating the variable of +interest, we need to check the stability of the result and derive +other estimates like standard errors and confidence intervals. For +this, we generate the sampling distribution for the estimate using +bootstrap inference. A detailed explanation of the methodology is +presented in \citep{PatnaikShahSingh2013}. This specific approach +used here is based on \citet{davison1986efficient}. The \textit{inference.bootstrap} function does the bootstrap to -generate distribution of $\bar{CR}$. The bootstrap generates -confidence interval at 2.5\% and 97.5\% for the estimate. +generate distribution of $\overline{CR}$. The bootstrap generates +confidence interval at 2.5 percent and 97.5 percent for the estimate. <<>>= result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) @@ -340,7 +337,7 @@ \subsubsection{Wilcoxon signed rank test} We next compute the Wilcoxon signed rank test, which is a -non-parametric inference test to compute confidence interval. +non-parametric inference test to compute the confidence interval. <<>>= result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) @ @@ -410,6 +407,6 @@ %\newpage \bibliographystyle{jss} -\bibliography{eventstudies} +\bibliography{es} \end{document} From noreply at r-forge.r-project.org Sat Aug 17 12:36:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 17 Aug 2013 12:36:28 +0200 (CEST) Subject: [Eventstudies-commits] r132 - pkg/vignettes Message-ID: <20130817103628.9AB541853D9@r-forge.r-project.org> Author: vimsaa Date: 2013-08-17 12:36:28 +0200 (Sat, 17 Aug 2013) New Revision: 132 Modified: pkg/vignettes/eventstudies.Rnw Log: Edits for the first few sections of the vignette. Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-15 12:01:35 UTC (rev 131) +++ pkg/vignettes/eventstudies.Rnw 2013-08-17 10:36:28 UTC (rev 132) @@ -8,301 +8,292 @@ \usepackage{parskip} \usepackage{amsmath} \title{Introduction to the \textbf{eventstudies} package in R} -\author{Ajay Shah, Vimal Balasubramaniam, Vikram Bahure and Renuka - Sane} +\author{Vikram Bahure and Renuka Sane and Ajay Shah\thanks{We thank + Chirag Anand for valuable inputs in the creation of this vignette.}} \begin{document} -%\VignetteIndexEntry{eventstudies: A package with functionality to do Event Studies} -%\VignetteDepends{} -%\VignetteKeywords{event studies} -%\VignettePackage{eventstudies} +% \VignetteIndexEntry{eventstudies: A package with functionality +% to do Event Studies} \VignetteDepends{} \VignetteKeywords{event +% studies} \VignettePackage{eventstudies} \maketitle + \begin{abstract} - Event study analysis is a ubiquitous tool in the study of the impact - of events on the value of a firm. There is, however, no single - repository to undertake such an analysis with - R. \textbf{eventstudies} provides the toolbox to carry out an - event-study analysis. It contains functions to calculate measures of - firm returns, convert a data-set to event time and procedures for - inference. + Event study analysis is a ubiquitous tool in the econometric + analysis of an event and its impact on the measured + outcome. Although widely used in finance, it is a generic tool + that can be used for other purposes as well. There is, however, + no single repository to undertake such an analysis with + R. \texttt{eventstudies} provides the toolbox to carry out an + event-study analysis. It contains functions to transform data + into the event-time frame and procedures for statistical + inference. In this vignette, we provide a finance example and + utilise the rich features of this package. \end{abstract} \SweaveOpts{engine=R,pdf=TRUE} \section{Introduction} -Event study methodology has been primarily used to evaluate the impact -of specific events on the value of the firm. The typical procedure for -conducting an event study involves \citep{MacKinlay1997}: -\begin{itemize} -\item Defining the event of interest and the event window. The event - window should be larger than the specific period of - interest. % Generally the event - % period itself is not included in the estimation period to prevent - % the event from influencing the normal performance model parameter - % estimates. - \item Determining a measure of abnormal returns, the most common - being the \textit{constant mean return model} and the - \textit{market model}. This is important to disentangle the effects - on stock prices of information that is specific to the firm under - question (e.g. stock split announcement) and information that is - likely to affect stock prices market-wide (e.g. interest rates). - \item Analysis of firm returns around the event date. -\end{itemize} +Event study methodology has been primarily used to evaluate the +impact of specific events on the value of a firm. The typical +procedure for conducting an event study involves +\citep{MacKinlay1997}: +\begin{enumerate} +\item Defining the event of interest and the event window. The + event window should be larger than the specific period of + interest. +\item Determining a measure of abnormal returns, the most common + being the \textit{constant mean return model} and the + \textit{market model}. This is important to disentangle the + effects on stock prices of information that is specific to the + firm under question (e.g. stock split announcement) and + information that is likely to affect all stock prices + (e.g. interest rates). +\item Analysis of firm returns on or after the event date. +\end{enumerate} -The \textbf{eventstudies} package brings together the various aspects -of an event study analysis in one library. It provides for functions -to calculate returns, transform data into event-time, and inference -procedures. All functions in this package are implemented in the R -system for statistical computing. The package, and R are available at -no cost under the terms of the general public license (GPL) from the -comprehensive R archive network (CRAN, -\texttt{http://CRAN.R-project.org}). +The \textbf{eventstudies} package brings together the various +aspects of an event study analysis in one library. It provides for +functions to calculate returns, transform data into event-time, +and inference procedures. All functions in this package are +implemented in the R system for statistical computing. The +package, and R are available at no cost under the terms of the +general public license (GPL) from the comprehensive R archive +network (CRAN, \texttt{http://CRAN.R-project.org}). -This paper is organised as follows. A skeletal event study model is -presented in Section \ref{s:model}. Section \ref{s:approach} discusses -the software approach used in this package. Section \ref{s:example} -shows an example. +This paper is organised as follows. A skeletal event study model +is presented in Section \ref{s:model}. Section \ref{s:approach} +discusses the software approach used in this package. Section +\ref{s:example} shows an example. \section{Skeletal event study model} \label{s:model} -In this section, we present a model to evaluate the impact of stock -splits on returns \citep{Corrado2011}. +In this section, we present a model to evaluate the impact of +stock splits on returns \citep{Corrado2011}. -Let day-0 identify the stock split date under scrutiny and let days -t = ... -3,-2,-1 represent trading days leading up to the event. If -the return on the firm with the stock split $R_o$ is statistically -large compared to returns on previous dates, we may conclude that the -stock split event had a significant price impact. +Let day $-0$ identify the stock split date under scrutiny and let +days t = $...,-3,-2,-1$ represent trading days leading up to the +event. If the return on the firm with the stock split $R_o$ is +statistically large compared to returns on previous dates, we may +conclude that the stock split event had a significant price +impact. To disentangle the impact of the stock split on the returns of the -firm from general market-wide information, we use the market-model to -adjust the event-date return, thus removing the influence of market -information. +firm from general market-wide information, we use the market-model +to adjust the event-date return, thus removing the influence of +market information. The market model is calculated as follows: \[ R_t = a + b RM_t + e_t \] -The firm-specific return $e_t$ is unrelated to the overall market and -has an expected value of zero. Hence, the expected event date return -conditional on the event date market return is +The firm-specific return $e_t$ is unrelated to the overall market +and has an expected value of zero. Hence, the expected event date +return conditional on the event date market return is \[ E(R_0|RM_0) = a + b RM_0 \] -The abnormal return $A_0$ is simply the day-zero firm-specific return -$e_0$: +The abnormal return $A_0$ is simply the day-zero firm-specific +return $e_0$: \[ A_0 = R_0- E(R_0|RM_0) = R_0 - a - b RM_0 \] -A series of abnormal returns from previous periods are also calculated -for comparison, and to determine statistical significance. +A series of abnormal returns from previous periods are also +calculated for comparison, and to determine statistical +significance. -\[ A_t = R_t- E(R_t|RM_t) = R_t - a - b RM_t \] +\[ A_t = R_t- E(R_t|RM_t) = R_t - a - b RM_t \] -The event date abnormal return $A_0$ is then assessed for statistical -significance relative to the distribution of abnormal returns $A_t$ in -the control period. A common assumption used to formulate tests of -statistical significance is that abnormal returns are normally -distributed. +The event date abnormal return $A_0$ is then assessed for +statistical significance relative to the distribution of abnormal +returns $A_t$ in the control period. A common assumption used to +formulate tests of statistical significance is that abnormal +returns are normally distributed. \section{Software approach} \label{s:approach} \textbf{eventstudies} offers the following functionalities: + \begin{itemize} - \item Models for calculating returns - \item Procedures for converting data to event-time and remapping - event-frame - \item Procedures for inference +\item Models for calculating returns +\item Procedures for converting data to event-time and remapping + event-frame +\item Procedures for inference \end{itemize} \subsection{Models for calculating returns} + Firm returns can be calculated using the following functions: + \begin{itemize} -\item \texttt{excessReturn}: estimation of excess returns i.e. $R_j - - R_m$ where $R_j$ is the return of firm $j$ and $R_m$ is the market - return. -\item \texttt{marketResidual}: estimation of market residual after - extracting market returns from firm returns. +\item \texttt{excessReturn}: estimation of excess returns + i.e. $R_j - R_m$ where $R_j$ is the return of firm $j$ and $R_m$ + is the market return. +\item \texttt{marketResidual}: estimation of market model to + obtain idiosyncratic firm returns, controlling for the market + returns. + \item \texttt{AMM}: estimation of the Augmented market model which - gives the market residual after extracting market returns and - currency returns from firm returns. The function allows for - specifying the type of the AMM model as well. + provides user the capability to run a multivariate market model + with orthogonalisation and obtain idiosyncratic returns. + \end{itemize} - -The two common arguments for these functions are -\texttt{firm.returns} which is a time-series of stock returns, and -\texttt{market.returns}, which is a time-series of market -returns. The type of AMM model is specified with the option -\texttt{amm.type}. + +% Once AMM() is rewritten, one paragraph on the onefirmAMM +% arguments here used with AMM(...). The output from these models is also a time-series object. This -becomes the input for converting to event time. +becomes the input for converting to event time. % Check if I can + % work with 'xts' and/or 'zoo'? \subsection{Converting the data-set to an event time} -The conversion of the returns data to event-time, and to cumulative -returns is done using the following functions: + +The conversion of the returns data to event-time, and to +cumulate returns is done using the following functions: + \begin{itemize} \item \texttt{phys2eventtime}: conversion to an event frame. This - requires a time series object of stock price returns and an object - with two columns \textit{unit} and \textit{when}, the firms and the - date on which the event occurred respectively. + requires a time series object of stock price returns and an + object with two columns \textit{unit} and \textit{when}, the + firms and the date on which the event occurred respectively. - \item \texttt{remap.cumsum}: conversion of returns to cumulative - returns. The input for this function is the time-series data in - event-time that is the output from \texttt{phys2eventtime}. +\item \texttt{remap.cumsum}: conversion of returns to cumulative + returns. The input for this function is the time-series data in + event-time that is the output from \texttt{phys2eventtime}. \end{itemize} \subsection{Procedures for inference} Procedures for inference include: \begin{itemize} - \item \texttt{inference.bootstrap}: estimation of bootstrap to - generate the distribution of cumulative returns series. - \item \texttt{inference.wilcox}: estimation of wilcox inference to - generate the distribution of cumulative returns series. - \end{itemize} +\item \texttt{inference.bootstrap}: estimation of bootstrap to + generate the distribution of cumulative returns series. + +\item \texttt{inference.wilcox}: estimation of wilcox inference to + generate the distribution of cumulative returns series. +\end{itemize} - The arguments for both these include \texttt{es.w}, the cumulative - returns in event-time. The argument \texttt{to.plot} plots the - confidence interval around returns series. +The arguments for both these include \texttt{es.w}, the cumulative +returns in event-time. The argument \texttt{to.plot} plots the +confidence interval around returns series. -\section{Example: Performing eventstudy analysis} +\section{Example: Performing eventstudy analysis} \label{s:example} -We demonstrate the package with a study of the impact of stock splits -on the stock prices of firms. We use the returns series of the -thirty index companies, as of 2013, of the Bombay Stock Exchange -(BSE), from 2001 to 2013. We have stock split dates for each firm -from 2000 onwards. +We demonstrate the package with a study of the impact of stock +splits on the stock prices of firms. We use the returns series of +the thirty index companies, as of 2013, of the Bombay Stock +Exchange (BSE), from 2001 to 2013. We have stock split dates for +each firm from 2000 onwards. -Our data consists of a \textit{zoo} object for stock price returns for -the thirty firms. This is called \textit{StockPriceReturns} and -another zoo object, \textit{nifty.index}, of market returns. +Our data consists of a \textit{zoo} object for stock price returns +for the thirty firms. This is called \textit{StockPriceReturns} +and another zoo object, \textit{nifty.index}, of market returns. -<<>>= -library(eventstudies) -data(StockPriceReturns) -data(nifty.index) -str(StockPriceReturns) -head(StockPriceReturns) -head(nifty.index) -@ +<<>>= library(eventstudies) data(StockPriceReturns) +data(nifty.index) str(StockPriceReturns) head(StockPriceReturns) +head(nifty.index) @ -The dates of interest and the firms on which the event occurred are -stored in a data frame, \textit{SplitDates} with two columns -\textit{unit}, the name of the firms, and \textit{when}, the date of -the occurrence of the event. \textit{unit} should be in -\textit{character} format and \textit{when} in \textit{Date} format. +The dates of interest and the firms on which the event occurred +are stored in a data frame, \textit{SplitDates} with two columns +\textit{unit}, the name of the firms, and \textit{when}, the date +of the occurrence of the event. \textit{unit} should be in +\textit{character} format and \textit{when} in \textit{Date} +format. -<<>>= -data(SplitDates) -head(SplitDates) -@ +<<>>= data(SplitDates) head(SplitDates) @ \subsection{Calculating returns} -The function \texttt{excessReturn} calculates the excess returns while -\texttt{marketResidual} calculates the market model. The two inputs -are \texttt{firm.returns} and \texttt{market.returns}. The results are -stored in \texttt{er.result} and \texttt{mm.result} respectively. +The function \texttt{excessReturn} calculates the excess returns +while \texttt{marketResidual} calculates the market model. The two +inputs are \texttt{firm.returns} and \texttt{market.returns}. The +results are stored in \texttt{er.result} and \texttt{mm.result} +respectively. -<<>>= -# Excess return -er.result <- excessReturn(firm.returns = StockPriceReturns, - market.returns = nifty.index) -er.result <- er.result[rowSums(is.na(er.result))!=NCOL(er.result),] +<<>>= # Excess return er.result <- excessReturn(firm.returns = +StockPriceReturns, market.returns = nifty.index) er.result <- +er.result[rowSums(is.na(er.result))!=NCOL(er.result),] head(er.result[,1:3]) -@ -<<>>= -# Extracting market residual -mm.result <- marketResidual(firm.returns = StockPriceReturns, - market.returns = nifty.index) -mm.result <- mm.result[rowSums(is.na(mm.result))!=NCOL(mm.result),] +@ <<>>= # Extracting market residual mm.result <- +marketResidual(firm.returns = StockPriceReturns, market.returns = +nifty.index) mm.result <- +mm.result[rowSums(is.na(mm.result))!=NCOL(mm.result),] head(mm.result[,1:3]) -@ +@ The \texttt{AMM} model requires a time-series of the exchange rate -along with firm returns and market returns. This is done by loading -the \textit{inr} data, which is the INR-USD exchange rate for the same -period. The complete data-set consisting of stock returns, market -returns, and exchange rate is first created. +along with firm returns and market returns. This is done by +loading the \textit{inr} data, which is the INR-USD exchange rate +for the same period. The complete data-set consisting of stock +returns, market returns, and exchange rate is first created. The inputs into the \texttt{AMM} model also include -\texttt{firm.returns} and \texttt{market.returns}. Currency returns -can be specified using \texttt{others}. Two types of the AMM model are -supported: \textit{residual} and \textit{all}. +\texttt{firm.returns} and \texttt{market.returns}. Currency +returns can be specified using \texttt{others}. Two types of the +AMM model are supported: \textit{residual} and \textit{all}. -%AMM model -<<>>= -# Create RHS before running AMM() -data(inr) -inrusd <- diff(log(inr))*100 -all.data <- merge(StockPriceReturns,nifty.index,inrusd,all=TRUE) -StockPriceReturns <- all.data[,-which(colnames(all.data)%in%c("nifty.index", - "inr"))] -nifty.index <- all.data$nifty.index -inrusd <- all.data$inr +% AMM model +<<>>= # Create RHS before running AMM() data(inr) inrusd <- +diff(log(inr))*100 all.data <- +merge(StockPriceReturns,nifty.index,inrusd,all=TRUE) +StockPriceReturns <- +all.data[,-which(colnames(all.data)%in%c("nifty.index", +"inr"))] nifty.index <- all.data$nifty.index inrusd <- +all.data$inr -## AMM output -## For Full period: dates=NULL -amm.residual <- AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], - verbose=FALSE, - dates= NULL, - market.returns=nifty.index, others=inrusd, - switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=0) +## AMM output ## For Full period: dates=NULL amm.residual <- +AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], +verbose=FALSE, dates= NULL, market.returns=nifty.index, +others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, +nlags=0) -amm.output <- AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], - verbose=FALSE, - dates= NULL, - market.returns=nifty.index, others=inrusd, - switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) +amm.output <- +AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], +verbose=FALSE, dates= NULL, market.returns=nifty.index, +others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, +nlags=1) -@ +@ \subsection{Conversion to event frame} -For conversion to event time, the event date and the returns on that -date are indexed to 0. Post-event dates are indexed as positive, and -pre-event dates as negative. The conversion is done using the -\texttt{phys2eventtime} function. The function requires a returns -series, \textit{StockPriceReturns}, a data-frame with event unit and -time, \textit{SplitDates}, and the width for creating the -event-frame. +For conversion to event time, the event date and the returns on +that date are indexed to 0. Post-event dates are indexed as +positive, and pre-event dates as negative. The conversion is done +using the \texttt{phys2eventtime} function. The function requires +a returns series, \textit{StockPriceReturns}, a data-frame with +event unit and time, \textit{SplitDates}, and the width for +creating the event-frame. -<<>>= -es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, width=10) -str(es) -es$outcomes -es.w <- window(es$z.e, start=-10, end=10) -colnames(es.w) <- SplitDates[which(es$outcomes=="success"),1] -SplitDates[1,] -StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] -es.w[,1] -@ +<<>>= es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, +width=10) str(es) es$outcomes es.w <- window(es$z.e, start=-10, +end=10) colnames(es.w) <- +SplitDates[which(es$outcomes=="success"),1] SplitDates[1,] +StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] es.w[,1] @ -The output for \texttt{phys2eventtime} is a list. The first element of -a list is a time series object which is converted to event time. +The output for \texttt{phys2eventtime} is a list. The first +element of a list is a time series object which is converted to +event time. -The second element shows the \textit{outcome} of the conversion. If -the outcome is \textit{success} then all is well with the given window -as specified by the width. If there are too many NAs within the event -window, the outcome is \textit{wdatamissing}. The outcome for the -event date not being within the span of data for the unit is -\textit{wrongspan} while the outcome if a unit named in events is not -in the returns data is \textit{unitmissing}. +The second element shows the \textit{outcome} of the +conversion. If the outcome is \textit{success} then all is well +with the given window as specified by the width. If there are too +many NAs within the event window, the outcome is +\textit{wdatamissing}. The outcome for the event date not being +within the span of data for the unit is \textit{wrongspan} while +the outcome if a unit named in events is not in the returns data +is \textit{unitmissing}. -In the example described here, es.w contains the returns in event-time -form for all the stocks. It contains variables for whom all data is -available. +In the example described here, es.w contains the returns in +event-time form for all the stocks. It contains variables for whom +all data is available. -Once the returns are converted to event-time, \texttt{remap.cumsum} -function is used to convert the returns to cumulative returns. +Once the returns are converted to event-time, +\texttt{remap.cumsum} function is used to convert the returns to +cumulative returns. -<<>>= -es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) -es.cs[,1] -@ +<<>>= es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) es.cs[,1] @ \subsection{Inference procedures} \subsubsection{Bootstrap inference} @@ -317,96 +308,82 @@ The \textit{inference.bootstrap} function does the bootstrap to generate distribution of $\overline{CR}$. The bootstrap generates -confidence interval at 2.5 percent and 97.5 percent for the estimate. +confidence interval at 2.5 percent and 97.5 percent for the +estimate. -<<>>= -result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) -@ +<<>>= result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) @ \begin{figure}[t] \begin{center} \caption{Stock splits event and response of respective stock returns: Bootstrap CI} \setkeys{Gin}{width=0.8\linewidth} - \setkeys{Gin}{height=0.8\linewidth} -<>= - result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) -@ -\end{center} -\label{fig:one} + \setkeys{Gin}{height=0.8\linewidth} <>= + result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) @ + \end{center} + \label{fig:one} \end{figure} \subsubsection{Wilcoxon signed rank test} We next compute the Wilcoxon signed rank test, which is a non-parametric inference test to compute the confidence interval. -<<>>= -result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) -@ +<<>>= result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) @ \begin{figure}[t] \begin{center} \caption{Stock splits event and response of respective stock returns: Wilcoxon CI} \setkeys{Gin}{width=0.8\linewidth} - \setkeys{Gin}{height=0.8\linewidth} -<>= - result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) -@ -\end{center} -\label{fig:two} + \setkeys{Gin}{height=0.8\linewidth} <>= + result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) @ + \end{center} + \label{fig:two} \end{figure} \subsection{General eventstudy function} \texttt{eventstudy} is a wrapper around all the internal -functions. Several examples of the use of this function are provided -below. +functions. Several examples of the use of this function are +provided below. -<<>>= -## Event study without adjustment -es.na <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, - width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = TRUE, inference = TRUE, - inference.strategy = "wilcoxon", - type = "None") +<<>>= ## Event study without adjustment es.na <- +eventstudy(firm.returns = StockPriceReturns, eventList = +SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot += TRUE, inference = TRUE, inference.strategy = "wilcoxon", type = +"None") -## Event study using market residual and bootstrap -es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, - width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = FALSE, inference = TRUE, - inference.strategy = "bootstrap", - type = "marketResidual", market.returns = nifty.index) -es.mm +## Event study using market residual and bootstrap es.mm <- +eventstudy(firm.returns = StockPriceReturns, eventList = +SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot += FALSE, inference = TRUE, inference.strategy = "bootstrap", type += "marketResidual", market.returns = nifty.index) es.mm -## Event study using excess return and bootstrap -es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, - width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = FALSE, inference = TRUE, - inference.strategy = "bootstrap", - type = "excessReturn", market.returns = nifty.index) +## Event study using excess return and bootstrap es.er <- +eventstudy(firm.returns = StockPriceReturns, eventList = +SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot += FALSE, inference = TRUE, inference.strategy = "bootstrap", type += "excessReturn", market.returns = nifty.index) ## Event study using augmented market model (AMM) and bootstrap -es.amm <- eventstudy(firm.returns = StockPriceReturns, - eventList = SplitDates, - width = 10, to.remap = TRUE, remap = "cumsum", - to.plot = FALSE, inference = TRUE, - inference.strategy = "bootstrap", - type = "AMM", - market.returns = nifty.index, - others=inrusd, verbose=FALSE, dates= NULL, - switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) +es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = +SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot += FALSE, inference = TRUE, inference.strategy = "bootstrap", type += "AMM", market.returns = nifty.index, others=inrusd, +verbose=FALSE, dates= NULL, switch.to.innov=TRUE, +market.returns.purge=TRUE, nlags=1) -@ +@ \section{Computational details} -The package code is purely written in R. It has dependencies to zoo +The package code is purely written in R. It has dependencies to +zoo (\href{http://cran.r-project.org/web/packages/zoo/index.html}{Zeileis 2012}) and boot (\href{http://cran.r-project.org/web/packages/boot/index.html}{Ripley - 2013}). R itself as well as these packages can be obtained from \href{http://CRAN.R-project.org/}{CRAN}. -%\section{Acknowledgments} + 2013}). R itself as well as these packages can be obtained from +\href{http://CRAN.R-project.org/}{CRAN}. +% \section{Acknowledgments} -%\newpage -\bibliographystyle{jss} -\bibliography{es} +% \newpage +\bibliographystyle{jss} \bibliography{es} \end{document} From noreply at r-forge.r-project.org Sat Aug 17 13:10:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 17 Aug 2013 13:10:51 +0200 (CEST) Subject: [Eventstudies-commits] r133 - pkg/man Message-ID: <20130817111051.D48BC185113@r-forge.r-project.org> Author: vimsaa Date: 2013-08-17 13:10:51 +0200 (Sat, 17 Aug 2013) New Revision: 133 Modified: pkg/man/SplitDates.Rd pkg/man/StockPriceReturns.Rd pkg/man/ees.Rd pkg/man/eesData.Rd pkg/man/eesPlot.Rd pkg/man/eventstudy-package.Rd pkg/man/eventstudy.Rd Log: Edits to Rd files. Got two-thirds to go. Modified: pkg/man/SplitDates.Rd =================================================================== --- pkg/man/SplitDates.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/SplitDates.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -4,17 +4,16 @@ \alias{SplitDates} -\title{It is the data-set used for event-study analysis.} +\title{A set of events to perform eventstudy analysis.} \description{ -It has stock split event dates for the BSE index firms with two columns 'unit' which has firm names and 'when' which has event date for the firm. -} +The data contains stock split event dates for the index constituents of the Bombay Stock Exchange index (SENSEX). The data format follows the required format in the function \code{phys2eventtime}, with two columns 'unit' (firm name) and 'when' (stock split date).} \usage{data(SplitDates)} -\format{An object with class attributes \code{zoo} containing resposne series for eventstudy and a data frame with stock split event dates.} +\format{\code{data.frame}} \examples{ data(SplitDates) } -\keyword{datasets} +\keyword{dataset} \ No newline at end of file Modified: pkg/man/StockPriceReturns.Rd =================================================================== --- pkg/man/StockPriceReturns.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/StockPriceReturns.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -4,15 +4,14 @@ \alias{StockPriceReturns} -\title{It is the data-set used for event-study analysis.} +\title{An example dataset of stock price returns to perform eventstudy analysis.} -\description{ -It has stock price returns for index constituents of Bombay Stock Exchange (BSE), nifty index and INR/USD returns. -} +\description{Daily stock price returns for the index constituents of the Bombay Stock Exchange Index (SENSEX) and the National Stock Exchange of India Index (NIFTY), NIFTY index, and the Rupee-Dollar exchange rate returns.} + \usage{data(StockPriceReturns)} -\format{An object with class attributes \code{zoo} containing resposne series for eventstudy.} +\format{\code{zoo}} \examples{ data(StockPriceReturns) Modified: pkg/man/ees.Rd =================================================================== --- pkg/man/ees.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/ees.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -2,36 +2,29 @@ \alias{ees} \title{ -Extreme events study for a time series. +Extreme events study analysis for a univariate time series } \description{ -This function identifies the extreme events from a time -series. It also generates summary statistics for clustered and -unclustered extreme event distribution. - } +This function identifies tail events on a univariate time series, generates summary statistics for clustered and unclustered tail events.} \usage{ ees(input,prob.value) } \arguments{ - \item{input}{'input' is the time-series on which extreme event - analysis is done. This series should in returns format.} - \item{prob.value}{It is the tail value on the basis of which the - extreme event are defined. For eg: prob.value of 5 will consider 5\% tail on both sides.} + \item{input}{A univariate time series for which tail events identification is required.} + \item{prob.value}{The cut off (in percent) on the probability distribution for the tail event.} } -\value{ - Output is in a list format with following items: +\value{ A \code{list} object that contains: \item{Summary statistics}{Summary of the data set} - \item{Lower tail}{Distribution of extreme events; Run length - distribution; Quantile values; Yearly distribution; Extreme event - data} + \item{Lower tail}{Distribution of extreme events; Run length + distribution; Quantile values; Yearly distribution; and the tail events data} \item{Upper tail}{Distribution of extreme events; Run length - distribution; Quantile values; Yearly distribution; Extreme event - data} + distribution; Quantile values; Yearly distribution; and the tail events data} } + \references{To convert number to words, code uses function \href{http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46843.html}{numbers2words} by \href{http://socserv.mcmaster.ca/jfox/}{John Fox} and deprintize function by \href{http://mbq.me/}{Miron Kursa} } \author{Vikram Bahure} Modified: pkg/man/eesData.Rd =================================================================== --- pkg/man/eesData.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/eesData.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -4,15 +4,13 @@ \alias{eesData} -\title{It is the data-set used for event-study analysis.} +\title{Returns data used for extreme events analysis} -\description{ -It is a time series object with daily series for S&P 500 and Nifty (NSE index). -} +\description{A daily time series object for S&P 500 and the NIFTY Index.} \usage{data(eesData)} -\format{An object with class attributes \code{zoo} containing resposne series for eventstudy.} +\format{\code{zoo}} \examples{ data(eesData) Modified: pkg/man/eesPlot.Rd =================================================================== --- pkg/man/eesPlot.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/eesPlot.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -2,13 +2,13 @@ \alias{eesPlot} \title{ -Plotting clustered and unclustered extreme event study plot. +Plotting clustered and unclustered extreme events retuns. } \description{ -This function generates an extreme event study plot by marking extreme events and fusing clustered events together. It plots event study plot for lower tail and upper tail events. Tail events are defined as per given probability value. The value of the event series and response series should be in returns. - } +This function creates an event study plot that treats all clustered events as one event. It plots both the lower and upper tail events and the events are defined based on the cut off probability values provided (in percentage terms).} + \usage{ eesPlot(z, response.series.name, event.series.name, titlestring, ylab, width, prob.value) } @@ -16,20 +16,18 @@ \arguments{ \item{z}{Data object with both response and event series on which event study is to be performed} \item{response.series.name}{Column name of the series in 'z' on which response is to be observed } - \item{event.series.name}{Column name of the series in 'z' on which event is to be observed } - \item{titlestring}{Title for event study plot: Preferred to be response series name} + \item{event.series.name}{Column name of the series in 'z' on which event is to be defined } + \item{titlestring}{Title for event study plot} \item{ylab}{Y-axis label} \item{width}{Width for event study plot} - \item{prob.value}{It is the tail value on the basis of which the - extreme event are defined. For eg: prob.value of 5 will consider 5\% tail on both sides.} + \item{prob.value}{Cut-off values in the probability distribution (in percentage terms)} } \value{ - It gives an extreme event study plot for very bad (lower tail) and very good (upper tail) events on event series. -} +A plot of the response series with lower and upper tail events defined on the event series.} \examples{ library(eventstudies) data(eesData) eesPlot(z=eesData, response.series.name="nifty", event.series.name="sp500",titlestring="S&P500", ylab="(Cum.) change in NIFTY") -} +} \ No newline at end of file Modified: pkg/man/eventstudy-package.Rd =================================================================== --- pkg/man/eventstudy-package.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/eventstudy-package.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -26,9 +26,9 @@ } \author{ -Ajay Shah, Vimal Balasubramniam, Vikram Bahure +Ajay Shah, Chirag Anand, Vikram Bahure, Vimal Balasubramaniam -Maintainer: economics.vikram at gmail.com +Maintainer: Vikram Bahure } \keyword{ eventstudies } Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2013-08-17 10:36:28 UTC (rev 132) +++ pkg/man/eventstudy.Rd 2013-08-17 11:10:51 UTC (rev 133) @@ -1,10 +1,9 @@ \name{eventstudy} \alias{eventstudy} -\title{Performs event study using different methods and computes confidence intervals using different inference models} +\title{A wrapper that performs eventstudies using different methods} -\description{ This function generates event study output and further computes confidence intervals using bootstrap or wilcox method. -} +\description{This function undertakes an eventstudy based on the inference methodology chosen by the user.} \usage{ eventstudy(firm.returns = NULL, From noreply at r-forge.r-project.org Sat Aug 17 15:31:20 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 17 Aug 2013 15:31:20 +0200 (CEST) Subject: [Eventstudies-commits] r134 - / Message-ID: <20130817133120.64D2018549F@r-forge.r-project.org> Author: chiraganand Date: 2013-08-17 15:31:20 +0200 (Sat, 17 Aug 2013) New Revision: 134 Added: todo.org Log: Added todo list Added: todo.org =================================================================== --- todo.org (rev 0) +++ todo.org 2013-08-17 13:31:20 UTC (rev 134) @@ -0,0 +1,35 @@ +List of things need to be done. + +* eventstudies package + - should work with data.frames, zoo, xts + - create a generic "eventstudies" class + - DESIGN!!! + +* phys2eventtime + - more testing: all output is unitmissing + - parallelise (provide an argument to the user) + - document: + > stopifnot(sum(outcomes=="success") == NCOL(z.e)) + - if data is missing within the width around the event date, we + simply discard that particular observation from the dataset! + +* AMM() + - vectorise it + - parallelise it + - don't ask the user for amm.type in the eventstudies() function + - separate vignette + - Rewriting? # XXX + +* Vignette + - improvements in AMM() + - missing entries in .bib + - need to define all the variables used + - citation for Corrado (2011) seems misplaced in the beginning. It + seems as though we are replicating his work on stock-splits, which + isn't the case + +* man pages + - modify ess.Rd: put reference to Patnaik, Shah, and Singh (2013) + +* es-match + - synthetic returns From noreply at r-forge.r-project.org Mon Aug 19 11:26:48 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 19 Aug 2013 11:26:48 +0200 (CEST) Subject: [Eventstudies-commits] r135 - pkg/vignettes Message-ID: <20130819092648.CB75B181059@r-forge.r-project.org> Author: vimsaa Date: 2013-08-19 11:26:48 +0200 (Mon, 19 Aug 2013) New Revision: 135 Modified: pkg/vignettes/eventstudies.Rnw Log: Please be careful with auto-formatting the Rnw file with emacs. It messed up the Rnw file Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-17 13:31:20 UTC (rev 134) +++ pkg/vignettes/eventstudies.Rnw 2013-08-19 09:26:48 UTC (rev 135) @@ -189,9 +189,14 @@ for the thirty firms. This is called \textit{StockPriceReturns} and another zoo object, \textit{nifty.index}, of market returns. -<<>>= library(eventstudies) data(StockPriceReturns) -data(nifty.index) str(StockPriceReturns) head(StockPriceReturns) -head(nifty.index) @ +<<>>= +library(eventstudies) +data(StockPriceReturns) +data(nifty.index) +str(StockPriceReturns) +head(StockPriceReturns) +head(nifty.index) +@ The dates of interest and the firms on which the event occurred are stored in a data frame, \textit{SplitDates} with two columns @@ -200,7 +205,11 @@ \textit{character} format and \textit{when} in \textit{Date} format. -<<>>= data(SplitDates) head(SplitDates) @ +<<>>= +data(SplitDates) +head(SplitDates) +@ + \subsection{Calculating returns} The function \texttt{excessReturn} calculates the excess returns @@ -209,15 +218,20 @@ results are stored in \texttt{er.result} and \texttt{mm.result} respectively. -<<>>= # Excess return er.result <- excessReturn(firm.returns = -StockPriceReturns, market.returns = nifty.index) er.result <- -er.result[rowSums(is.na(er.result))!=NCOL(er.result),] +<<>>= # Excess return +er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = nifty.index) + +er.result <- er.result[rowSums(is.na(er.result))!=NCOL(er.result),] head(er.result[,1:3]) -@ <<>>= # Extracting market residual mm.result <- -marketResidual(firm.returns = StockPriceReturns, market.returns = -nifty.index) mm.result <- -mm.result[rowSums(is.na(mm.result))!=NCOL(mm.result),] +@ + +<<>>= +# Extracting market residual +mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = +nifty.index) + +mm.result <- mm.result[rowSums(is.na(mm.result))!=NCOL(mm.result),] head(mm.result[,1:3]) @ @@ -234,22 +248,24 @@ AMM model are supported: \textit{residual} and \textit{all}. % AMM model -<<>>= # Create RHS before running AMM() data(inr) inrusd <- -diff(log(inr))*100 all.data <- -merge(StockPriceReturns,nifty.index,inrusd,all=TRUE) -StockPriceReturns <- -all.data[,-which(colnames(all.data)%in%c("nifty.index", -"inr"))] nifty.index <- all.data$nifty.index inrusd <- -all.data$inr +<<>>= +# Create RHS before running AMM() +data(inr) +inrusd <- diff(log(inr))*100 +all.data <- merge(StockPriceReturns,nifty.index,inrusd,all=TRUE) +StockPriceReturns <- all.data[,-which(colnames(all.data)%in%c("nifty.index", +"inr"))] +nifty.index <- all.data$nifty.index +inrusd <- all.data$inr -## AMM output ## For Full period: dates=NULL amm.residual <- -AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], +## AMM output ## For Full period: dates=NULL + +amm.residual <- AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], verbose=FALSE, dates= NULL, market.returns=nifty.index, others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=0) -amm.output <- -AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], +amm.output <- AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], verbose=FALSE, dates= NULL, market.returns=nifty.index, others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) @@ -266,11 +282,17 @@ event unit and time, \textit{SplitDates}, and the width for creating the event-frame. -<<>>= es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, -width=10) str(es) es$outcomes es.w <- window(es$z.e, start=-10, -end=10) colnames(es.w) <- -SplitDates[which(es$outcomes=="success"),1] SplitDates[1,] -StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] es.w[,1] @ +<<>>= +es <- phys2eventtime(z=StockPriceReturns, events=SplitDates, +width=10) +str(es) +es$outcomes +es.w <- window(es$z.e, start=-10,end=10) +colnames(es.w) <- SplitDates[which(es$outcomes=="success"),1] +SplitDates[1,] +StockPriceReturns[SplitDates[1,2],SplitDates[1,1]] +es.w[,1] +@ The output for \texttt{phys2eventtime} is a list. The first element of a list is a time series object which is converted to @@ -293,7 +315,10 @@ \texttt{remap.cumsum} function is used to convert the returns to cumulative returns. -<<>>= es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) es.cs[,1] @ +<<>>= +es.cs <- remap.cumsum(es.w,is.pc=FALSE,base=0) +es.cs[,1] +@ \subsection{Inference procedures} \subsubsection{Bootstrap inference} @@ -311,7 +336,10 @@ confidence interval at 2.5 percent and 97.5 percent for the estimate. -<<>>= result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) @ +<<>>= +result <- inference.bootstrap(es.w=es.cs, to.plot=TRUE) +@ + \begin{figure}[t] \begin{center} \caption{Stock splits event and response of respective stock @@ -344,20 +372,21 @@ functions. Several examples of the use of this function are provided below. -<<>>= ## Event study without adjustment es.na <- -eventstudy(firm.returns = StockPriceReturns, eventList = +<<>>= ## Event study without adjustment +es.na <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = TRUE, inference = TRUE, inference.strategy = "wilcoxon", type = "None") -## Event study using market residual and bootstrap es.mm <- -eventstudy(firm.returns = StockPriceReturns, eventList = +## Event study using market residual and bootstrap +es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = FALSE, inference = TRUE, inference.strategy = "bootstrap", type -= "marketResidual", market.returns = nifty.index) es.mm += "marketResidual", market.returns = nifty.index) +es.mm -## Event study using excess return and bootstrap es.er <- -eventstudy(firm.returns = StockPriceReturns, eventList = +## Event study using excess return and bootstrap +es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot = FALSE, inference = TRUE, inference.strategy = "bootstrap", type = "excessReturn", market.returns = nifty.index) From noreply at r-forge.r-project.org Mon Aug 19 19:46:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 19 Aug 2013 19:46:02 +0200 (CEST) Subject: [Eventstudies-commits] r136 - in pkg: R man vignettes Message-ID: <20130819174602.71D39184DB1@r-forge.r-project.org> Author: vikram Date: 2013-08-19 19:46:02 +0200 (Mon, 19 Aug 2013) New Revision: 136 Modified: pkg/R/AMM.R pkg/man/AMM.Rd pkg/vignettes/eventstudies.Rnw Log: Modified AMM function; Work in progress Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-19 09:26:48 UTC (rev 135) +++ pkg/R/AMM.R 2013-08-19 17:46:02 UTC (rev 136) @@ -1,3 +1,6 @@ +########################### +## Event study AMM function +########################### ########################## # Generalised AMM function ########################## @@ -2,14 +5,4 @@ -AMM <- function(amm.type = NULL, ...) { +AMM <- function(...) { - ## List of models currently supported - modelsList <- c("all","residual","firmExposures") - - if (is.null(amm.type) || length(amm.type) != 1) { - stop("Argument amm.type not provided or incorrect") - } - if (match(amm.type, modelsList, nomatch = -1) == -1) { - stop("Unknown model provided") - } - # NULLify all the values before use @@ -57,66 +50,22 @@ } ## Assign values - - ##---- - ## AMM - ##---- - if(amm.type == "residual") { - ## One firm - if(NCOL(firm.returns)==1){ + ## One firm + if(NCOL(firm.returns)==1){ # Checking required arguments - if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { - stop("Input firm.returns (firm data) is missing") - } - - X <- makeX(market.returns, others, switch.to.innov, - market.returns.purge, nlags, dates, verbose) - result <- onefirmAMM(firm.returns, X, nlags, verbose, dates) - result <- result$residuals - } - - ## Many firms - if(NCOL(firm.returns)>1){ - # Checking required arguments if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { stop("Input firm.returns (firm data) is missing") } - if(NCOL(firm.returns)<2){ - stop("Less than two firms in inputData") - } X <- makeX(market.returns, others, switch.to.innov, market.returns.purge, nlags, dates, verbose) - tmp.result <- onefirmAMM(firm.returns[,1], X, nlags, verbose, dates) - result <- tmp.result$residuals - for(i in 2:NCOL(firm.returns)){ - tmp <- onefirmAMM(firm.returns[,i], X, nlags, verbose, dates) - result <- merge(result,tmp$residuals) - } - colnames(result) <- colnames(firm.returns) - } - index(result) <- as.Date(index(result)) + result <- onefirmAMM(firm.returns, X, nlags, verbose, dates) + result <- result$residuals } - - ##---- - ## All - ##---- - if(amm.type == "all") { - ## One firm - if(NCOL(firm.returns)==1){ - # Checking required arguments - if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { - stop("Input firm.returns (firm data) is missing") - } - - X <- makeX(market.returns, others, switch.to.innov, - market.returns.purge, nlags, dates, verbose) - result <- onefirmAMM(firm.returns, X, nlags, verbose, dates) - } - ## Many firms - if(NCOL(firm.returns)>1){ - # Checking required arguments + ## Many firms + if(NCOL(firm.returns)>1){ + # Checking required arguments if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { stop("Input firm.returns (firm data) is missing") } @@ -126,30 +75,16 @@ X <- makeX(market.returns, others, switch.to.innov, market.returns.purge, nlags, dates, verbose) - result <- list() - for(i in 1:NCOL(firm.returns)){ + tmp.result <- onefirmAMM(firm.returns[,1], X, nlags, verbose, dates) + result <- tmp.result$residuals + for(i in 2:NCOL(firm.returns)){ tmp <- onefirmAMM(firm.returns[,i], X, nlags, verbose, dates) - result[[i]] <- tmp + result <- merge(result,tmp$residuals) } - names(result) <- colnames(firm.returns) - } + colnames(result) <- colnames(firm.returns) } + index(result) <- as.Date(index(result)) - ##--------------- - ## Firm exposures - ##--------------- - if (amm.type=="firmExposures") { - # Checking required arguments - if (match("firm.returns", names(modelArgs), nomatch = -1) == -1) { - stop("Input firm.returns (firm data) is missing") - } - - X <- makeX(market.returns, others, switch.to.innov, - market.returns.purge, nlags, dates, verbose) - - result <- firmExposures(firm.returns, X, nlags, verbose) - } - return(result) } Modified: pkg/man/AMM.Rd =================================================================== --- pkg/man/AMM.Rd 2013-08-19 09:26:48 UTC (rev 135) +++ pkg/man/AMM.Rd 2013-08-19 17:46:02 UTC (rev 136) @@ -3,30 +3,16 @@ \title{A function that estimates exposure for a single firm over multiple periods} -\description{This function does three tasks: One firm AMM model, many firms AMM model and firm exposures. One should refer to the individual functions manual for arguments. -} +\description{This function computes AMM residuals} \usage{ -AMM(amm.type=NULL, ...) +AMM(...) } \arguments{ - \item{amm.type}{If amm.type take following inputs: all, residual and firmExposures. If amm.type is residual it gives only AMM residual as output, if amm.type is firmExposures then it gives only firm exposure as output else if all output is needed then option all is used.} \item{...}{Accepts specific arguments for the model.} } -\value{The function returns the exposures, HAC adjusted standard - errors, the number of lags used, and the residuals from the fitted - model. Default is NULL. - -\item{exposures}{This contains the exposure estimates for the firm -j} - -\item{s.exposures}{This contains the HAC adjusted standard error -of the exposures estimated for the firm rj.} - -\item{nlags}{Specifies the lag length provided by the user} - -\item{lm.res}{The model estimates used in the analysis are stored here.} +\value{ This function computes AMM residual using onefirmAMM function. } \author{Vikram Bahure} @@ -45,10 +31,8 @@ regressand <- cbind(Company_A,Company_B,Company_C) ## One firm -of <- AMM(amm.type="residual",firm.returns=Company_A, - verbose=TRUE, - dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06", - "2008-01-05","2009-01-03")), +of <- AMM(firm.returns=Company_A, + verbose=FALSE, market.returns=NIFTY_INDEX, others=INRUSD, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) } Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-19 09:26:48 UTC (rev 135) +++ pkg/vignettes/eventstudies.Rnw 2013-08-19 17:46:02 UTC (rev 136) @@ -11,9 +11,10 @@ \author{Vikram Bahure and Renuka Sane and Ajay Shah\thanks{We thank Chirag Anand for valuable inputs in the creation of this vignette.}} \begin{document} -% \VignetteIndexEntry{eventstudies: A package with functionality -% to do Event Studies} \VignetteDepends{} \VignetteKeywords{event -% studies} \VignettePackage{eventstudies} +% \VignetteIndexEntry{eventstudies: A package with functionality to do Event Studies} +% \VignetteDepends{} +% \VignetteKeywords{eventstudies} +% \VignettePackage{eventstudies} \maketitle \begin{abstract} @@ -194,7 +195,8 @@ data(StockPriceReturns) data(nifty.index) str(StockPriceReturns) -head(StockPriceReturns) +## head(StockPriceReturns) +head(StockPriceReturns[rowSums(is.na((StockPriceReturns)))==3,1:3]) head(nifty.index) @ @@ -260,16 +262,17 @@ ## AMM output ## For Full period: dates=NULL -amm.residual <- AMM(amm.type="residual",firm.returns=StockPriceReturns[,1:3], -verbose=FALSE, dates= NULL, market.returns=nifty.index, -others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, -nlags=0) +amm.residual <- AMM(firm.returns=StockPriceReturns[,1:3], + verbose=FALSE, market.returns=nifty.index, + others=inrusd, switch.to.innov=TRUE, + market.returns.purge=TRUE, nlags=0) -amm.output <- AMM(amm.type="all",firm.returns=StockPriceReturns[,1:3], -verbose=FALSE, dates= NULL, market.returns=nifty.index, -others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, -nlags=1) +amm.output <- AMM(firm.returns=StockPriceReturns[,1:3], + verbose=FALSE, market.returns=nifty.index, + others=inrusd, switch.to.innov=TRUE, + market.returns.purge=TRUE,nlags=1) + @ \subsection{Conversion to event frame} @@ -354,7 +357,9 @@ \subsubsection{Wilcoxon signed rank test} We next compute the Wilcoxon signed rank test, which is a non-parametric inference test to compute the confidence interval. -<<>>= result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) @ +<<>>= +result <- inference.wilcox(es.w=es.cs, to.plot=TRUE) +@ \begin{figure}[t] \begin{center} \caption{Stock splits event and response of respective stock @@ -372,32 +377,38 @@ functions. Several examples of the use of this function are provided below. -<<>>= ## Event study without adjustment +<<>>= +## Event study without adjustment es.na <- eventstudy(firm.returns = StockPriceReturns, eventList = -SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot -= TRUE, inference = TRUE, inference.strategy = "wilcoxon", type = -"None") + SplitDates, width = 10, to.remap = TRUE, + remap = "cumsum", + to.plot = TRUE, inference = TRUE, + inference.strategy = "wilcoxon", type = "None") + ## Event study using market residual and bootstrap -es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = -SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot -= FALSE, inference = TRUE, inference.strategy = "bootstrap", type -= "marketResidual", market.returns = nifty.index) +es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, + width = 10, to.remap = TRUE, remap = "cumsum", + to.plot = FALSE, inference = TRUE, + inference.strategy = "bootstrap", + type = "marketResidual", market.returns = nifty.index) es.mm ## Event study using excess return and bootstrap -es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = -SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot -= FALSE, inference = TRUE, inference.strategy = "bootstrap", type -= "excessReturn", market.returns = nifty.index) +es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, + width = 10, to.remap = TRUE, remap = "cumsum", + to.plot = FALSE, inference = TRUE, + inference.strategy = "bootstrap", type = "excessReturn", + market.returns = nifty.index) ## Event study using augmented market model (AMM) and bootstrap -es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = -SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", to.plot -= FALSE, inference = TRUE, inference.strategy = "bootstrap", type -= "AMM", market.returns = nifty.index, others=inrusd, -verbose=FALSE, dates= NULL, switch.to.innov=TRUE, -market.returns.purge=TRUE, nlags=1) +es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, + width = 10, to.remap = TRUE, remap = "cumsum", + to.plot = FALSE, inference = TRUE, + inference.strategy = "bootstrap", + type = "AMM", market.returns = nifty.index, + others=inrusd, verbose=FALSE, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) @ From noreply at r-forge.r-project.org Tue Aug 20 19:56:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 20 Aug 2013 19:56:27 +0200 (CEST) Subject: [Eventstudies-commits] r137 - in pkg: R vignettes Message-ID: <20130820175627.63712184BCC@r-forge.r-project.org> Author: vikram Date: 2013-08-20 19:56:27 +0200 (Tue, 20 Aug 2013) New Revision: 137 Modified: pkg/R/AMM.R pkg/vignettes/eventstudies.Rnw Log: Modified AMM function to handle when there are all NAs in some firm Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-19 17:46:02 UTC (rev 136) +++ pkg/R/AMM.R 2013-08-20 17:56:27 UTC (rev 137) @@ -77,12 +77,28 @@ market.returns.purge, nlags, dates, verbose) tmp.result <- onefirmAMM(firm.returns[,1], X, nlags, verbose, dates) result <- tmp.result$residuals + remove.columns <- NULL for(i in 2:NCOL(firm.returns)){ + cat("Computing AMM residuals for", + colnames(firm.returns)[i],"and", "column no.",i,"\n") + ## Checking number of observations tmp <- onefirmAMM(firm.returns[,i], X, nlags, verbose, dates) + if(is.null(tmp)){ + remove.columns <- c(remove.columns,colnames(firm.returns)[i]) + next("Cannot compute AMM residuals due to less observations") + } result <- merge(result,tmp$residuals) } - colnames(result) <- colnames(firm.returns) + ## Removing columns with less obs + if(is.null(remove.columns)!=TRUE){ + cn.names <- colnames(firm.returns)[-which(colnames(firm.returns)%in%remove.columns)] + cat(length(remove.columns), "columns removed:",remove.columns,"\n") + } else { + cn.names <- colnames(firm.returns) + } + colnames(result) <- cn.names } + index(result) <- as.Date(index(result)) return(result) @@ -106,11 +122,16 @@ ## Getting firm exposure, amm residuals if(is.null(dates)){ res <- firmExposures(firm.returns,X,verbose=verbose,nlags=nlags) - exposures <- res$exposure - sds <- res$s.exposure - m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) - if(residual==TRUE){ + if(is.null(res)!=TRUE){ + exposures <- res$exposure + sds <- res$s.exposure m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) + if(residual==TRUE){ + m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names"))) + } + rval <- list(exposures=exposures,sds=sds,residuals=m.residuals) + } else { + rval <- NULL } }else{ tmp <- window(firm.returns,start=dates[1],end=dates[1+1]) @@ -139,8 +160,8 @@ m.residuals <- merge(m.residuals, period.resid, all=TRUE) } rownames(exposures) <- rownames(sds) <- periodnames - } - rval <- list(exposures=exposures,sds=sds,residuals=m.residuals) + rval <- list(exposures=exposures,sds=sds,residuals=m.residuals) + } return(rval) } @@ -496,3 +517,4 @@ } } } + Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2013-08-19 17:46:02 UTC (rev 136) +++ pkg/vignettes/eventstudies.Rnw 2013-08-20 17:56:27 UTC (rev 137) @@ -260,19 +260,12 @@ nifty.index <- all.data$nifty.index inrusd <- all.data$inr -## AMM output ## For Full period: dates=NULL - +## AMM output ## amm.residual <- AMM(firm.returns=StockPriceReturns[,1:3], verbose=FALSE, market.returns=nifty.index, others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=0) - -amm.output <- AMM(firm.returns=StockPriceReturns[,1:3], - verbose=FALSE, market.returns=nifty.index, - others=inrusd, switch.to.innov=TRUE, - market.returns.purge=TRUE,nlags=1) - @ \subsection{Conversion to event frame} From noreply at r-forge.r-project.org Sat Aug 24 00:07:19 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 24 Aug 2013 00:07:19 +0200 (CEST) Subject: [Eventstudies-commits] r138 - pkg/R Message-ID: <20130823220720.121D91856F6@r-forge.r-project.org> Author: chiraganand Date: 2013-08-24 00:07:19 +0200 (Sat, 24 Aug 2013) New Revision: 138 Modified: pkg/R/AMM.R pkg/R/eventstudy.R Log: Fixed non-loading of AMM() argument in the environment, changed the evaluation process, more clean now. Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-20 17:56:27 UTC (rev 137) +++ pkg/R/AMM.R 2013-08-23 22:07:19 UTC (rev 138) @@ -7,22 +7,12 @@ AMM <- function(...) { - # NULLify all the values before use - firm.returns <- NULL - market.returns <- NULL - market.returns.purge <- NULL - nlags <- NULL - others <- NULL - switch.to.innov <- NULL - verbose <- NULL - dates <- NULL - - # parse the input arguments for the model + # extract the arguments for + # the model and load into the + # current (function's) + # environment modelArgs <- list(...) - # assign values - for (i in 1:length(modelArgs)) { - eval(parse(text = paste(names(modelArgs)[i], "<-", "modelArgs[[i]]"))) - } + list2env(list(...), envir = environment()) # Checking required arguments if (match("market.returns", names(modelArgs), nomatch = -1) == -1) { Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-20 17:56:27 UTC (rev 137) +++ pkg/R/eventstudy.R 2013-08-23 22:07:19 UTC (rev 138) @@ -25,7 +25,7 @@ ## AMM if (type == "AMM") { amm.type <- "residual" - tmp.outputModel <- AMM(amm.type, firm.returns = firm.returns, ...) + tmp.outputModel <- AMM(amm.type = amm.type, firm.returns = firm.returns, ...) outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } From noreply at r-forge.r-project.org Sat Aug 24 17:39:20 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 24 Aug 2013 17:39:20 +0200 (CEST) Subject: [Eventstudies-commits] r139 - pkg/R Message-ID: <20130824153920.CB554184F68@r-forge.r-project.org> Author: vikram Date: 2013-08-24 17:39:20 +0200 (Sat, 24 Aug 2013) New Revision: 139 Modified: pkg/R/eventstudy.R Log: Changed the AMM argument in eventstudy funciton Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2013-08-23 22:07:19 UTC (rev 138) +++ pkg/R/eventstudy.R 2013-08-24 15:39:20 UTC (rev 139) @@ -24,8 +24,7 @@ ### Run models ## AMM if (type == "AMM") { - amm.type <- "residual" - tmp.outputModel <- AMM(amm.type = amm.type, firm.returns = firm.returns, ...) + tmp.outputModel <- AMM(firm.returns = firm.returns, ...) outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel)) } From noreply at r-forge.r-project.org Sun Aug 25 00:48:17 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 25 Aug 2013 00:48:17 +0200 (CEST) Subject: [Eventstudies-commits] r140 - pkg/R Message-ID: <20130824224817.8CE6B183EBB@r-forge.r-project.org> Author: chiraganand Date: 2013-08-25 00:48:14 +0200 (Sun, 25 Aug 2013) New Revision: 140 Modified: pkg/R/AMM.R Log: Fixed global variables, defined them in the function environment itself. Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-24 15:39:20 UTC (rev 139) +++ pkg/R/AMM.R 2013-08-24 22:48:14 UTC (rev 140) @@ -6,15 +6,19 @@ ########################## AMM <- function(...) { - + firm.returns <- NULL + market.returns <- NULL + others <- NULL + switch.to.innov <- NULL + market.returns.purge <- NULL # extract the arguments for # the model and load into the # current (function's) # environment modelArgs <- list(...) - list2env(list(...), envir = environment()) + list2env(list(...)) - # Checking required arguments + # Checking required arguments if (match("market.returns", names(modelArgs), nomatch = -1) == -1) { stop("Input market.returns (stock market index) is missing") } From noreply at r-forge.r-project.org Mon Aug 26 20:55:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 26 Aug 2013 20:55:33 +0200 (CEST) Subject: [Eventstudies-commits] r141 - pkg/R Message-ID: <20130826185533.66DB01853D9@r-forge.r-project.org> Author: chiraganand Date: 2013-08-26 20:55:33 +0200 (Mon, 26 Aug 2013) New Revision: 141 Modified: pkg/R/AMM.R Log: Fixed verbose argument error, handling arguments directly using list now. Modified: pkg/R/AMM.R =================================================================== --- pkg/R/AMM.R 2013-08-24 22:48:14 UTC (rev 140) +++ pkg/R/AMM.R 2013-08-26 18:55:33 UTC (rev 141) @@ -6,17 +6,8 @@ ########################## AMM <- function(...) { - firm.returns <- NULL - market.returns <- NULL - others <- NULL - switch.to.innov <- NULL - market.returns.purge <- NULL - # extract the arguments for - # the model and load into the - # current (function's) - # environment + modelArgs <- list(...) - list2env(list(...)) # Checking required arguments if (match("market.returns", names(modelArgs), nomatch = -1) == -1) { @@ -31,19 +22,30 @@ if (match("switch.to.innov", names(modelArgs), nomatch = -1) == -1) { stop("Input switch.to.innov is missing") } - + + firm.returns <- modelArgs$firm.returns + market.returns <- modelArgs$market.returns + others <- modelArgs$others + switch.to.innov <- modelArgs$switch.to.innov + market.returns.purge <- modelArgs$market.returns.purge + # Checking remaining arguments if (match("nlags", names(modelArgs), nomatch = -1) == -1) { nlags <- 1 + } else { + nlags <- modelArgs$nlags } if (match("verbose", names(modelArgs), nomatch = -1) == -1) { verbose <- FALSE + } else { + verbose <- modelArgs$verbose } if (match("dates", names(modelArgs), nomatch = -1) == -1) { dates <- NULL + } else { + dates <- modelArgs$dates } - - ## Assign values + ## One firm if(NCOL(firm.returns)==1){ # Checking required arguments