[Eventstudies-commits] r81 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 16 08:05:54 CEST 2013


Author: vimsaa
Date: 2013-07-16 08:05:54 +0200 (Tue, 16 Jul 2013)
New Revision: 81

Modified:
   pkg/R/AMM.R
Log:
Modified onefirmAMM

Modified: pkg/R/AMM.R
===================================================================
--- pkg/R/AMM.R	2013-07-16 05:53:26 UTC (rev 80)
+++ pkg/R/AMM.R	2013-07-16 06:05:54 UTC (rev 81)
@@ -117,16 +117,18 @@
 #######################
 # AMM for one firm
 #######################
-onefirmAMM <- function(rj,X,nlags=NA,verbose=FALSE,dates=NULL){
+onefirmAMM <- function(rj,X,nlags=NA,verbose=FALSE,dates=NULL,residual=FALSE){
   exposures <- data.frame(matrix(NA,ncol=ncol(X),nrow=(length(dates)-1)))
   colnames(exposures) <- colnames(X)
   sds <- exposures
   periodnames <- NULL
-  
+  m.residuals <- NULL
   if(is.null(dates)){
    res <- firmExposures(rj,X,verbose=verbose,nlags=nlags)
    exposures <- res$exposure
    sds <- res$s.exposure
+   if(residual==TRUE)
+     m.residuals <- res$residuals
  }else{
    for(i in 1:(length(dates)-1)){
      tmp <- window(rj,start=dates[i],end=dates[i+1])
@@ -138,10 +140,11 @@
      exposures[i,] <- res$exposure
      periodnames <- c(periodnames,paste(dates[i],dates[i+1],sep=" TO "))
      sds[i,] <- res$s.exposure
+     m.residuals <- merge(m.residuals,res$residuals,all=TRUE)
    }
    rownames(exposures) <- rownames(sds) <- periodnames
  }
-  rval <- list(exposures=exposures,sds=sds)
+  rval <- list(exposures=exposures,sds=sds,residuals=m.residuals)
   return(rval)
 }
 
@@ -267,8 +270,9 @@
       s.exposures <- c(s.exposures, sqrt(w %*% Sigma %*% w))
     }
   }
+  residuals <- m$resid
   names(exposures) <- names(s.exposures) <- colnames(X)
-  results <- list(exposures=exposures,
+  results <- list(exposures=exposures,residuals=residuals,
                   s.exposures=s.exposures, nlags=nlags,
                   lm.res=m)
   class(results) <- "amm"



More information about the Eventstudies-commits mailing list