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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 19 19:46:02 CEST 2013


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)
 
 @
 



More information about the Eventstudies-commits mailing list