[Eventstudies-commits] r169 - in pkg: R vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 13 15:45:45 CET 2014


Author: vikram
Date: 2014-02-13 15:45:45 +0100 (Thu, 13 Feb 2014)
New Revision: 169

Modified:
   pkg/R/eventstudy.R
   pkg/vignettes/eventstudies.Rnw
Log:
Modified eventstudy function; Work in progress

Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R	2014-02-13 11:53:23 UTC (rev 168)
+++ pkg/R/eventstudy.R	2014-02-13 14:45:45 UTC (rev 169)
@@ -24,8 +24,25 @@
 ### Run models
   ## AMM
   if (type == "AMM") {
-    tmp.outputModel <- AMM(firm.returns = firm.returns, ...)
-    outputModel <- zoo(coredata(tmp.outputModel),index(tmp.outputModel))
+    ## AMM residual to time series
+    timeseriesAMM <- function(firm.returns,X,verbose=FALSE,nlags=1){
+      tmp <- resid(lmAMM(firm.returns,X,nlags))
+      tmp.res <- zoo(tmp,as.Date(names(tmp)))
+    }    
+    if(NCOL(firm.returns)==1){
+      ## One firm
+      outputModel <- timeseriesAMM(firm.returns=StockPriceReturns[,1], 
+                                   X=regressors, verbose=FALSE, nlags=1)
+    } else {
+      ## More than one firm
+                                        # Extracting and merging
+      tmp.resid <- sapply(colnames(StockPriceReturns)[1:3],function(y)
+                          timeseriesAMM(firm.returns=StockPriceReturns[,y],
+                                        X=regressors,
+                                        verbose=FALSE,
+                                        nlags=1))
+      outputModel <- do.call("merge",tmp.resid)
+    }    
   }
 
   ## marketResidual
@@ -82,6 +99,27 @@
     ## Providing event frame as default output
     result <- es.w
   }
-    
-  return(list(result, es$outcomes))
+    final.result <- list(eventstudy.output=result,
+                         outcomes=as.character(es$outcomes),
+                         inference=inference.strategy, nlags=nlags)
+  class(final.result) <- "es"
+  return(final.result)
 }
+
+#########################
+## Functions for class es
+#########################
+print.es <- function(){
+
+
+}
+
+summary.es <- function(){
+
+
+}
+
+plot.es <- function(){
+
+
+}

Modified: pkg/vignettes/eventstudies.Rnw
===================================================================
--- pkg/vignettes/eventstudies.Rnw	2014-02-13 11:53:23 UTC (rev 168)
+++ pkg/vignettes/eventstudies.Rnw	2014-02-13 14:45:45 UTC (rev 169)
@@ -203,17 +203,37 @@
 regression appropriately.
 
 % AMM model
-<<>>= # Create RHS before running AMM() 
+<<>>= # Create RHS before running lmAMM() 
 data(inr) 
-inrusd <- diff(log(inr))*100 
+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 ## 
-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=1)
+###################
+## AMM residuals ##
+###################
+## Getting Regressors
+regressors <- makeX(market.returns=nifty.index, others=inrusd, 
+                    market.returns.purge=TRUE, nlags=1)
+## AMM residual to time series
+timeseriesAMM <- function(firm.returns,X,verbose=FALSE,nlags=1){
+  tmp <- resid(lmAMM(firm.returns,X,nlags))
+  tmp.res <- zoo(tmp,as.Date(names(tmp)))
+}
+## One firm
+amm.result <- timeseriesAMM(firm.returns=StockPriceReturns[,1], 
+                            X=regressors, verbose=FALSE, nlags=1)
 
+## More than one firm
+                                        # Extracting and merging
+tmp.resid <- sapply(colnames(StockPriceReturns)[1:3],function(y)
+                    timeseriesAMM(firm.returns=StockPriceReturns[,y],
+                                  X=regressors,
+                                  verbose=FALSE,
+                                  nlags=1))
+amm.resid <- do.call("merge",tmp.resid)
 @
 
 \subsection{Conversion to event-time frame}



More information about the Eventstudies-commits mailing list