[Eventstudies-commits] r165 - in pkg: R man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Feb 13 10:52:45 CET 2014
Author: vikram
Date: 2014-02-13 10:52:44 +0100 (Thu, 13 Feb 2014)
New Revision: 165
Added:
pkg/man/subperiodmanyfirms.lmAMM.Rd
Removed:
pkg/man/manyfirmsAMM.Rd
pkg/man/y3c3.Rd
Modified:
pkg/R/lmAmm.R
pkg/man/lmAMM.Rd
pkg/man/makeX.Rd
pkg/man/onefirmAMM.Rd
pkg/vignettes/amm.Rnw
Log:
Renamed and rewrote AMM functions, changed the structure of AMM functions; added new data for AMM examples and separate for eventstudies examples
Modified: pkg/R/lmAmm.R
===================================================================
--- pkg/R/lmAmm.R 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/R/lmAmm.R 2014-02-13 09:52:44 UTC (rev 165)
@@ -1,9 +1,70 @@
+###############
+## One firm AMM
+###############
+## This function takes care of the structural break dates introduced by calculating exposure for sub periods differently
+## This function is used when date are provided in the function
+subperiod.lmAMM <- function(firm.returns,X,nlags=1,verbose=FALSE,dates=NULL,residual=TRUE){
+ ## Creating empty frames
+ if(is.null(dates)){
+ dates.no <- c(start(firm.returns),end(firm.returns))
+ } else{
+ dates.no <- dates
+ }
+ exposures <- data.frame(matrix(NA,ncol=ncol(X),nrow=(length(dates.no)-1)))
+ colnames(exposures) <- colnames(X)
+ sds <- exposures
+ periodnames <- NULL
+
+ ## Getting firm exposure, amm residuals
+ if(is.null(dates)){
+ res <- lmAMM(firm.returns,X,verbose=verbose,nlags=nlags)
+ if(is.null(res)!=TRUE){
+ exposures <- res$exposure
+ sds <- res$s.exposure
+ m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names")))
+ if(residual==TRUE){
+ m.residuals <- xts(res$residuals,as.Date(attr(res$residuals,"names")))
+ }
+ rval <- list(exposures=exposures,sds=sds,residuals=m.residuals)
+ } else {
+ rval <- NULL
+ }
+ }else{
+ tmp <- window(firm.returns,start=dates[1],end=dates[1+1])
+ rhs <- window(X,start=dates[1],end=dates[1+1])
+ res <- lmAMM(firm.returns=tmp,
+ X=rhs,
+ verbose=verbose,
+ nlags=nlags)
+ exposures[1,] <- res$exposure
+ periodnames <- c(periodnames,paste(dates[1],dates[1+1],sep=" TO "))
+ sds[1,] <- res$s.exposure
+ 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(firm.returns,start=dates[i],end=dates[i+1])
+ rhs <- window(X,start=dates[i],end=dates[i+1])
+ res <- lmAMM(firm.returns=tmp,
+ X=rhs,
+ verbose=verbose,
+ nlags=nlags)
+ exposures[i,] <- res$exposure
+ periodnames <- c(periodnames,paste(dates[i],dates[i+1],sep=" TO "))
+ sds[i,] <- res$s.exposure
+ period.resid <- xts(res$residuals,as.Date(attr(res$residuals,"names")))
+ colnames(period.resid) <- paste(dates[i],"to",dates[i+1],sep=".")
+ m.residuals <- merge(m.residuals, period.resid, all=TRUE)
+ }
+ rownames(exposures) <- rownames(sds) <- periodnames
+ rval <- list(exposures=exposures,sds=sds,residuals=m.residuals)
+ }
+ return(rval)
+}
-
########################
# Many firms AMM
########################
-manyfirmsAMM <-
+subperiodmanyfirms.lmAMM <-
function(regressand,regressors,
lags,dates=NULL, periodnames=NULL,verbose=FALSE){
require("doMC")
Modified: pkg/man/lmAMM.Rd
===================================================================
--- pkg/man/lmAMM.Rd 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/man/lmAMM.Rd 2014-02-13 09:52:44 UTC (rev 165)
@@ -55,7 +55,7 @@
\examples{
# lmAMM
data("lmAMMData")
-firm.returns <- lmAMMData[,c("Infosys")]
+firm.returns <- lmAMMData[,"Infosys"]
market.returns <- lmAMMData[,"index.nifty"]
currency.returns <- lmAMMData[,"currency.inrusd"]
## Creating regressors for AMM estimation using makeX function
Modified: pkg/man/makeX.Rd
===================================================================
--- pkg/man/makeX.Rd 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/man/makeX.Rd 2014-02-13 09:52:44 UTC (rev 165)
@@ -1,7 +1,7 @@
\name{makeX}
\alias{makeX}
\title{A function to prepare explanatory variables for computation
-of Augmented Market Models
+of Augmented Market Models used in lmAMM function
}
\description{
@@ -63,11 +63,9 @@
\examples{
# makeX
-data("firmExposuresData")
-firm.returns <- firmExposuresData$Company_A
-market.returns <- firmExposuresData$NIFTY_INDEX
-rM2 <- firmExposuresData$usdinr
-rM3 <- firmExposuresData$baa
+data("lmAMMData")
+market.returns <- lmAMMData$index.nifty
+rM2 <- lmAMMData$currency.inrusd
X <- makeX(market.returns, others=rM2,
switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE)
}
Deleted: pkg/man/manyfirmsAMM.Rd
===================================================================
--- pkg/man/manyfirmsAMM.Rd 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/man/manyfirmsAMM.Rd 2014-02-13 09:52:44 UTC (rev 165)
@@ -1,62 +0,0 @@
-\name{manyfirmsAMM}
-\alias{manyfirmsAMM}
-
-\title{A function to compute AMM for multiple firms across several
-periods}
-
-\description{
- This function will compute AMM for multiple firms at once using the
- matrix of data obtained from \code{makeX}, and a matrix of LHS variables}
-
-\usage{
-manyfirmsAMM(regressand, regressors, lags, dates = NULL, periodnames = NULL, verbose = FALSE)
-}
-
-\arguments{
- \item{regressand}{A zoo matrix of all firms for which AMM is to
- be computed}
-
- \item{regressors}{A zoo matrix containing at least two
- regressors generally obtained after applying the makeX function }
-
- \item{lags}{ Specifies the number of lags to be used in the
- market model}
-
- \item{dates}{A set of dates that mark out subperiods of
- interest. If dates is NULL then full period is considered.}
-
- \item{periodnames}{Name for each subperiod that has been marked
- by the dates above.}
-
- \item{verbose}{Whether detailed print while running this
- function is required}
-}
-
-\section{Warning}{Do not have any space between names provided under 'periodnames'}
-
-\author{Ajay Shah, Vimal Balasubramaniam}
-
-\seealso{
-\code{\link{onefirmAMM}}
-}
-
-\examples{
-# Running manyfirmsAMM() involves as many steps as working with onefirmAMM.
-data("lmAMMData")
-regressand <- lmAMMData[,c("Infosys","TCS")]
-market.returns <- lmAMMData[,"index.nifty"]
-currency.returns <- lmAMMData[,"currency.inrusd"]
-## Creating regressors for AMM estimation using makeX function
-regressors <- makeX(market.returns, others=currency.returns,, nlags=1,
- switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE,
- dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06",
- "2008-01-05","2009-01-03")))
-## Estimating exposure
-res <- manyfirmsAMM(regressand,regressors,lags=1,
- dates=as.Date(c("2005-01-15","2006-01-07","2007-01-06",
- "2008-01-05","2009-01-03")),periodnames=c("P1","P2","P3","P4"),
- verbose=FALSE)
-print(res)
-}
-
-\keyword{manyfirmsAMM}
\ No newline at end of file
Modified: pkg/man/onefirmAMM.Rd
===================================================================
--- pkg/man/onefirmAMM.Rd 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/man/onefirmAMM.Rd 2014-02-13 09:52:44 UTC (rev 165)
@@ -1,5 +1,5 @@
-\name{onefirmAMM}
-\alias{onefirmAMM}
+\name{subperiod.lmAMM}
+\alias{subperiod.lmAMM}
\title{A function that estimates exposure for a single firm over multiple periods}
@@ -10,7 +10,7 @@
}
\usage{
-onefirmAMM(firm.returns, X, nlags = 1, verbose = FALSE, dates = NULL, residual = TRUE)
+subperiod.lmAMM(firm.returns, X, nlags = 1, verbose = FALSE, dates = NULL, residual = TRUE)
}
\arguments{
@@ -27,7 +27,7 @@
\item{verbose}{Default is FALSE. When set to TRUE, the function
prints detailed results of using the function.
}
- \item{dates}{Default is NULL. If no dates are mentioned, onefirmAMM does
+ \item{dates}{Default is NULL. If no dates are mentioned, subperiod.lmAMM does
what firmExposures() would do, i.e., estimate exposures for the full time period.
}
\item{residual}{Returns AMM Residuals if TRUE, AMM exposure
@@ -43,23 +43,20 @@
\code{\link{manyfirmsAMM}}}
\examples{
-# Create RHS before running onefirmAMM()
-data("y3c3")
-NIFTY_INDEX <- y3c3$NIFTY_INDEX
-INRUSD <- y3c3$INRUSD
-Company_A <- y3c3$Company_A
-rhs.dat <- makeX(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)
-
+# Create RHS before running subperiod.lmAMM()
+data("lmAMMData")
+firm.returns <- lmAMMData$Infosys
+market.returns <- lmAMMData$index.nifty
+currency.returns <- lmAMMData$currency.inrusd
+regressors <- makeX(market.returns, others=currency.returns,
+ switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1,
+ dates=as.Date(c("2012-02-01","2013-01-01","2014-01-31")), verbose=FALSE)
# Run AMM for one firm across different periods
-onefirmAMM(firm.returns=Company_A,
- X=rhs.dat,
- nlags=1,
- verbose=TRUE,
- dates= as.Date(c("2005-01-15","2006-01-07","2007-01-06",
- "2008-01-05","2009-01-03")))
+res <- subperiod.lmAMM(firm.returns,
+ X=regressors,
+ nlags=1,
+ verbose=TRUE,
+ dates= as.Date(c("2012-02-01","2013-01-01","2014-01-31")))
}
-\keyword{onefirmAMM}
\ No newline at end of file
+\keyword{subperiod.lmAMM}
\ No newline at end of file
Copied: pkg/man/subperiodmanyfirms.lmAMM.Rd (from rev 164, pkg/man/manyfirmsAMM.Rd)
===================================================================
--- pkg/man/subperiodmanyfirms.lmAMM.Rd (rev 0)
+++ pkg/man/subperiodmanyfirms.lmAMM.Rd 2014-02-13 09:52:44 UTC (rev 165)
@@ -0,0 +1,61 @@
+\name{subperiodmanyfirms.lmAMM}
+\alias{subperiodmanyfirms.lmAMM}
+
+\title{A function to compute AMM for multiple firms across several
+periods}
+
+\description{
+ This function will compute AMM for multiple firms at once using the
+ matrix of data obtained from \code{makeX}, and a matrix of LHS variables}
+
+\usage{
+subperiodmanyfirms.lmAMM(regressand, regressors, lags, dates = NULL, periodnames = NULL, verbose = FALSE)
+}
+
+\arguments{
+ \item{regressand}{A zoo matrix of all firms for which AMM is to
+ be computed}
+
+ \item{regressors}{A zoo matrix containing at least two
+ regressors generally obtained after applying the makeX function }
+
+ \item{lags}{ Specifies the number of lags to be used in the
+ market model}
+
+ \item{dates}{A set of dates that mark out subperiods of
+ interest. If dates is NULL then full period is considered.}
+
+ \item{periodnames}{Name for each subperiod that has been marked
+ by the dates above.}
+
+ \item{verbose}{Whether detailed print while running this
+ function is required}
+}
+
+\section{Warning}{Do not have any space between names provided under 'periodnames'}
+
+\author{Ajay Shah, Vimal Balasubramaniam}
+
+\seealso{
+\code{\link{onefirmAMM}}
+}
+
+\examples{
+# Running subperiodmanyfirms.lmAMM() involves as many steps as working with onefirmAMM.
+data("lmAMMData")
+regressand <- lmAMMData[,c("Infosys","TCS")]
+market.returns <- lmAMMData[,"index.nifty"]
+currency.returns <- lmAMMData[,"currency.inrusd"]
+## Creating regressors for AMM estimation using makeX function
+regressors <- makeX(market.returns, others=currency.returns, nlags=1,
+ switch.to.innov=FALSE, market.returns.purge=FALSE, verbose=FALSE,
+ dates=as.Date(c("2012-02-01","2013-01-01","2014-01-31")))
+## Estimating exposure
+res <- subperiodmanyfirms.lmAMM(regressand,regressors,lags=1,
+ dates=as.Date(c("2012-02-01","2013-01-01","2014-01-31")),
+ periodnames=c("P1","P2"),
+ verbose=FALSE)
+print(res)
+}
+
+\keyword{subperiodmanyfirms.lmAMM}
\ No newline at end of file
Deleted: pkg/man/y3c3.Rd
===================================================================
--- pkg/man/y3c3.Rd 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/man/y3c3.Rd 2014-02-13 09:52:44 UTC (rev 165)
@@ -1,17 +0,0 @@
-\name{y3c3}
-\alias{y3c3}
-
-
-\title{Three years and three random companies}
-
-\description{Data for testing and examples in the package}
-
-\usage{data(y3c3)}
-
-\examples{
-library(zoo)
-data(y3c3)
-str(y3c3)
-}
-
-\keyword{y3c3}
\ No newline at end of file
Modified: pkg/vignettes/amm.Rnw
===================================================================
--- pkg/vignettes/amm.Rnw 2014-02-08 07:53:10 UTC (rev 164)
+++ pkg/vignettes/amm.Rnw 2014-02-13 09:52:44 UTC (rev 165)
@@ -87,36 +87,34 @@
returns before using AMM model.
<<>>=
-# Create RHS before running onefirmAMM()
+# Create RHS before running subperiod.lmAMM()
library(eventstudies)
-data("y3c3")
-NIFTY <- y3c3$NIFTY_INDEX
-INRUSD <- y3c3$INRUSD
-Company_A <- y3c3$Company_A
-regressors <- makeX(NIFTY, others=INRUSD,
+data("lmAMMData")
+nifty <- lmAMMData$index.nifty
+inrusd <- lmAMMData$currency.inrusd
+firm.returns <- lmAMMData$Infosys
+regressors <- makeX(nifty, 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)
+ dates=as.Date(c("2012-02-01","2013-01-01","2014-01-31")), verbose=FALSE)
@
\subsubsection{Getting currency exposure}
-The output of {makeX} function is used in \textit{onefirmAMM} and
+The output of {makeX} function is used in \textit{subperiod.lmAMM} and
\textit{AMM} function to get currency exposure of the firms and AMM
residuals respectively. In the example below, we demonstrate the use
-of \textit{onefirmAMM} function to estimate currency exposure for
+of \textit{subperiod.lmAMM} function to estimate currency exposure for
firms.
-% MakeX and onefirmAMM
+% MakeX and subperiod.lmAMM
<<>>=
# Run AMM for one firm across different periods
deprintize<-function(f){
return(function(...) {capture.output(w<-f(...));return(w);});
}
-firm.exposure <- deprintize(onefirmAMM)(firm.returns=Company_A,
- X=regressors,
- nlags=1,
- verbose=TRUE,
- dates= as.Date(c("2005-01-15",
- "2006-01-07","2007-01-06",
- "2008-01-05","2009-01-03")))
+firm.exposure <- deprintize(subperiod.lmAMM)(firm.returns=firm.returns,
+ X=regressors,
+ nlags=1,
+ verbose=TRUE,
+ dates= as.Date(c("2012-02-01",
+ "2013-01-01","2014-01-31")))
str(firm.exposure)
@
More information about the Eventstudies-commits
mailing list