[Eventstudies-commits] r113 - in pkg: R man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 6 10:58:43 CEST 2013


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,



More information about the Eventstudies-commits mailing list