[Eventstudies-commits] r120 - in pkg: R data man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 8 13:42:17 CEST 2013


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



More information about the Eventstudies-commits mailing list