From noreply at r-forge.r-project.org Tue Apr 1 11:21:17 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 11:21:17 +0200 (CEST) Subject: [Eventstudies-commits] r269 - pkg/man Message-ID: <20140401092117.8BF04186E3A@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 11:21:17 +0200 (Tue, 01 Apr 2014) New Revision: 269 Modified: pkg/man/SplitDates.Rd pkg/man/StockPriceReturns.Rd pkg/man/inr.Rd pkg/man/lmAMMData.Rd pkg/man/mmData.Rd Log: Changed title of data objects. Modified: pkg/man/SplitDates.Rd =================================================================== --- pkg/man/SplitDates.Rd 2014-03-31 18:31:48 UTC (rev 268) +++ pkg/man/SplitDates.Rd 2014-04-01 09:21:17 UTC (rev 269) @@ -4,7 +4,7 @@ \alias{SplitDates} -\title{A set of events to perform eventstudy analysis.} +\title{Sample data containing set of events to perform eventstudy analysis.} \description{ This data set contains stock split event dates for the index constituents of the Bombay Stock Exchange index (SENSEX). The data Modified: pkg/man/StockPriceReturns.Rd =================================================================== --- pkg/man/StockPriceReturns.Rd 2014-03-31 18:31:48 UTC (rev 268) +++ pkg/man/StockPriceReturns.Rd 2014-04-01 09:21:17 UTC (rev 269) @@ -4,9 +4,8 @@ \alias{StockPriceReturns} -\title{An example dataset of stock price returns to perform event study analysis.} +\title{Sample data containing stock price returns} -% FIXME: Remove NAs in the dataset? If we do complete.cases then all rows will be removed \description{This data set contains stock price returns of 30 major stocks on the National Stock Exchange (NSE) of India for a period of 23 years.} Modified: pkg/man/inr.Rd =================================================================== --- pkg/man/inr.Rd 2014-03-31 18:31:48 UTC (rev 268) +++ pkg/man/inr.Rd 2014-04-01 09:21:17 UTC (rev 269) @@ -2,9 +2,7 @@ \alias{inr} \docType{data} -\title{ - Exchange rate for Indian rupee: INR/USD -} +\title{Exchange rate data of Indian Rupee to US Dollar} \description{ A sample of INR/USD rates from 1990 to 2011. Modified: pkg/man/lmAMMData.Rd =================================================================== --- pkg/man/lmAMMData.Rd 2014-03-31 18:31:48 UTC (rev 268) +++ pkg/man/lmAMMData.Rd 2014-04-01 09:21:17 UTC (rev 269) @@ -2,7 +2,8 @@ \alias{lmAMMData} -\title{Firm returns, market returns (Nifty) and currency returns (INR/USD) for AMM estimation} +\title{Data containing firm returns, market returns, and currency + returns used for AMM estimation} \description{The data series is a daily time-series zoo object. The sample range for the data is from 2012-02-01 to 2014-01-31. It consists daily time series for firm returns (Infosys and TCS), market returns (Nifty returns) and currency returns (INR/USD). This data is used to demonstrate the AMM estimation.} @@ -16,4 +17,4 @@ str(lmAMMData) } -\keyword{lmAMMData} \ No newline at end of file +\keyword{lmAMMData} Modified: pkg/man/mmData.Rd =================================================================== --- pkg/man/mmData.Rd 2014-03-31 18:31:48 UTC (rev 268) +++ pkg/man/mmData.Rd 2014-04-01 09:21:17 UTC (rev 269) @@ -2,9 +2,9 @@ \alias{mmData} -\title{Data for testing the market model and use with examples.} +\title{Sample data used for market model examples} -\description{This data is only used for testing.} +\description{This data is only used for market model examples.} \usage{data(mmData)} From noreply at r-forge.r-project.org Tue Apr 1 12:05:40 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 12:05:40 +0200 (CEST) Subject: [Eventstudies-commits] r270 - in pkg: data man vignettes Message-ID: <20140401100540.E972718717A@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 12:05:39 +0200 (Tue, 01 Apr 2014) New Revision: 270 Added: pkg/data/EESData.rda pkg/man/EESData.Rd Removed: pkg/data/eesData.rda pkg/man/eesData.Rd Modified: pkg/man/ees.Rd pkg/man/eesPlot.Rd pkg/vignettes/ees.Rnw Log: Capitalised eesData name. All data file names to start with uppercase alphabet. Copied: pkg/data/EESData.rda (from rev 264, pkg/data/eesData.rda) =================================================================== (Binary files differ) Deleted: pkg/data/eesData.rda =================================================================== (Binary files differ) Copied: pkg/man/EESData.Rd (from rev 264, pkg/man/eesData.Rd) =================================================================== --- pkg/man/EESData.Rd (rev 0) +++ pkg/man/EESData.Rd 2014-04-01 10:05:39 UTC (rev 270) @@ -0,0 +1,18 @@ +\name{EESData} + +\docType{data} + +\alias{EESData} + +\title{Returns data used for extreme events analysis} + +\description{A daily time series object for S&P 500 and the NIFTY Index.} + +\usage{data(EESData)} + +\format{\code{zoo}} + +\examples{ + data(EESData) +} +\keyword{datasets} Modified: pkg/man/ees.Rd =================================================================== --- pkg/man/ees.Rd 2014-04-01 09:21:17 UTC (rev 269) +++ pkg/man/ees.Rd 2014-04-01 10:05:39 UTC (rev 270) @@ -54,7 +54,7 @@ \author{Vikram Bahure} \examples{ library(eventstudies) -data(eesData) -input <- eesData$sp500 +data(EESData) +input <- EESData$sp500 output <- ees(input, prob.value = 5) } Deleted: pkg/man/eesData.Rd =================================================================== --- pkg/man/eesData.Rd 2014-04-01 09:21:17 UTC (rev 269) +++ pkg/man/eesData.Rd 2014-04-01 10:05:39 UTC (rev 270) @@ -1,18 +0,0 @@ -\name{eesData} - -\docType{data} - -\alias{eesData} - -\title{Returns data used for extreme events analysis} - -\description{A daily time series object for S&P 500 and the NIFTY Index.} - -\usage{data(eesData)} - -\format{\code{zoo}} - -\examples{ - data(eesData) -} -\keyword{datasets} Modified: pkg/man/eesPlot.Rd =================================================================== --- pkg/man/eesPlot.Rd 2014-04-01 09:21:17 UTC (rev 269) +++ pkg/man/eesPlot.Rd 2014-04-01 10:05:39 UTC (rev 270) @@ -51,8 +51,8 @@ \examples{ library(eventstudies) -data(eesData) -eesPlot(z = eesData, +data(EESData) +eesPlot(z = EESData, response.series.name = "nifty", event.series.name = "sp500", titlestring = "S&P500", Modified: pkg/vignettes/ees.Rnw =================================================================== --- pkg/vignettes/ees.Rnw 2014-04-01 09:21:17 UTC (rev 269) +++ pkg/vignettes/ees.Rnw 2014-04-01 10:05:39 UTC (rev 270) @@ -66,16 +66,16 @@ Since the object of interest is the impact on returns of the outcome variable, nifty, with tail events on the S\&P 500, we first obtain a -zoo object of returns data (``eesData''). Next, we define tail events +zoo object of returns data (``EESData''). Next, we define tail events for a given probability value; if \textit{prob.value} is 5, then returns that fall under $0-5\%$ and $95-100\%$ of the probability distribution form our set of events. <<>>== library(eventstudies) -data(eesData) +data(EESData) -input <- eesData$sp500 +input <- EESData$sp500 deprintize<-function(f){ return(function(...){ @@ -212,7 +212,7 @@ days before and after the event. <<>>= -eesPlot(z=eesData, response.series.name="nifty", event.series.name="sp500", titlestring="S&P500", ylab="(Cum.) change in NIFTY", prob.value=5, width=5) +eesPlot(z=EESData, response.series.name="nifty", event.series.name="sp500", titlestring="S&P500", ylab="(Cum.) change in NIFTY", prob.value=5, width=5) @ \begin{figure}[t] @@ -221,7 +221,7 @@ \setkeys{Gin}{width=1\linewidth} \setkeys{Gin}{height=0.8\linewidth} <>= -res <- deprintize(eesPlot)(z=eesData, response.series.name="nifty", +res <- deprintize(eesPlot)(z=EESData, response.series.name="nifty", event.series.name="sp500", titlestring="S&P500", ylab="(Cum.) change in NIFTY", From noreply at r-forge.r-project.org Tue Apr 1 12:19:53 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 12:19:53 +0200 (CEST) Subject: [Eventstudies-commits] r271 - pkg/inst Message-ID: <20140401101953.984A4186E34@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 12:19:53 +0200 (Tue, 01 Apr 2014) New Revision: 271 Modified: pkg/inst/CITATION Log: Fixed quotation symbol, removed non-ASCII warning. Modified: pkg/inst/CITATION =================================================================== --- pkg/inst/CITATION 2014-04-01 10:05:39 UTC (rev 270) +++ pkg/inst/CITATION 2014-04-01 10:19:53 UTC (rev 271) @@ -1,11 +1,9 @@ - bibentry(bibtype = "Manual", - title = ?{eventstudies}: An R package for researchers and users of event studie -s", - author = c(person(?Chirag?, ?Anand?), - person(?Vimal?, "Balasubramaniam?), - person(?Vikram?, ?Bahure?), - person(?Ajay?, "Shah?)), - organisation = ?NIPFP, Macro/Finance group?, + title = "{eventstudies}: An R package for conducting event studies and a platform for methodological research on event studies.", + author = c(person("Chirag", "Anand"), + person("Vimal", "Balasubramaniam"), + person("Vikram", "Bahure"), + person("Ajay", "Shah")), +organisation = "NIPFP, Macro/Finance group", year = 2014, - url = "http://CRAN.R-project.org/package=eventstudies?) + url = "http://CRAN.R-project.org/package=eventstudies") From noreply at r-forge.r-project.org Tue Apr 1 12:37:11 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 12:37:11 +0200 (CEST) Subject: [Eventstudies-commits] r272 - in pkg: data inst/tests man vignettes Message-ID: <20140401103711.A2408187218@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 12:37:11 +0200 (Tue, 01 Apr 2014) New Revision: 272 Added: pkg/data/INR.rda pkg/man/INR.Rd Removed: pkg/data/inr.rda pkg/man/inr.Rd Modified: pkg/inst/tests/test_inr_inference.R pkg/vignettes/eventstudies.Rnw Log: Modified the name of INR data set. Copied: pkg/data/INR.rda (from rev 264, pkg/data/inr.rda) =================================================================== (Binary files differ) Deleted: pkg/data/inr.rda =================================================================== (Binary files differ) Modified: pkg/inst/tests/test_inr_inference.R =================================================================== --- pkg/inst/tests/test_inr_inference.R 2014-04-01 10:19:53 UTC (rev 271) +++ pkg/inst/tests/test_inr_inference.R 2014-04-01 10:37:11 UTC (rev 272) @@ -3,9 +3,9 @@ test_that("test.inr.inference", { library(eventstudies) -load(system.file("data", "inr.rda",package = "eventstudies")) +load(system.file("data", "INR.rda",package = "eventstudies")) -inr_returns <- diff(log(inr))[-1] +inr_returns <- diff(log(INR))[-1] eventslist <- data.frame(outcome.unit=rep("inr",10), event.when=as.Date(c( Copied: pkg/man/INR.Rd (from rev 269, pkg/man/inr.Rd) =================================================================== --- pkg/man/INR.Rd (rev 0) +++ pkg/man/INR.Rd 2014-04-01 10:37:11 UTC (rev 272) @@ -0,0 +1,18 @@ +\name{INR} +\alias{INR} +\docType{data} + +\title{Exchange rate data of Indian Rupee to US Dollar} + +\description{ + A sample of INR/USD rates from 1990 to 2011. +} +\usage{data(INR)} + +\format{\pkg{zoo}} + +\examples{ +data(INR) +} + +\keyword{datasets} Deleted: pkg/man/inr.Rd =================================================================== --- pkg/man/inr.Rd 2014-04-01 10:19:53 UTC (rev 271) +++ pkg/man/inr.Rd 2014-04-01 10:37:11 UTC (rev 272) @@ -1,18 +0,0 @@ -\name{inr} -\alias{inr} -\docType{data} - -\title{Exchange rate data of Indian Rupee to US Dollar} - -\description{ - A sample of INR/USD rates from 1990 to 2011. -} -\usage{data(inr)} - -\format{\pkg{zoo}} - -\examples{ -data(inr) -} - -\keyword{datasets} Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2014-04-01 10:19:53 UTC (rev 271) +++ pkg/vignettes/eventstudies.Rnw 2014-04-01 10:37:11 UTC (rev 272) @@ -169,8 +169,8 @@ <<>>= data(SplitDates) head(SplitDates) -data(inr) -inrusd <- diff(log(inr))*100 +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 From noreply at r-forge.r-project.org Tue Apr 1 13:32:13 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 13:32:13 +0200 (CEST) Subject: [Eventstudies-commits] r273 - in pkg: data man vignettes Message-ID: <20140401113213.5BB37187084@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 13:32:12 +0200 (Tue, 01 Apr 2014) New Revision: 273 Added: pkg/data/AMMData.rda pkg/man/AMMData.Rd Removed: pkg/data/lmAMMData.rda pkg/man/lmAMMData.Rd Modified: pkg/man/lmAMM.Rd pkg/man/makeX.Rd pkg/man/manyfirmssubperiod.lmAMM.Rd pkg/man/subperiod.lmAMM.Rd pkg/vignettes/amm.Rnw Log: Renamed lmAMMData to AMMData. Copied: pkg/data/AMMData.rda (from rev 264, pkg/data/lmAMMData.rda) =================================================================== (Binary files differ) Deleted: pkg/data/lmAMMData.rda =================================================================== (Binary files differ) Copied: pkg/man/AMMData.Rd (from rev 269, pkg/man/lmAMMData.Rd) =================================================================== --- pkg/man/AMMData.Rd (rev 0) +++ pkg/man/AMMData.Rd 2014-04-01 11:32:12 UTC (rev 273) @@ -0,0 +1,20 @@ +\name{AMMData} +\alias{AMMData} + + +\title{Data containing firm returns, market returns, and currency + returns used for AMM estimation} + +\description{The data series is a daily time-series zoo object. The sample range for the data is from 2012-02-01 to 2014-01-31. It consists daily time series for firm returns (Infosys and TCS), market returns (Nifty returns) and currency returns (INR/USD). This data is used to demonstrate the AMM estimation.} + +\usage{data(AMMData)} + +\author{Vikram Bahure} + +\examples{ +library(zoo) +data(AMMData) +str(AMMData) +} + +\keyword{AMMData} Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-01 10:37:11 UTC (rev 272) +++ pkg/man/lmAMM.Rd 2014-04-01 11:32:12 UTC (rev 273) @@ -79,11 +79,11 @@ } \examples{ -data("lmAMMData") +data("AMMData") -firm.returns <- lmAMMData[,"Infosys"] -market.returns <- lmAMMData[,"index.nifty"] -currency.returns <- lmAMMData[,"currency.inrusd"] +firm.returns <- AMMData[,"Infosys"] +market.returns <- AMMData[,"index.nifty"] +currency.returns <- AMMData[,"currency.inrusd"] ## Creating regressors for AMM estimation using makeX function X <- makeX(market.returns, Deleted: pkg/man/lmAMMData.Rd =================================================================== --- pkg/man/lmAMMData.Rd 2014-04-01 10:37:11 UTC (rev 272) +++ pkg/man/lmAMMData.Rd 2014-04-01 11:32:12 UTC (rev 273) @@ -1,20 +0,0 @@ -\name{lmAMMData} -\alias{lmAMMData} - - -\title{Data containing firm returns, market returns, and currency - returns used for AMM estimation} - -\description{The data series is a daily time-series zoo object. The sample range for the data is from 2012-02-01 to 2014-01-31. It consists daily time series for firm returns (Infosys and TCS), market returns (Nifty returns) and currency returns (INR/USD). This data is used to demonstrate the AMM estimation.} - -\usage{data(lmAMMData)} - -\author{Vikram Bahure} - -\examples{ -library(zoo) -data(lmAMMData) -str(lmAMMData) -} - -\keyword{lmAMMData} Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2014-04-01 10:37:11 UTC (rev 272) +++ pkg/man/makeX.Rd 2014-04-01 11:32:12 UTC (rev 273) @@ -63,10 +63,10 @@ \author{Ajay Shah, Vimal Balasubramaniam} \examples{ -data("lmAMMData") +data("AMMData") -market.returns <- lmAMMData$index.nifty -currency.returns <- lmAMMData$currency.inrusd +market.returns <- AMMData$index.nifty +currency.returns <- AMMData$currency.inrusd X <- makeX(market.returns, others = currency.returns, Modified: pkg/man/manyfirmssubperiod.lmAMM.Rd =================================================================== --- pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-01 10:37:11 UTC (rev 272) +++ pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-01 11:32:12 UTC (rev 273) @@ -54,11 +54,11 @@ ## Running manyfirmssubperiod.lmAMM() involves as many steps as working ## with onefirmAMM. -data("lmAMMData") +data("AMMData") -firm.returns <- lmAMMData[, c("Infosys","TCS")] -market.returns <- lmAMMData[, "index.nifty"] -currency.returns <- lmAMMData[, "currency.inrusd"] +firm.returns <- AMMData[, c("Infosys","TCS")] +market.returns <- AMMData[, "index.nifty"] +currency.returns <- AMMData[, "currency.inrusd"] ## Creating X for AMM estimation using makeX function X <- makeX(market.returns, Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-01 10:37:11 UTC (rev 272) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-01 11:32:12 UTC (rev 273) @@ -52,12 +52,12 @@ \code{\link{manyfirmssubperiod.lmAMM}}} \examples{ -data("lmAMMData") +data("AMMData") ## Create RHS before running subperiod.lmAMM() -firm.returns <- lmAMMData$Infosys -market.returns <- lmAMMData$index.nifty -currency.returns <- lmAMMData$currency.inrusd +firm.returns <- AMMData$Infosys +market.returns <- AMMData$index.nifty +currency.returns <- AMMData$currency.inrusd regressors <- makeX(market.returns, others = currency.returns, @@ -77,4 +77,4 @@ "2014-01-20"))) } -\keyword{subperiod.lmAMM} \ No newline at end of file +\keyword{subperiod.lmAMM} Modified: pkg/vignettes/amm.Rnw =================================================================== --- pkg/vignettes/amm.Rnw 2014-04-01 10:37:11 UTC (rev 272) +++ pkg/vignettes/amm.Rnw 2014-04-01 11:32:12 UTC (rev 273) @@ -78,7 +78,7 @@ Regressors in the AMM equation are market returns and currency returns, while regressands is firm returns. All the variables should have balanced panel if not then merge the time series variable to get -one. \textit{lmAMMData} is an time series object with market returns as +one. \textit{AMMData} is an time series object with market returns as \textit{Nifty} and currency returns as \textit{INR/USD}. If currency exposure is to be estimated for different periods separately then argument \textit{dates} will be helpful or else \textit{NULL} @@ -92,10 +92,10 @@ <<>>= # Create RHS before running subperiod.lmAMM() library(eventstudies) -data("lmAMMData") -nifty <- lmAMMData$index.nifty -inrusd <- lmAMMData$currency.inrusd -regressand <- lmAMMData[,c("Infosys","TCS")] +data("AMMData") +nifty <- AMMData$index.nifty +inrusd <- AMMData$currency.inrusd +regressand <- AMMData[,c("Infosys","TCS")] regressors <- makeX(nifty, others=inrusd, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, dates=as.Date(c("2012-02-01","2013-01-01","2014-01-20")), verbose=FALSE) From noreply at r-forge.r-project.org Tue Apr 1 13:53:22 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 13:53:22 +0200 (CEST) Subject: [Eventstudies-commits] r274 - in pkg: data man Message-ID: <20140401115322.AC981186EEF@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 13:53:22 +0200 (Tue, 01 Apr 2014) New Revision: 274 Added: pkg/data/MMData.rda pkg/man/MMData.Rd Removed: pkg/data/mmData.rda pkg/man/mmData.Rd Log: Renamed mmData to MMData. Copied: pkg/data/MMData.rda (from rev 264, pkg/data/mmData.rda) =================================================================== (Binary files differ) Deleted: pkg/data/mmData.rda =================================================================== (Binary files differ) Copied: pkg/man/MMData.Rd (from rev 269, pkg/man/mmData.Rd) =================================================================== --- pkg/man/MMData.Rd (rev 0) +++ pkg/man/MMData.Rd 2014-04-01 11:53:22 UTC (rev 274) @@ -0,0 +1,21 @@ +\name{MMData} +\alias{MMData} + + +\title{Sample data used for market model examples} + +\description{This data is only used for market model examples.} + +\usage{data(MMData)} + +\format{\pkg{zoo}} + +\author{Vikram Bahure} + +\examples{ +library(zoo) +data(MMData) +str(MMData) +} + +\keyword{MMData} Deleted: pkg/man/mmData.Rd =================================================================== --- pkg/man/mmData.Rd 2014-04-01 11:32:12 UTC (rev 273) +++ pkg/man/mmData.Rd 2014-04-01 11:53:22 UTC (rev 274) @@ -1,21 +0,0 @@ -\name{mmData} -\alias{mmData} - - -\title{Sample data used for market model examples} - -\description{This data is only used for market model examples.} - -\usage{data(mmData)} - -\format{\pkg{zoo}} - -\author{Vikram Bahure} - -\examples{ -library(zoo) -data(mmData) -str(mmData) -} - -\keyword{mmData} From noreply at r-forge.r-project.org Tue Apr 1 14:03:59 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 1 Apr 2014 14:03:59 +0200 (CEST) Subject: [Eventstudies-commits] r275 - in pkg: data inst/tests man vignettes Message-ID: <20140401120359.E8EAC186FD8@r-forge.r-project.org> Author: chiraganand Date: 2014-04-01 14:03:59 +0200 (Tue, 01 Apr 2014) New Revision: 275 Added: pkg/data/NiftyIndex.rda pkg/man/NiftyIndex.Rd Removed: pkg/data/nifty.index.rda pkg/man/nifty.index.Rd Modified: pkg/inst/tests/test_marketresiduals.R pkg/man/excessReturn.Rd pkg/man/marketResidual.Rd pkg/vignettes/eventstudies.Rnw Log: Renamed nifty.index data. Copied: pkg/data/NiftyIndex.rda (from rev 264, pkg/data/nifty.index.rda) =================================================================== (Binary files differ) Deleted: pkg/data/nifty.index.rda =================================================================== (Binary files differ) Modified: pkg/inst/tests/test_marketresiduals.R =================================================================== --- pkg/inst/tests/test_marketresiduals.R 2014-04-01 11:53:22 UTC (rev 274) +++ pkg/inst/tests/test_marketresiduals.R 2014-04-01 12:03:59 UTC (rev 275) @@ -4,19 +4,19 @@ library(eventstudies) load(system.file("data", "StockPriceReturns.rda", package = "eventstudies")) -load(system.file("data", "nifty.index.rda", package = "eventstudies")) +load(system.file("data", "NiftyIndex.rda", package = "eventstudies")) -alldata <- merge(StockPriceReturns, nifty.index, all = TRUE) -StockPriceReturns <- alldata[,-which(colnames(alldata) %in% "nifty.index")] -nifty.index <- alldata$nifty.index +alldata <- merge(StockPriceReturns, NiftyIndex, all = TRUE) +StockPriceReturns <- alldata[,-which(colnames(alldata) %in% "NiftyIndex")] +NiftyIndex <- alldata$NiftyIndex mm.result <- marketResidual(firm.returns=StockPriceReturns[,c("BHEL")], - market.returns=nifty.index) + market.returns=NiftyIndex) mm.result <- xts(mm.result[complete.cases(mm.result),]) colnames(mm.result) <- "BHEL" # Calculating manually -result <- lm(BHEL ~ nifty.index, data=StockPriceReturns) +result <- lm(BHEL ~ NiftyIndex, data=StockPriceReturns) resid.res <- xts(result$resid,as.Date(attr(result$resid,"names"))) colnames(resid.res) <- "BHEL" Copied: pkg/man/NiftyIndex.Rd (from rev 264, pkg/man/nifty.index.Rd) =================================================================== --- pkg/man/NiftyIndex.Rd (rev 0) +++ pkg/man/NiftyIndex.Rd 2014-04-01 12:03:59 UTC (rev 275) @@ -0,0 +1,17 @@ +\name{NiftyIndex} +\alias{NiftyIndex} +\docType{data} + +\title{NSE Nifty index from 2004 to 2012.} + +\description{A sample time series of Nifty index return from 1990 to + 2012.} + +\usage{data(NiftyIndex)} + +\format{\pkg{zoo}} + +\examples{ +data(NiftyIndex) +} +\keyword{datasets} Modified: pkg/man/excessReturn.Rd =================================================================== --- pkg/man/excessReturn.Rd 2014-04-01 11:53:22 UTC (rev 274) +++ pkg/man/excessReturn.Rd 2014-04-01 12:03:59 UTC (rev 275) @@ -22,9 +22,9 @@ \examples{ data(StockPriceReturns) -data(nifty.index) +data(NiftyIndex) er.result <- excessReturn(firm.returns = StockPriceReturns, - market.returns = nifty.index) + market.returns = NiftyIndex) } \keyword{excessReturn} Modified: pkg/man/marketResidual.Rd =================================================================== --- pkg/man/marketResidual.Rd 2014-04-01 11:53:22 UTC (rev 274) +++ pkg/man/marketResidual.Rd 2014-04-01 12:03:59 UTC (rev 275) @@ -22,10 +22,10 @@ \examples{ data(StockPriceReturns) -data(nifty.index) +data(NiftyIndex) mm.result <- marketResidual(firm.returns = StockPriceReturns, - market.returns = nifty.index) + market.returns = NiftyIndex) } Deleted: pkg/man/nifty.index.Rd =================================================================== --- pkg/man/nifty.index.Rd 2014-04-01 11:53:22 UTC (rev 274) +++ pkg/man/nifty.index.Rd 2014-04-01 12:03:59 UTC (rev 275) @@ -1,17 +0,0 @@ -\name{nifty.index} -\alias{nifty.index} -\docType{data} - -\title{NSE Nifty index from 2004 to 2012.} - -\description{A sample time series of Nifty index return from 1990 to - 2012.} - -\usage{data(nifty.index)} - -\format{\pkg{zoo}} - -\examples{ -data(nifty.index) -} -\keyword{datasets} Modified: pkg/vignettes/eventstudies.Rnw =================================================================== --- pkg/vignettes/eventstudies.Rnw 2014-04-01 11:53:22 UTC (rev 274) +++ pkg/vignettes/eventstudies.Rnw 2014-04-01 12:03:59 UTC (rev 275) @@ -153,15 +153,15 @@ In this section, we demonstrate the package with a study of the impact of stock splits on the stock prices of firms. We use the returns series of the thirty index companies, as of 2013, of the Bombay Stock Exchange (BSE), between 2001 and 2013. We also have stock split dates for each firm since 2000. -Our data consists of a \textit{zoo} object for stock price returns for the thirty firms. This is our ``outcome variable'' of interest, and is called \textit{StockPriceReturns}. Another zoo object, \textit{nifty.index}, contains a time series of market returns. +Our data consists of a \textit{zoo} object for stock price returns for the thirty firms. This is our ``outcome variable'' of interest, and is called \textit{StockPriceReturns}. Another zoo object, \textit{NiftyIndex}, contains a time series of market returns. <<>>= library(eventstudies) data(StockPriceReturns) -data(nifty.index) +data(NiftyIndex) str(StockPriceReturns) head(StockPriceReturns[rowSums(is.na((StockPriceReturns)))==3,1:3]) -head(nifty.index) +head(NiftyIndex) @ As required by the package, the event date (the dates on which stock splits occured for these 30 firms) for each firm is recorded in \textit{SplitDates} where ``outcome.unit'' is the name of the firm (the column name in ``StockPriceReturns'') and ``event.date'' is when the event took place for that outcome unit. In R, the column ``outcome.unit'' has to be of class ``character'' and ``event.date'' of class ``Date'', as seen below: @@ -171,9 +171,9 @@ head(SplitDates) 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 +all.data <- merge(StockPriceReturns,NiftyIndex,inrusd,all=TRUE) +StockPriceReturns <- all.data[,-which(colnames(all.data)%in%c("NiftyIndex", "inr"))] +NiftyIndex <- all.data$NiftyIndex inrusd <- all.data$inr @ @@ -188,14 +188,14 @@ idiosyncratic return estimation that is possible with this package. <<>>= # Excess return -er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = nifty.index) +er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = NiftyIndex) er.result <- er.result[rowSums(is.na(er.result))!=NCOL(er.result),] head(er.result[,1:3]) @ <<>>= # Extracting market residual -mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = nifty.index) +mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = NiftyIndex) mm.result <- mm.result[rowSums(is.na(mm.result))!=NCOL(mm.result),] head(mm.result[,1:3]) @@ -223,7 +223,7 @@ ## AMM residuals ## ################### ## Getting Regressors -regressors <- makeX(market.returns=nifty.index, others=inrusd, +regressors <- makeX(market.returns=NiftyIndex, others=inrusd, market.returns.purge=TRUE, nlags=1) ## AMM residual to time series timeseries.lmAMM <- function(firm.returns,X,verbose=FALSE,nlags=1){ @@ -341,19 +341,19 @@ es.mm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", inference = TRUE, inference.strategy = "bootstrap", - type = "marketResidual", market.returns = nifty.index) + type = "marketResidual", market.returns = NiftyIndex) ## Event study using excess return and bootstrap es.er <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", inference = TRUE, inference.strategy = "bootstrap", - type = "excessReturn", market.returns = nifty.index) + type = "excessReturn", market.returns = NiftyIndex) ## Event study using augmented market model (AMM) and bootstrap es.amm <- eventstudy(firm.returns = StockPriceReturns, eventList = SplitDates, width = 10, to.remap = TRUE, remap = "cumsum", inference = TRUE, inference.strategy = "bootstrap", - type = "lmAMM", market.returns = nifty.index, + type = "lmAMM", market.returns = NiftyIndex, others=inrusd, verbose=FALSE, switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1) print(es.na) From noreply at r-forge.r-project.org Wed Apr 2 18:14:17 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 2 Apr 2014 18:14:17 +0200 (CEST) Subject: [Eventstudies-commits] r276 - pkg/man Message-ID: <20140402161417.B5D1D184EF7@r-forge.r-project.org> Author: chiraganand Date: 2014-04-02 18:14:17 +0200 (Wed, 02 Apr 2014) New Revision: 276 Modified: pkg/man/eventstudy.Rd pkg/man/makeX.Rd pkg/man/phys2eventtime.Rd pkg/man/subperiod.lmAMM.Rd Log: Added printing of objects and structures at the end of examples. Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2014-04-01 12:03:59 UTC (rev 275) +++ pkg/man/eventstudy.Rd 2014-04-02 16:14:17 UTC (rev 276) @@ -202,5 +202,7 @@ inference = TRUE, inference.strategy = "bootstrap") } +print(es) +plot(es) \keyword{eventstudy} Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2014-04-01 12:03:59 UTC (rev 275) +++ pkg/man/makeX.Rd 2014-04-02 16:14:17 UTC (rev 276) @@ -74,5 +74,5 @@ market.returns.purge = FALSE, verbose = FALSE) } - +head(X) \keyword{makeX} Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-01 12:03:59 UTC (rev 275) +++ pkg/man/phys2eventtime.Rd 2014-04-02 16:14:17 UTC (rev 276) @@ -79,5 +79,5 @@ events = SplitDates, width = 5) } - +str(result) \keyword{phys2eventime} Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-01 12:03:59 UTC (rev 275) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-02 16:14:17 UTC (rev 276) @@ -76,5 +76,5 @@ "2013-01-01", "2014-01-20"))) } - +str(res) \keyword{subperiod.lmAMM} From noreply at r-forge.r-project.org Wed Apr 2 18:25:49 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 2 Apr 2014 18:25:49 +0200 (CEST) Subject: [Eventstudies-commits] r277 - pkg/R Message-ID: <20140402162549.31BFA186B15@r-forge.r-project.org> Author: chiraganand Date: 2014-04-02 18:25:48 +0200 (Wed, 02 Apr 2014) New Revision: 277 Added: pkg/R/lmAMM.R Removed: pkg/R/lmAmm.R Log: Renamed lmAMM R file, making consistent with the function name. Copied: pkg/R/lmAMM.R (from rev 275, pkg/R/lmAmm.R) =================================================================== --- pkg/R/lmAMM.R (rev 0) +++ pkg/R/lmAMM.R 2014-04-02 16:25:48 UTC (rev 277) @@ -0,0 +1,362 @@ +############### +## 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 +######################## +manyfirmssubperiod.lmAMM <- +function(firm.returns,X, + lags,dates=NULL, periodnames=NULL,verbose=FALSE){ + if(is.null(dates)){ + dates=c(start(X),end(X)) + periodnames="Full" + } + nperiods <- length(periodnames) + if(length(dates) != (nperiods+1)){ + cat("Mistake in length of dates versus length of periods.\n") + return(NULL) + } + nfirms <- ncol(firm.returns) + + # Let's get "exposure' and 'sds'. Setting up structures:- + + exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(X)) + exposures <- as.data.frame(exposures) + rownames(exposures) <- colnames(firm.returns) + tmp <- NULL + for(i in 1:length(periodnames)){ + for(j in 1:NCOL(X)){ + tmp <- c(tmp, paste(colnames(X)[j], + periodnames[i],sep=".")) + } + } + colnames(exposures) <- tmp + sds <- exposures + colnames(sds) <- paste("sd",colnames(exposures),sep=".") + + # Setup a list structure for an OLS that failed + empty <- list(exposures=rep(NA,ncol(X)), + s.exposures=rep(NA,ncol(X))) + + for(i in 1:NCOL(firm.returns)){ + cat("AMM estimation for",colnames(firm.returns)[i],"\n") + if (verbose) {cat ("AMM estimation for", colnames(firm.returns)[i], "\n")} + stock.return <- firm.returns[,i] + dataset <- cbind(stock.return, X) # This is the full time-series + this.exp <- this.sds <- NULL + for(j in 1:nperiods){ # now we chop it up + t1 <- dates[j] + t2 <- dates[j+1] + this <- window(dataset,start=t1, end=t2) + fe <- lmAMM(this[,1],this[,-1],nlags=lags,verbose) + if(is.null(fe)) {fe <- empty} + this.exp <- c(this.exp, fe$exposures) + this.sds <- c(this.sds, fe$s.exposures) + } + exposures[colnames(firm.returns)[i],] <- this.exp + sds[colnames(firm.returns)[i],] <- this.sds + } + list(exposures=exposures, sds=sds, sig=exposures/sds) +} + +############################################### +## Estimating one firm's exposure in one period +############################################### +lmAMM <- function(firm.returns, X, nlags=NA, verbose=FALSE) { + do.ols <- function(nlags) { + 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) { + tmp <- cbind(tmp, lag(X[,i], -j)) + labels <- c(labels, paste(colnames(X)[i], j, sep=".")) + } + } + } + tmp <- na.omit(tmp) + if (nrow(tmp) < 30) { # refuse to do the work. + return(NULL) # returns out of do.ols() only + } + + colnames(tmp) <- labels # So the OLS results will look nice + lm(firm.returns ~ ., data=as.data.frame(tmp)) + } + + if (is.na(nlags)) { + if (verbose) {cat("Trying to find the best lag structure...\n")} + bestlag <- 0 + bestm <- NULL + bestAIC <- Inf + 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")} + if (thisAIC < bestAIC) { + bestlag <- trylag + bestAIC <- thisAIC + bestm <- thism + } + } + nlags <- bestlag + m <- bestm + } else { + m <- do.ols(nlags) + if (is.null(m)) {return(NULL)} + } + # In either event, you endup holding an "m" here. + if (verbose) {cat("\n\nThe OLS:\n"); print(summary(m))} + + # Compute a series of exposure measures, and their standard errors. + beta <- m$coefficients + Sigma <- vcovHAC(m) + # 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-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. + n.block2 <- length(beta) - n.block1 - (1 + nlags) + w <- c(rep(0, n.block1), rep(1, 1+nlags), rep(0, n.block2)) + exposures <- c(exposures, w %*% beta) + s.exposures <- c(s.exposures, sqrt(w %*% Sigma %*% w)) + } + } + results <- m + names(exposures) <- names(s.exposures) <- colnames(X) + results$exposures <- exposures + results$s.exposures <- s.exposures + results$nlags <- nlags + class(results) <- "amm" + return(results) +} + + +########################### +# Maintaining NAs in AR model +########################### +ARinnovations <- function(x) { + stopifnot(NCOL(x) == 1) + dt <- NULL + if (class(x) == "zoo") { + dt <- index(x) + x <- as.numeric(x) + } + non.na.locations <- !is.na(x) + x <- x[non.na.locations] + m <- ar(x) + e <- m$resid + # Relocate with the old NA structure + result <- rep(NA, length(non.na.locations)) + result[non.na.locations] <- e + if (!is.null(dt)) {result <- zoo(result, order.by=dt)} + list(result=result, m=m) +} + +# --------------------------------------------------------------------------- +# The workhorse called by makeX to return a nice matrix of RHS +# variables to be used in an analysis. +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 ", + as.character(tail(thedates,1)), "\n") + } + otherlags <- NULL + for (i in 1:NCOL(others)) { + if (switch.to.innov[i]) { + a <- ARinnovations(others[,i]) + innovated <- a$result + if (verbose) { + cat(" AR model for ", colnames(others, do.NULL=FALSE)[i], "\n") + print(a$m) + } + otherlags <- c(otherlags, a$m$order) + } else { + innovated <- others[,i] + otherlags <- c(otherlags, 0) + } + if (i > 1) { + innov <- cbind(innov, innovated) + } else { + innov <- innovated + } + } + if (NCOL(innov) > 1) {colnames(innov) <- colnames(others)} + market.returns.purged <- market.returns + if (market.returns.purge) { + firstpass <- TRUE + for (i in 1:NCOL(innov)) { + for (j in 0:nlags) { + if (firstpass) { + z <- lag(innov[,i],-j) + labels <- paste(colnames(innov,do.NULL=FALSE)[i],j,sep=".") + firstpass <- FALSE + } else { + z <- cbind(z, lag(innov[,i], -j)) + labels <- c(labels, paste(colnames(innov,do.NULL=FALSE)[i],j,sep=".")) + } + } + } + if (NCOL(z) > 1) {colnames(z) <- labels} + m <- lm(market.returns ~ ., as.data.frame(cbind(market.returns, z))) + if (verbose) { + cat(" Model explaining market.returns:\n") + print(summary(m)) + } + how.many.NAs <- nlags + max(otherlags) + market.returns.purged <- zoo(c(rep(NA,how.many.NAs),m$residuals), + order.by=thedates) + } + # if (verbose) {cat(" Finished do.one.piece()\n")} + 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(market.returns, others, + switch.to.innov=rep(TRUE, NCOL(others)), + market.returns.purge=TRUE, + nlags=5, + dates=NULL, + verbose=FALSE) { + if (verbose) {cat("0. Checking args\n")} + 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(market.returns),end(market.returns)) + } + 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(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")} + for (i in 1:(length(dates)-1)) { + t1 <- dates[i] + t2 <- dates[i+1] + if (i != (length(dates)-1)) {t2 <- t2 -1} + if (verbose) { + cat(" Focusing down from date = ", as.character(t1), " to ", as.character(t2), "\n") + } + tmp.market.returns <- window(market.returns, start=t1, end=t2) + tmp.others <- window(others, start=t1, end=t2) + a <- do.one.piece(tmp.market.returns, tmp.others, switch.to.innov, market.returns.purge, nlags, verbose) + if (i > 1) { + res.market.returns <- c(res.market.returns, a$market.returns.purged) + res.innov <- rbind(res.innov, a$innov) + } else { + 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.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 +} + + +############################################ +## Summary, print and plot functions for AMM +############################################ +summary.amm <- function(object, ...) { + cat("\n", "Summary statistics of exposure: \n") + sstats <- cbind(object$exposure, object$s.exposure, + object$exposure/object$s.exposure) + colnames(sstats) <- c("Exposure", "Std.Err", "t statistic") + rownames(sstats) <- names(object$exposures) + print(sstats) + cat("\n","Linear model AMM results: ","\n"); + class(object) <- "lm"; + print.default(summary.default(object)) +} + +print.amm <- function(x, ...){ + cat("\n") + print(x$call) + cat("\n","Coefficients:","\n") + print(x$coef) + cat("\n","Exposures:","\n") + print.default(x$exposures) +} + +plot.amm <- function(x, ...){ + tmp.x <- zoo(as.numeric(resid(x)), as.Date(names(resid(x)))) + tmp.f <- zoo(x$model$firm.returns, index(tmp.x)) + tmp <- merge(tmp.x,tmp.f) + colnames(tmp) <- c("amm.residuals","firm.returns") + plot(tmp, screen=1, lty=1:2, lwd=2, col=c("indian red", "navy blue"),ylab="", + xlab="") + legend("topleft",legend=c("AMM residual","Firm returns"),lty=1:2, lwd=2, + col=c("indian red", "navy blue"), bty='n') +} Deleted: pkg/R/lmAmm.R =================================================================== --- pkg/R/lmAmm.R 2014-04-02 16:14:17 UTC (rev 276) +++ pkg/R/lmAmm.R 2014-04-02 16:25:48 UTC (rev 277) @@ -1,362 +0,0 @@ -############### -## 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 -######################## -manyfirmssubperiod.lmAMM <- -function(firm.returns,X, - lags,dates=NULL, periodnames=NULL,verbose=FALSE){ - if(is.null(dates)){ - dates=c(start(X),end(X)) - periodnames="Full" - } - nperiods <- length(periodnames) - if(length(dates) != (nperiods+1)){ - cat("Mistake in length of dates versus length of periods.\n") - return(NULL) - } - nfirms <- ncol(firm.returns) - - # Let's get "exposure' and 'sds'. Setting up structures:- - - exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(X)) - exposures <- as.data.frame(exposures) - rownames(exposures) <- colnames(firm.returns) - tmp <- NULL - for(i in 1:length(periodnames)){ - for(j in 1:NCOL(X)){ - tmp <- c(tmp, paste(colnames(X)[j], - periodnames[i],sep=".")) - } - } - colnames(exposures) <- tmp - sds <- exposures - colnames(sds) <- paste("sd",colnames(exposures),sep=".") - - # Setup a list structure for an OLS that failed - empty <- list(exposures=rep(NA,ncol(X)), - s.exposures=rep(NA,ncol(X))) - - for(i in 1:NCOL(firm.returns)){ - cat("AMM estimation for",colnames(firm.returns)[i],"\n") - if (verbose) {cat ("AMM estimation for", colnames(firm.returns)[i], "\n")} - stock.return <- firm.returns[,i] - dataset <- cbind(stock.return, X) # This is the full time-series - this.exp <- this.sds <- NULL - for(j in 1:nperiods){ # now we chop it up - t1 <- dates[j] - t2 <- dates[j+1] - this <- window(dataset,start=t1, end=t2) - fe <- lmAMM(this[,1],this[,-1],nlags=lags,verbose) - if(is.null(fe)) {fe <- empty} - this.exp <- c(this.exp, fe$exposures) - this.sds <- c(this.sds, fe$s.exposures) - } - exposures[colnames(firm.returns)[i],] <- this.exp - sds[colnames(firm.returns)[i],] <- this.sds - } - list(exposures=exposures, sds=sds, sig=exposures/sds) -} - -############################################### -## Estimating one firm's exposure in one period -############################################### -lmAMM <- function(firm.returns, X, nlags=NA, verbose=FALSE) { - do.ols <- function(nlags) { - 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) { - tmp <- cbind(tmp, lag(X[,i], -j)) - labels <- c(labels, paste(colnames(X)[i], j, sep=".")) - } - } - } - tmp <- na.omit(tmp) - if (nrow(tmp) < 30) { # refuse to do the work. - return(NULL) # returns out of do.ols() only - } - - colnames(tmp) <- labels # So the OLS results will look nice - lm(firm.returns ~ ., data=as.data.frame(tmp)) - } - - if (is.na(nlags)) { - if (verbose) {cat("Trying to find the best lag structure...\n")} - bestlag <- 0 - bestm <- NULL - bestAIC <- Inf - 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")} - if (thisAIC < bestAIC) { - bestlag <- trylag - bestAIC <- thisAIC - bestm <- thism - } - } - nlags <- bestlag - m <- bestm - } else { - m <- do.ols(nlags) - if (is.null(m)) {return(NULL)} - } - # In either event, you endup holding an "m" here. - if (verbose) {cat("\n\nThe OLS:\n"); print(summary(m))} - - # Compute a series of exposure measures, and their standard errors. - beta <- m$coefficients - Sigma <- vcovHAC(m) - # 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-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. - n.block2 <- length(beta) - n.block1 - (1 + nlags) - w <- c(rep(0, n.block1), rep(1, 1+nlags), rep(0, n.block2)) - exposures <- c(exposures, w %*% beta) - s.exposures <- c(s.exposures, sqrt(w %*% Sigma %*% w)) - } - } - results <- m - names(exposures) <- names(s.exposures) <- colnames(X) - results$exposures <- exposures - results$s.exposures <- s.exposures - results$nlags <- nlags - class(results) <- "amm" - return(results) -} - - -########################### -# Maintaining NAs in AR model -########################### -ARinnovations <- function(x) { - stopifnot(NCOL(x) == 1) - dt <- NULL - if (class(x) == "zoo") { - dt <- index(x) - x <- as.numeric(x) - } - non.na.locations <- !is.na(x) - x <- x[non.na.locations] - m <- ar(x) - e <- m$resid - # Relocate with the old NA structure - result <- rep(NA, length(non.na.locations)) - result[non.na.locations] <- e - if (!is.null(dt)) {result <- zoo(result, order.by=dt)} - list(result=result, m=m) -} - -# --------------------------------------------------------------------------- -# The workhorse called by makeX to return a nice matrix of RHS -# variables to be used in an analysis. -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 ", - as.character(tail(thedates,1)), "\n") - } - otherlags <- NULL - for (i in 1:NCOL(others)) { - if (switch.to.innov[i]) { - a <- ARinnovations(others[,i]) - innovated <- a$result - if (verbose) { - cat(" AR model for ", colnames(others, do.NULL=FALSE)[i], "\n") - print(a$m) - } - otherlags <- c(otherlags, a$m$order) - } else { - innovated <- others[,i] - otherlags <- c(otherlags, 0) - } - if (i > 1) { - innov <- cbind(innov, innovated) - } else { - innov <- innovated - } - } - if (NCOL(innov) > 1) {colnames(innov) <- colnames(others)} - market.returns.purged <- market.returns - if (market.returns.purge) { - firstpass <- TRUE - for (i in 1:NCOL(innov)) { - for (j in 0:nlags) { - if (firstpass) { - z <- lag(innov[,i],-j) - labels <- paste(colnames(innov,do.NULL=FALSE)[i],j,sep=".") - firstpass <- FALSE - } else { - z <- cbind(z, lag(innov[,i], -j)) - labels <- c(labels, paste(colnames(innov,do.NULL=FALSE)[i],j,sep=".")) - } - } - } - if (NCOL(z) > 1) {colnames(z) <- labels} - m <- lm(market.returns ~ ., as.data.frame(cbind(market.returns, z))) - if (verbose) { - cat(" Model explaining market.returns:\n") - print(summary(m)) - } - how.many.NAs <- nlags + max(otherlags) - market.returns.purged <- zoo(c(rep(NA,how.many.NAs),m$residuals), - order.by=thedates) - } - # if (verbose) {cat(" Finished do.one.piece()\n")} - 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(market.returns, others, - switch.to.innov=rep(TRUE, NCOL(others)), - market.returns.purge=TRUE, - nlags=5, - dates=NULL, - verbose=FALSE) { - if (verbose) {cat("0. Checking args\n")} - 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(market.returns),end(market.returns)) - } - 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(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")} - for (i in 1:(length(dates)-1)) { - t1 <- dates[i] - t2 <- dates[i+1] - if (i != (length(dates)-1)) {t2 <- t2 -1} - if (verbose) { - cat(" Focusing down from date = ", as.character(t1), " to ", as.character(t2), "\n") - } - tmp.market.returns <- window(market.returns, start=t1, end=t2) - tmp.others <- window(others, start=t1, end=t2) - a <- do.one.piece(tmp.market.returns, tmp.others, switch.to.innov, market.returns.purge, nlags, verbose) - if (i > 1) { - res.market.returns <- c(res.market.returns, a$market.returns.purged) - res.innov <- rbind(res.innov, a$innov) - } else { - 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.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 -} - - -############################################ -## Summary, print and plot functions for AMM -############################################ -summary.amm <- function(object, ...) { - cat("\n", "Summary statistics of exposure: \n") - sstats <- cbind(object$exposure, object$s.exposure, - object$exposure/object$s.exposure) - colnames(sstats) <- c("Exposure", "Std.Err", "t statistic") - rownames(sstats) <- names(object$exposures) - print(sstats) - cat("\n","Linear model AMM results: ","\n"); - class(object) <- "lm"; - print.default(summary.default(object)) -} - -print.amm <- function(x, ...){ - cat("\n") - print(x$call) - cat("\n","Coefficients:","\n") - print(x$coef) - cat("\n","Exposures:","\n") - print.default(x$exposures) -} - -plot.amm <- function(x, ...){ - tmp.x <- zoo(as.numeric(resid(x)), as.Date(names(resid(x)))) - tmp.f <- zoo(x$model$firm.returns, index(tmp.x)) - tmp <- merge(tmp.x,tmp.f) - colnames(tmp) <- c("amm.residuals","firm.returns") - plot(tmp, screen=1, lty=1:2, lwd=2, col=c("indian red", "navy blue"),ylab="", - xlab="") - legend("topleft",legend=c("AMM residual","Firm returns"),lty=1:2, lwd=2, - col=c("indian red", "navy blue"), bty='n') -} From noreply at r-forge.r-project.org Wed Apr 2 18:26:27 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 2 Apr 2014 18:26:27 +0200 (CEST) Subject: [Eventstudies-commits] r278 - pkg/man Message-ID: <20140402162627.3C15C186C69@r-forge.r-project.org> Author: chiraganand Date: 2014-04-02 18:26:26 +0200 (Wed, 02 Apr 2014) New Revision: 278 Modified: pkg/man/eventstudy.Rd pkg/man/makeX.Rd pkg/man/phys2eventtime.Rd pkg/man/subperiod.lmAMM.Rd Log: Fixed the example code. Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2014-04-02 16:25:48 UTC (rev 277) +++ pkg/man/eventstudy.Rd 2014-04-02 16:26:26 UTC (rev 278) @@ -201,8 +201,8 @@ remap = "cumsum", inference = TRUE, inference.strategy = "bootstrap") -} print(es) plot(es) +} \keyword{eventstudy} Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2014-04-02 16:25:48 UTC (rev 277) +++ pkg/man/makeX.Rd 2014-04-02 16:26:26 UTC (rev 278) @@ -73,6 +73,6 @@ switch.to.innov = FALSE, market.returns.purge = FALSE, verbose = FALSE) +head(X) } -head(X) \keyword{makeX} Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-02 16:25:48 UTC (rev 277) +++ pkg/man/phys2eventtime.Rd 2014-04-02 16:26:26 UTC (rev 278) @@ -78,6 +78,6 @@ result <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) +str(result) } -str(result) \keyword{phys2eventime} Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-02 16:25:48 UTC (rev 277) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-02 16:26:26 UTC (rev 278) @@ -75,6 +75,6 @@ dates = as.Date(c("2012-02-01", "2013-01-01", "2014-01-20"))) +str(res) } -str(res) \keyword{subperiod.lmAMM} From noreply at r-forge.r-project.org Wed Apr 2 18:27:43 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 2 Apr 2014 18:27:43 +0200 (CEST) Subject: [Eventstudies-commits] r279 - pkg Message-ID: <20140402162743.68DEA186D4A@r-forge.r-project.org> Author: chiraganand Date: 2014-04-02 18:27:42 +0200 (Wed, 02 Apr 2014) New Revision: 279 Modified: pkg/DESCRIPTION Log: The necessary version bump. Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2014-04-02 16:26:26 UTC (rev 278) +++ pkg/DESCRIPTION 2014-04-02 16:27:42 UTC (rev 279) @@ -1,7 +1,7 @@ Package: eventstudies Type: Package Title: Event study analysis -Version: 1.1 +Version: 1.2 Date: 2014-03-28 Author: Chirag Anand, Vikram Bahure, Vimal Balasubramaniam, Ajay Shah Maintainer: Vikram Bahure From noreply at r-forge.r-project.org Wed Apr 2 20:48:49 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 2 Apr 2014 20:48:49 +0200 (CEST) Subject: [Eventstudies-commits] r280 - in pkg: R man Message-ID: <20140402184849.161EF186F26@r-forge.r-project.org> Author: chiraganand Date: 2014-04-02 20:48:48 +0200 (Wed, 02 Apr 2014) New Revision: 280 Modified: pkg/R/lmAMM.R pkg/man/subperiod.lmAMM.Rd Log: Reformatted lmAMM functions, modified text in subperiod manual. Modified: pkg/R/lmAMM.R =================================================================== --- pkg/R/lmAMM.R 2014-04-02 16:27:42 UTC (rev 279) +++ pkg/R/lmAMM.R 2014-04-02 18:48:48 UTC (rev 280) @@ -1,202 +1,4 @@ -############### -## 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 -######################## -manyfirmssubperiod.lmAMM <- -function(firm.returns,X, - lags,dates=NULL, periodnames=NULL,verbose=FALSE){ - if(is.null(dates)){ - dates=c(start(X),end(X)) - periodnames="Full" - } - nperiods <- length(periodnames) - if(length(dates) != (nperiods+1)){ - cat("Mistake in length of dates versus length of periods.\n") - return(NULL) - } - nfirms <- ncol(firm.returns) - - # Let's get "exposure' and 'sds'. Setting up structures:- - - exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(X)) - exposures <- as.data.frame(exposures) - rownames(exposures) <- colnames(firm.returns) - tmp <- NULL - for(i in 1:length(periodnames)){ - for(j in 1:NCOL(X)){ - tmp <- c(tmp, paste(colnames(X)[j], - periodnames[i],sep=".")) - } - } - colnames(exposures) <- tmp - sds <- exposures - colnames(sds) <- paste("sd",colnames(exposures),sep=".") - - # Setup a list structure for an OLS that failed - empty <- list(exposures=rep(NA,ncol(X)), - s.exposures=rep(NA,ncol(X))) - - for(i in 1:NCOL(firm.returns)){ - cat("AMM estimation for",colnames(firm.returns)[i],"\n") - if (verbose) {cat ("AMM estimation for", colnames(firm.returns)[i], "\n")} - stock.return <- firm.returns[,i] - dataset <- cbind(stock.return, X) # This is the full time-series - this.exp <- this.sds <- NULL - for(j in 1:nperiods){ # now we chop it up - t1 <- dates[j] - t2 <- dates[j+1] - this <- window(dataset,start=t1, end=t2) - fe <- lmAMM(this[,1],this[,-1],nlags=lags,verbose) - if(is.null(fe)) {fe <- empty} - this.exp <- c(this.exp, fe$exposures) - this.sds <- c(this.sds, fe$s.exposures) - } - exposures[colnames(firm.returns)[i],] <- this.exp - sds[colnames(firm.returns)[i],] <- this.sds - } - list(exposures=exposures, sds=sds, sig=exposures/sds) -} - -############################################### -## Estimating one firm's exposure in one period -############################################### -lmAMM <- function(firm.returns, X, nlags=NA, verbose=FALSE) { - do.ols <- function(nlags) { - 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) { - tmp <- cbind(tmp, lag(X[,i], -j)) - labels <- c(labels, paste(colnames(X)[i], j, sep=".")) - } - } - } - tmp <- na.omit(tmp) - if (nrow(tmp) < 30) { # refuse to do the work. - return(NULL) # returns out of do.ols() only - } - - colnames(tmp) <- labels # So the OLS results will look nice - lm(firm.returns ~ ., data=as.data.frame(tmp)) - } - - if (is.na(nlags)) { - if (verbose) {cat("Trying to find the best lag structure...\n")} - bestlag <- 0 - bestm <- NULL - bestAIC <- Inf - 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")} - if (thisAIC < bestAIC) { - bestlag <- trylag - bestAIC <- thisAIC - bestm <- thism - } - } - nlags <- bestlag - m <- bestm - } else { - m <- do.ols(nlags) - if (is.null(m)) {return(NULL)} - } - # In either event, you endup holding an "m" here. - if (verbose) {cat("\n\nThe OLS:\n"); print(summary(m))} - - # Compute a series of exposure measures, and their standard errors. - beta <- m$coefficients - Sigma <- vcovHAC(m) - # 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-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. - n.block2 <- length(beta) - n.block1 - (1 + nlags) - w <- c(rep(0, n.block1), rep(1, 1+nlags), rep(0, n.block2)) - exposures <- c(exposures, w %*% beta) - s.exposures <- c(s.exposures, sqrt(w %*% Sigma %*% w)) - } - } - results <- m - names(exposures) <- names(s.exposures) <- colnames(X) - results$exposures <- exposures - results$s.exposures <- s.exposures - results$nlags <- nlags - class(results) <- "amm" - return(results) -} - - -########################### -# Maintaining NAs in AR model -########################### +## Function to retain NA positions ARinnovations <- function(x) { stopifnot(NCOL(x) == 1) dt <- NULL @@ -215,9 +17,8 @@ list(result=result, m=m) } -# --------------------------------------------------------------------------- -# The workhorse called by makeX to return a nice matrix of RHS -# variables to be used in an analysis. +## The workhorse called by makeX to return a nice matrix of RHS +## variables to be used in an analysis. do.one.piece <- function(market.returns, others, switch.to.innov, market.returns.purge, nlags, verbose=FALSE) { thedates <- index(market.returns) if (verbose) { @@ -325,7 +126,192 @@ X } +## One regressor, one period AMM estimation +lmAMM <- function(firm.returns, X, nlags=NA, verbose=FALSE) { + do.ols <- function(nlags) { + 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) { + tmp <- cbind(tmp, lag(X[,i], -j)) + labels <- c(labels, paste(colnames(X)[i], j, sep=".")) + } + } + } + tmp <- na.omit(tmp) + if (nrow(tmp) < 30) { # refuse to do the work. + return(NULL) # returns out of do.ols() only + } + colnames(tmp) <- labels # So the OLS results will look nice + lm(firm.returns ~ ., data=as.data.frame(tmp)) + } + + if (is.na(nlags)) { + if (verbose) {cat("Trying to find the best lag structure...\n")} + bestlag <- 0 + bestm <- NULL + bestAIC <- Inf + 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")} + if (thisAIC < bestAIC) { + bestlag <- trylag + bestAIC <- thisAIC + bestm <- thism + } + } + nlags <- bestlag + m <- bestm + } else { + m <- do.ols(nlags) + if (is.null(m)) {return(NULL)} + } + # In either event, you endup holding an "m" here. + if (verbose) {cat("\n\nThe OLS:\n"); print(summary(m))} + + # Compute a series of exposure measures, and their standard errors. + beta <- m$coefficients + Sigma <- vcovHAC(m) + # 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-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. + n.block2 <- length(beta) - n.block1 - (1 + nlags) + w <- c(rep(0, n.block1), rep(1, 1+nlags), rep(0, n.block2)) + exposures <- c(exposures, w %*% beta) + s.exposures <- c(s.exposures, sqrt(w %*% Sigma %*% w)) + } + } + results <- m + names(exposures) <- names(s.exposures) <- colnames(X) + results$exposures <- exposures + results$s.exposures <- s.exposures + results$nlags <- nlags + class(results) <- "amm" + return(results) +} + +## One regressor, with sub periods. +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 regressors, many periods, one matrix of RHS +manyfirmssubperiod.lmAMM <- function(firm.returns,X, + lags,dates=NULL, periodnames=NULL,verbose=FALSE){ + if(is.null(dates)){ + dates=c(start(X),end(X)) + periodnames="Full" + } + nperiods <- length(periodnames) + if(length(dates) != (nperiods+1)){ + cat("Mistake in length of dates versus length of periods.\n") + return(NULL) + } + nfirms <- ncol(firm.returns) + + # Let's get "exposure' and 'sds'. Setting up structures:- + + exposures <- matrix(NA,nrow=nfirms,ncol=nperiods*ncol(X)) + exposures <- as.data.frame(exposures) + rownames(exposures) <- colnames(firm.returns) + tmp <- NULL + for(i in 1:length(periodnames)){ + for(j in 1:NCOL(X)){ + tmp <- c(tmp, paste(colnames(X)[j], + periodnames[i],sep=".")) + } + } + colnames(exposures) <- tmp + sds <- exposures + colnames(sds) <- paste("sd",colnames(exposures),sep=".") + + # Setup a list structure for an OLS that failed + empty <- list(exposures=rep(NA,ncol(X)), + s.exposures=rep(NA,ncol(X))) + + for(i in 1:NCOL(firm.returns)){ + cat("AMM estimation for",colnames(firm.returns)[i],"\n") + if (verbose) {cat ("AMM estimation for", colnames(firm.returns)[i], "\n")} + stock.return <- firm.returns[,i] + dataset <- cbind(stock.return, X) # This is the full time-series + this.exp <- this.sds <- NULL + for(j in 1:nperiods){ # now we chop it up + t1 <- dates[j] + t2 <- dates[j+1] + this <- window(dataset,start=t1, end=t2) + fe <- lmAMM(this[,1],this[,-1],nlags=lags,verbose) + if(is.null(fe)) {fe <- empty} + this.exp <- c(this.exp, fe$exposures) + this.sds <- c(this.sds, fe$s.exposures) + } + exposures[colnames(firm.returns)[i],] <- this.exp + sds[colnames(firm.returns)[i],] <- this.sds + } + list(exposures=exposures, sds=sds, sig=exposures/sds) +} + ############################################ ## Summary, print and plot functions for AMM ############################################ @@ -360,3 +346,5 @@ legend("topleft",legend=c("AMM residual","Firm returns"),lty=1:2, lwd=2, col=c("indian red", "navy blue"), bty='n') } + + Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-02 16:27:42 UTC (rev 279) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-02 18:48:48 UTC (rev 280) @@ -1,14 +1,14 @@ \name{subperiod.lmAMM} \alias{subperiod.lmAMM} -\title{Function to estimate exposure for a single firm over multiple periods} +\title{Estimate exposure for a single regressor over multiple periods} -\description{This function typically utilises a firm.returns vector and - an X matrix of explanatory variables obtained out of the - \sQuote{makeX} function. It computes the exposure for all columns in X - for the specified time periods. +\description{This function estimates exposure for a single regressor + over a set of regressands obtained by using \sQuote{makeX} + over multiple periods. } + \usage{ subperiod.lmAMM(firm.returns, X, @@ -19,37 +19,49 @@ } \arguments{ - \item{firm.returns}{a \sQuote{numeric} vector of data for one firm. + \item{firm.returns}{a \sQuote{numeric} vector of data for one + regressor (firm). } - \item{X}{a matrix of explanatory variables obtained from - the \sQuote{makeX()} function. The first variable is always the - stock market index. Other variables could be risk factors - such as currency or bond returns, or foreign portfolio inflows. + + \item{X}{a matrix of regressands obtained by using \sQuote{makeX}. + See \sQuote{Details} when this is specified as a market model. } - \item{nlags}{\sQuote{integer} of length 1, number of lags of explanatory - variables. When unspecified, the best lag using the AIC is used. + + \item{nlags}{specifies a lag length required from the specified set + of regressands. When unspecified, the best lag using the AIC is used. } + \item{verbose}{\sQuote{logical}, indicating whether the function should print detailed results. } - \item{dates}{object of \sQuote{Date} class, specifying the time period - to estimate exposures for. Default is \sQuote{NULL}. If no dates are - mentioned, \sQuote{subperiod.lmAMM} does what \sQuote{firmExposures()} - would do, i.e., estimate exposures for the full time period. + + \item{dates}{ a \sQuote{Date} class vector, specifying break points in + the time series to be used for sub-period identification. + The default value is \sQuote{NULL} resulting in estimates + identical to \sQuote{lmAMM}. } + \item{residual}{\sQuote{logical}, returns AMM residuals if TRUE, AMM - exposure otherwise. Defaults to \sQuote{TRUE}.} + exposure otherwise. Defaults to \sQuote{TRUE}.} } -\value{A \sQuote{list} of length 3 is returned: - \item{exposures}{AMM exposure} - \item{sds}{HAC adjusted standard errors} - \item{residuals}{an \sQuote{xts} object of the residuals from the fitted model} + +\details{ + When \sQuote{dates} is \sQuote{NULL}, resulting estimates from this + function is identical to \sQuote{lmAMM}. } +\value{A \sQuote{list} object of length 3 is returned with: + \itemize{ + \item{\dQuote{exposures}: A matrix of exposures by sub-period and regressands.} + \item{\dQuote{sds}: HAC adjusted standard errors for all exposures.} + \item{\dQuote{residuals}: Contain residuals of class \pkg{xts} from the + fitted model for all sub-periods.} + } +} + \author{Vimal Balasubramaniam} -\seealso{ \code{\link{lmAMM}}, -\code{\link{manyfirmssubperiod.lmAMM}}} +\seealso{ \code{\link{lmAMM}}} \examples{ data("AMMData") From noreply at r-forge.r-project.org Wed Apr 2 21:18:50 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 2 Apr 2014 21:18:50 +0200 (CEST) Subject: [Eventstudies-commits] r281 - pkg/man Message-ID: <20140402191850.C8202186B61@r-forge.r-project.org> Author: chiraganand Date: 2014-04-02 21:18:50 +0200 (Wed, 02 Apr 2014) New Revision: 281 Modified: pkg/man/lmAMM.Rd Log: Modified text. Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-02 18:48:48 UTC (rev 280) +++ pkg/man/lmAMM.Rd 2014-04-02 19:18:50 UTC (rev 281) @@ -3,10 +3,8 @@ \title{Augmented market model (AMM) estimation} -\description{\sQuote{lmAMM} is used to estimate augmented market - model. It can be used to estimate AMM and calculate augmented market - model residuals (AMM abnormal returns) stripped of market and macro - variations.} +\description{\sQuote{lmAMM} (linear augmented market models) estimates + exposure and residuals.} \usage{ lmAMM(firm.returns, X, nlags = NA, verbose = FALSE) @@ -14,8 +12,7 @@ \arguments{ - \item{firm.returns}{a \pkg{zoo} time series object of firm returns for - AMM estimation.} + \item{firm.returns}{a \pkg{zoo} time series object of firm returns.} \item{X}{a time series of explanatory variables obtained from the \sQuote{makeX} function. See \sQuote{Details}.} @@ -29,6 +26,7 @@ } +% FIXME: review/rewrite? \details{ The function relates firm returns to the regressors (market index movements, currency fluctuations etc.) using the linear model @@ -39,10 +37,10 @@ Function \sQuote{makeX} is used to prepare the explanatory variables (\dQuote{X}) used in the estimation of AMM. The first variable of \dQuote{X} is always the stock market index. Other variables could be - currency, bond returns, or other variables as required. + currency, bond returns, or any macro-economic indicator for example. - If \dQuote{nlags} is \sQuote{NA} (default), then the function tries to - find the best lag structure using the AIC. + If \dQuote{nlags} is \sQuote{NA} (default), then the function finds + the best lag structure using the AIC(n). \sQuote{lmAMM} calls the \code{stats::lm} to do the OLS. \sQuote{print} function on an object of \sQuote{class} @@ -51,22 +49,19 @@ \value{The function returns an object of \sQuote{class} \dQuote{amm}. - The functions \sQuote{summary} and \sQuote{print} are provided to - print a summary of results and print the \sQuote{lm} command, - coefficients, and exposures of the analysis. The function - \sQuote{plot} is provided to plot the model residuals and firm - returns. + Function \sQuote{summary} is provided to print a summary of + results. \sQuote{print} prints the coefficients and exposures of the + analysis. \sQuote{plot} plots the model residuals and firm returns. - An object of class \dQuote{amm} is a \sQuote{list} containing - the result of \code{stats::lm} function along with the following - components: + An object of class \dQuote{amm} is a \sQuote{list} containing the + output of \code{stats::lm} function which includes \dQuote{residuals}, + along with the following components: \item{exposures}{a \sQuote{numeric} containing exposure estimates for - the firm j.} + the firm.} \item{s.exposures}{a \sQuote{numeric} containing the HAC adjusted - standard error of the exposures estimated for the firm - with returns \sQuote{firm.returns}.} + standard error of the exposures estimated for the firm.} \item{nlags}{shows the lag length provided by user.} } From noreply at r-forge.r-project.org Thu Apr 3 12:04:54 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 3 Apr 2014 12:04:54 +0200 (CEST) Subject: [Eventstudies-commits] r282 - in pkg: R man Message-ID: <20140403100454.E0E61187311@r-forge.r-project.org> Author: chiraganand Date: 2014-04-03 12:04:54 +0200 (Thu, 03 Apr 2014) New Revision: 282 Modified: pkg/R/lmAMM.R pkg/R/phys2eventtime.R pkg/man/ees.Rd pkg/man/lmAMM.Rd pkg/man/makeX.Rd pkg/man/phys2eventtime.Rd pkg/man/subperiod.lmAMM.Rd Log: Changed the default nlags to NULL, modified structure/text of the manuals, fixed a bug in subperiod.lmAMM to handle xts. Made classes of return values consistent. Modified: pkg/R/lmAMM.R =================================================================== --- pkg/R/lmAMM.R 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/R/lmAMM.R 2014-04-03 10:04:54 UTC (rev 282) @@ -2,7 +2,7 @@ ARinnovations <- function(x) { stopifnot(NCOL(x) == 1) dt <- NULL - if (class(x) == "zoo") { + if (any(c("xts","zoo") %in% class(x))) { dt <- index(x) x <- as.numeric(x) } @@ -127,7 +127,7 @@ } ## One regressor, one period AMM estimation -lmAMM <- function(firm.returns, X, nlags=NA, verbose=FALSE) { +lmAMM <- function(firm.returns, X, nlags=NULL, verbose=FALSE) { do.ols <- function(nlags) { tmp <- cbind(firm.returns, X[,1]) # Assume 1st is stock index, and no lags are required there. labels <- c("firm.returns","market.returns") @@ -148,13 +148,14 @@ lm(firm.returns ~ ., data=as.data.frame(tmp)) } - if (is.na(nlags)) { - if (verbose) {cat("Trying to find the best lag structure...\n")} + if (is.null(nlags)) { + if(verbose) {cat("Trying to find the best lag structure...\n")} bestlag <- 0 bestm <- NULL bestAIC <- Inf for (trylag in 0:min(10,log10(length(firm.returns)))) { thism <- do.ols(trylag) + if (is.null(m)) {return(NULL)} thisAIC <- AIC(thism, k=log(length(thism$fitted.values))) if (verbose) {cat(trylag, " lags, SBC = ", thisAIC, "\n")} if (thisAIC < bestAIC) { @@ -346,5 +347,3 @@ legend("topleft",legend=c("AMM residual","Firm returns"),lty=1:2, lwd=2, col=c("indian red", "navy blue"), bty='n') } - - Modified: pkg/R/phys2eventtime.R =================================================================== --- pkg/R/phys2eventtime.R 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/R/phys2eventtime.R 2014-04-03 10:04:54 UTC (rev 282) @@ -37,7 +37,7 @@ return(list(result=remapped, outcome="success")) } - answer <- apply(events, 1, timeshift) + answer <- apply(events, 1, timeshift) #this thing loops on num events answer <- unlist(answer, recursive = FALSE) rownums <- grep("outcome", names(answer)) outcomes <- as.character(do.call("c", answer[rownums])) Modified: pkg/man/ees.Rd =================================================================== --- pkg/man/ees.Rd 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/man/ees.Rd 2014-04-03 10:04:54 UTC (rev 282) @@ -1,14 +1,15 @@ \name{ees} \alias{ees} -\title{ -Extreme events study analysis: Summary statistics +\title{ Summary statistics of extreme events } + +\description{ + This function generates summary statistics for identification and + analysis of extreme events. } -\description{ This function generates summary statistics table from Patnaik, Shah and Singh (2013), using a univariate time series.} - \usage{ -ees(input, prob.value) + ees(input, prob.value) } \arguments{ Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/man/lmAMM.Rd 2014-04-03 10:04:54 UTC (rev 282) @@ -7,60 +7,63 @@ exposure and residuals.} \usage{ -lmAMM(firm.returns, X, nlags = NA, verbose = FALSE) + lmAMM(firm.returns, X, nlags = NULL, verbose = FALSE) } \arguments{ + \item{firm.returns}{a \sQuote{zoo} vector of data for one + regressor (firm). + } - \item{firm.returns}{a \pkg{zoo} time series object of firm returns.} + \item{X}{a matrix of regressors obtained by using \sQuote{makeX}. + See \sQuote{Details} when this is specified as a market model. + } + + \item{nlags}{specifies a lag length required from the specified set + of regressors. When unspecified, the best lag using the AIC is used. + } - \item{X}{a time series of explanatory variables obtained from the - \sQuote{makeX} function. See \sQuote{Details}.} - - \item{nlags}{an \sQuote{integer} with the number of lags of - explanatory variables.} - - \item{verbose}{\sQuote{logical}. Print function details. If - \sQuote{TRUE}, print detailed results while running. Default is - \sQuote{FALSE}.} - + \item{verbose}{\sQuote{logical}. If \sQuote{TRUE}, prints details of + piece-wise analysis.} } -% FIXME: review/rewrite? \details{ - The function relates firm returns to the regressors (market - index movements, currency fluctuations etc.) using the linear model - \sQuote{lm}. It computes firm exposure for all the regressors in - columns of \dQuote{X} and subsequently estimates AMM residuals by - purging out variation from the regressand. + This function estimates a linear regression model with multiple + variables using \sQuote{lm}, stores coefficients as + \sQuote{exposures}, and HAC adjusted standard errors as \sQuote{s.exposures}. - Function \sQuote{makeX} is used to prepare the explanatory variables - (\dQuote{X}) used in the estimation of AMM. The first variable of - \dQuote{X} is always the stock market index. Other variables could be - currency, bond returns, or any macro-economic indicator for example. + This function is the core engine for other functions that estimate + AMMs. Each regression is expected in this package to have a minimum of + 30 observations, a condition that translates into a month of + daily data. If the total number of observations is less than 30, the + function returns \sQuote{NULL}. + + Function \sQuote{makeX} is used to obtain a matrix of regressors used + as input for \sQuote{X}. - If \dQuote{nlags} is \sQuote{NA} (default), then the function finds + If \dQuote{nlags} is \sQuote{NULL}, then the function finds the best lag structure using the AIC(n). - \sQuote{lmAMM} calls the \code{stats::lm} to do the - OLS. \sQuote{print} function on an object of \sQuote{class} + \sQuote{lmAMM} calls \code{stats::lm} to estimate the linear model. + \sQuote{print} function on an object of \sQuote{class} \dQuote{amm} can be used to see the call (formula) to \code{lm}. } -\value{The function returns an object of \sQuote{class} \dQuote{amm}. +\value{The function returns an object of \sQuote{class} + \dQuote{amm}; \sQuote{NULL} if \code{nrow(firm.returns) < 30}. Function \sQuote{summary} is provided to print a summary of results. \sQuote{print} prints the coefficients and exposures of the analysis. \sQuote{plot} plots the model residuals and firm returns. An object of class \dQuote{amm} is a \sQuote{list} containing the - output of \code{stats::lm} function which includes \dQuote{residuals}, + output of \code{stats::lm} (which includes \dQuote{residuals}), along with the following components: \item{exposures}{a \sQuote{numeric} containing exposure estimates for the firm.} - \item{s.exposures}{a \sQuote{numeric} containing the HAC adjusted + \item{s.exposures}{a \sQuote{numeric} containing HAC adjusted standard error of the exposures estimated for the firm.} \item{nlags}{shows the lag length provided by user.} @@ -88,6 +91,7 @@ verbose = FALSE) a <- lmAMM(firm.returns, X, nlags = 0, verbose = FALSE) + print(a) } Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/man/makeX.Rd 2014-04-03 10:04:54 UTC (rev 282) @@ -1,10 +1,10 @@ \name{makeX} \alias{makeX} -\title{Prepare explanatory variables for computation of Augmented Market +\title{Prepare regressors for computation of Augmented Market Models} -\description{\sQuote{makeX} is used to prepare explanatory variables for +\description{\sQuote{makeX} is used to prepare regressors for computation of Augmented Market Models. It can be used to create a matrix of explanatory variables in the form specified by the user for estimation of AMM.} @@ -22,44 +22,56 @@ \arguments{ \item{market.returns}{a univariate timeseries object of \sQuote{class} - \pkg{zoo}. It is generally fixed to the stock market index.} + \pkg{zoo}. In market models, this is normally the returns of a + stock market index.} - \item{others}{a \pkg{zoo} matrix with other regressors of interest in the - AMM. This could be currency, bond returns, foreign flows, or any - other variable.} + \item{others}{a \pkg{zoo} matrix of other regressors for the multiple + regression model.} \item{switch.to.innov}{a \sQuote{logical} vector with an element for each column in \dQuote{others} specifying whether to switch the - column from raw values to AR residuals. Default is \sQuote{TRUE} for - all the columns.} + column from raw values to auto-regressive residuals. Default is \sQuote{TRUE} for + all the columns. See \sQuote{Details}.} \item{market.returns.purge}{a \sQuote{logical} indicating whether to purge the effects of \dQuote{others} from - \dQuote{market.returns}.} + \dQuote{market.returns}. See \sQuote{Details}.} - \item{nlags}{The number of lag terms present in this model explaining - \dQuote{market.returns} using all these \dQuote{others}.} + \item{nlags}{ a integer specifying the number of lags required when + \sQuote{market.returns.purge} is \sQuote{TRUE}.} - \item{dates}{Specified break dates as \sQuote{Date} object.} + \item{dates}{ a \sQuote{Date} vector, default set to \sQuote{NULL}, + specifying breaks. See \sQuote{Details}.} - \item{verbose}{Whether detailed output is required. Default is - \sQuote{FALSE}.} + \item{verbose}{ a \sQuote{logical} value, with the default being + \sQuote{FALSE}, specifying whether detailed output is required.} + } -\details{ Augmented market model (AMM) purges out the variation of market returns and variable of interest as specified in \sQuote{others}, from the dependent variable. This function creates the regressors for the AMM model using market returns and \sQuote{others}. +\details{ + This function prepares the regressors of interest for the purpose of + running aumgmented market models. + The \sQuote{logical} vector \sQuote{switch.to.innov} is applicable + only to the regressors in \sQuote{others} matrix and not to the time + series vector in \sQuote{market.returns}. + + When \sQuote{market.returns.purge} is \sQuote{TRUE}, residuals from a + regression of \sQuote{market.returns} on \sQuote{others} is + obtained. If \sQuote{dates} are provided, this regression is done + within sub-periods as identified by the \sQuote{dates} vector. When + \sQuote{dates} is set to default value of \sQuote{NULL}, the start and + end points of \sQuote{market.returns} is taken as the period for + estimation. } \section{Warning}{The input data should not contain \sQuote{NA}s, as is - required by the \dQuote{lm} function to compute linear estimates. Please use + required by the \dQuote{lm} function to estimate a linear regression. Please use \sQuote{na.omit} before feeding data into this function.} -\value{This function generates a user specified matrix of explanatory - variables that will be further used in running Augmented market - models.} +\value{a time-series object of regressors is returned.} - \author{Ajay Shah, Vimal Balasubramaniam} \examples{ Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/man/phys2eventtime.Rd 2014-04-03 10:04:54 UTC (rev 282) @@ -55,7 +55,7 @@ \value{ Returns a \sQuote{list} of two elements: - \item{z.e}{a \pkg{zoo}/\pkg{xts} object indexed with event time; \dQuote{NULL} if + \item{z.e}{a \pkg{zoo} object indexed with event time; \dQuote{NULL} if there are no \dQuote{success} in \dQuote{outcomes}.} \item{outcomes}{a character vector with outcome definition for each event.} Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-02 19:18:50 UTC (rev 281) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-03 10:04:54 UTC (rev 282) @@ -19,7 +19,7 @@ } \arguments{ - \item{firm.returns}{a \sQuote{numeric} vector of data for one + \item{firm.returns}{a \sQuote{zoo} vector of data for one regressor (firm). } From noreply at r-forge.r-project.org Thu Apr 3 17:19:51 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 3 Apr 2014 17:19:51 +0200 (CEST) Subject: [Eventstudies-commits] r283 - pkg/R Message-ID: <20140403151951.B3B8E1868BA@r-forge.r-project.org> Author: chiraganand Date: 2014-04-03 17:19:51 +0200 (Thu, 03 Apr 2014) New Revision: 283 Modified: pkg/R/eventstudy.R pkg/R/marketResidual.R pkg/R/remap.cumprod.R pkg/R/remap.cumsum.R Log: Moved functions around. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2014-04-03 10:04:54 UTC (rev 282) +++ pkg/R/eventstudy.R 2014-04-03 15:19:51 UTC (rev 283) @@ -2,7 +2,7 @@ eventList, width = 10, is.levels = FALSE, - type = "marketResidual", + type = "None", to.remap = TRUE, remap = "cumsum", inference = TRUE, @@ -71,7 +71,7 @@ index(outputModel) <- as.Date(index(outputModel)) ### Convert to event frame - es <- phys2eventtime(z=outputModel, events=eventList, width=width) + es <- phys2eventtime(z=outputModel, events=eventList, width=0) if (is.null(es$z.e) || length(es$z.e) == 0) { es.w <- NULL Modified: pkg/R/marketResidual.R =================================================================== --- pkg/R/marketResidual.R 2014-04-03 10:04:54 UTC (rev 282) +++ pkg/R/marketResidual.R 2014-04-03 15:19:51 UTC (rev 283) @@ -8,34 +8,37 @@ ## Value: Market residual after extracting market returns from the firm return marketResidual <- function(firm.returns, market.returns){ + mm.residual <- function(y,x){ + ## Identify start and end date + startdate <- start(x) + enddate <- end(x) + + fulldata <- merge(x,y,all=TRUE) + fulldata <- window(fulldata,start=startdate,end=enddate) + + ## Storing NA observations + non.na.loc <- complete.cases(fulldata) + fulldata <- fulldata[complete.cases(fulldata),] + colnames(fulldata) <- c("x","y") + reg <- lm(y ~ x, data = fulldata) + + result <- rep(NA,length(non.na.loc)) + result[non.na.loc] <- reg$residuals + result <- zoo(result,order.by=index(x)) + result + } + ## 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) + result <- NULL + for(i in 1:NCOL(firm.returns)){ + res <- mm.residual(y=firm.returns[,i],x=market.returns) + result <- merge(result,res,all=TRUE) } colnames(result) <- colnames(firm.returns) } else { - result <- mm.residual(firm.returns, market.returns) + result <- mm.residual(y=firm.returns,x=market.returns) } - result <- zoo(result) return(result) } -mm.residual <- function(firm.returns, market.returns){ - ## Storing NA observations - 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/R/remap.cumprod.R =================================================================== --- pkg/R/remap.cumprod.R 2014-04-03 10:04:54 UTC (rev 282) +++ pkg/R/remap.cumprod.R 2014-04-03 15:19:51 UTC (rev 283) @@ -5,7 +5,7 @@ # values are like "0.01" for 1% # is.returns is false in this case is.pc is ignored! # values are like 1.01 for 1% -remap.cumprod <- function(z, is.pc=TRUE, is.returns=TRUE, base=100) { +remap.cumprod <- function(z, is.pc=FALSE, is.returns=TRUE, base=100) { z <- firstValueZero(z) for (i in 1:NCOL(z)) { tmp <- z[,i] Modified: pkg/R/remap.cumsum.R =================================================================== --- pkg/R/remap.cumsum.R 2014-04-03 10:04:54 UTC (rev 282) +++ pkg/R/remap.cumsum.R 2014-04-03 15:19:51 UTC (rev 283) @@ -1,6 +1,6 @@ # If is.pc then a value like "1" means 0.01 -remap.cumsum <- function(z, is.pc=TRUE, base=0) { +remap.cumsum <- function(z, is.pc=FALSE, base=0) { z <- firstValueZero(z) for (i in 1:NCOL(z)) { tmp <- z[,i] From noreply at r-forge.r-project.org Thu Apr 3 17:20:27 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 3 Apr 2014 17:20:27 +0200 (CEST) Subject: [Eventstudies-commits] r284 - pkg/man Message-ID: <20140403152027.F3793186B83@r-forge.r-project.org> Author: chiraganand Date: 2014-04-03 17:20:27 +0200 (Thu, 03 Apr 2014) New Revision: 284 Modified: pkg/man/ees.Rd pkg/man/eesPlot.Rd pkg/man/eventstudy.Rd pkg/man/excessReturn.Rd pkg/man/lmAMM.Rd pkg/man/manyfirmssubperiod.lmAMM.Rd pkg/man/marketResidual.Rd pkg/man/remap.cumprod.Rd pkg/man/remap.cumsum.Rd pkg/man/remap.event.reindex.Rd pkg/man/subperiod.lmAMM.Rd Log: Content and formatting improved. Modified: pkg/man/ees.Rd =================================================================== --- pkg/man/ees.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/ees.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -14,48 +14,86 @@ \arguments{ - \item{input}{a univariate \pkg{zoo} or \pkg{xts} time series for which - tail events identification is required.} - - \item{prob.value}{The cut off (in per cent) on the probability - distribution for the tail event.} + \item{input}{a univariate \pkg{zoo} or \pkg{xts} time series object} + + \item{prob.value}{The value (in percent) on the probability + distribution to define a tail event.} } -\details{ Patnaik, Shah and Singh (2013) uses modified event study methodology in the paper, which is used to understand the impact of extreme tail events on a given variable (foreign investment, stock market returns in this case). Event dates are defined as those on which extreme values of returns or flows are observed. The argument \sQuote{prob.value} defines the extreme tail values on both side of the distribution as event dates. For instance, if \sQuote{prob.value} is 2.5 then it will consider 2.5 percent tail values on both side of the empirical distribution of the variable as event dates. The paper further differentiates between clustered events (consecutive extreme events) and unclustered events which is described in detail in summary tables. -This function helps to understand the various feature of the event dates by providing following summary statistics: - \itemize{ - \item \dQuote{Distribution of extreme events}: Number of events in clustered, unclustered and events used and discarded from the analysis - \item \dQuote{Run length distribution}: Table shows number of clustered events with a particular run length - \item \dQuote{Quantile values}: Quantile wise distribution of extreme events - \item \dQuote{Yearly distribution}: Year wise distribution of extreme events - } - Please refer to Patnaik, Shah and Singh (2013) for more detailed explanation. +\details{ + Tail (Rare) events are often the object of interest in finance. These + events are defined as those that have a low probability of + occurrence. This function identifies such events based on + \sQuote{prob.value} mentioned by the user and generates summary + statistics about the events. If \sQuote{prob.value} is 2.5\%, events + below 2.5\% (lower tail) and above 97.5\% (upper tail) of the + distribution are identified as extreme events. + + Following statistics is generated for both lower and upper tail + events: + + \itemize{ + \item \sQuote{extreme.event.distribution} provides summary + statistics on the number of consecutive events (\dQuote{clustered} + events) and those that are not (\dQuote{unclustered} + events). Consecutive events that are \dQuote{mixed}, i.e., with + upper (lower) tail event occurring after a lower (upper) tail event, + are classified separately. + + \item \sQuote{runlength}: When events are \dQuote{clustered}, + \sQuote{runlength} classifies such clusters into different duration + bins. + + \item \sQuote{quantile.values}: Within such events, + \sQuote{quantile.values} provide the probability distribution values + at 0\%, 25\%, 50\%, 75\% and 100\%, alongside the mean. + + \item \sQuote{yearly.extreme.event}: A year-wise tabulation of such + extreme events, with a clustered event taken as one event. + } } \value{ A \code{list} object containing: \item{data.summary}{a \sQuote{data.frame} containing summary of - the data set.} + the data set minimum, maximum, inter-quartile range, mean, median, + standard deviation and quantile values at 5\%, 25\%, 75\% and 95\%.} - \item{lower.tail}{a \sQuote{list} containing: distribution of extreme - events, run length distribution, quantile values, yearly - distribution, and the tail events data.} + \item{lower.tail}{a \sQuote{list} that contains + \sQuote{extreme.event.distribution}, \sQuote{runlength}, + \sQuote{quantile.values} and \sQuote{yearly.extreme.event} for the + events on the lower tail of the distribution. See + \sQuote{Details}.} - \item{upper.tail}{a \sQuote{list} containing: distribution of extreme - events, run length distribution, quantile values, yearly - distribution, and the tail events data.} + \item{upper.tail}{a \sQuote{list} that contains + \sQuote{extreme.event.distribution}, \sQuote{runlength}, + \sQuote{quantile.values} and \sQuote{yearly.extreme.event} for the + events on the upper tail of the distribution. See + \sQuote{Details}.} } -\references{To convert number to words, code uses function +\references{ + Ila Patnaik, Nirvikar Singh and Ajay Shah (2013). + Foreign Investors under stress: Evidence from + India. \emph{International Finance}, \bold{16(2)}, 213-244. + URL + http://onlinelibrary.wiley.com/doi/10.1111/j.1468-2362.2013.12032.x/abstract + and also available at http://macrofinance.nipfp.org.in/releases/PatnaikShahSingh2013_Foreign_Investors.html + + To convert number to words, code uses function \href{http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46843.html}{\dQuote{numbers2words}} by \href{http://socserv.mcmaster.ca/jfox/}{John Fox} and \dQuote{deprintize} function by \href{http://mbq.me/}{Miron Kursa}. + } \author{Vikram Bahure} + + \examples{ library(eventstudies) data(EESData) -input <- EESData$sp500 -output <- ees(input, prob.value = 5) +input <- EESData$sp500 ## Input S&P 500 as the univariate series +output <- ees(input, prob.value = 5) ## Estimate 5\% tails. +str(output) } Modified: pkg/man/eesPlot.Rd =================================================================== --- pkg/man/eesPlot.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/eesPlot.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,11 +1,10 @@ \name{eesPlot} \alias{eesPlot} -\title{ -Extreme event study analysis: Plotting clustered and unclustered extreme events returns -} +\title{Plotting clustered and unclustered extreme events} -\description{ This function uses modified event study methodology from Patnaik, Shah and Singh (2013) to plot the impact of event series on the response series. +\description{ This function plots an event study with extreme events + as identified by the function \sQuote{ees}. } \usage{ @@ -20,35 +19,53 @@ \arguments{ - \item{z}{Data object with both response and event series on which - event study is to be performed.} + \item{z}{a time series object with the response and event series.} - \item{response.series.name}{Column name of the series in \sQuote{z} on which - response is to be observed.} + \item{response.series.name}{Column name of the series in \sQuote{z} + that will be the \sQuote{outcome} or \sQuote{response} series.} - \item{event.series.name}{Column name of the series in \sQuote{z} on which - event is to be defined.} + \item{event.series.name}{Column name of the series in \sQuote{z} that + will be the \sQuote{event} series.} - \item{titlestring}{Title for event study plot.} + \item{titlestring}{Title for event study plot} - \item{ylab}{Y-axis label of the plot.} + \item{ylab}{Y-axis label of the plot} - \item{width}{Width for event study plot.} + \item{width}{Time window before and after the event to be plotted} \item{prob.value}{Cut-off values in the probability distribution (in - percentage terms).} + percentage terms) to identify extreme events.} } -\details{Patnaik, Shah, and Singh (2013) use modified event study methodology to draw the event study plot. The function draws the event dates from the tail of the event series. Extreme events are then formatted by fusing the consecutive events on same side of the tail into one event, further fusing the response series on a clustered event and removing the mixed clusters (consecutive events from left and right tails). After formatting the events, response series is converted to event time frame and mean response is constructed for all event dates. The function also estimates confidence interval using bootstrap inference strategy. +\details{ + This function draws from many different functions in the package: + \itemize{ + \item Identify extreme events based on \sQuote{prob.value} on the + series named \sQuote{event.series.name} in \sQuote{z}, similar to + the function \code{ees}; + + \item Treats clusters in the events identified as one event by + cumulating the series named \sQuote{response.series.name} in + \sQuote{z} for the period in the cluster; -The paper defines extreme tail events as event dates and the argument \sQuote{prob.value} is used for the same. The function using the argument \sQuote{event.series.name} picks a column from the data object \sQuote{z}, which is used to extract extreme event dates. While, argument \sQuote{response.series.name} gets the response series on which impact of the extreme event dates is to be analysed. + \item Obtains confidence intervals using \code{inference.bootstrap} + and the presents the anaylsis in a graph. + } -Please refer to the paper Patnaik, Shah and Singh (2013) for detailed explanation. } \value{A plot of the response series with lower and upper tail events defined on the event series.} +\references{ + Ila Patnaik, Nirvikar Singh and Ajay Shah (2013). + Foreign Investors under stress: Evidence from + India. \emph{International Finance}, \bold{16(2)}, 213-244. + URL + http://onlinelibrary.wiley.com/doi/10.1111/j.1468-2362.2013.12032.x/abstract + and also available at http://macrofinance.nipfp.org.in/releases/PatnaikShahSingh2013_Foreign_Investors.html +} + \examples{ library(eventstudies) data(EESData) Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/eventstudy.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,13 +1,14 @@ \name{eventstudy} \alias{eventstudy} -\title{Function for performing event study analysis} +\title{Event study analysis} \description{ - %% FIXME - \sQuote{eventstudy} performs event study analysis. It calculates - returns using a specified model, converts physical dates to event - frame, and conducts inference on the unit of interest. + \sQuote{eventstudy} provides a easy interface that integrates all + functionalities of package \pkg{eventstudies} to undertake event study + analysis. It allows the user to specify the type of data adjustment + to be done (using the augmented market model functionalities of the + package) and then an inference strategy of choice. } \usage{ @@ -25,60 +26,68 @@ \arguments{ \item{firm.returns}{ - a \pkg{zoo} timeseries on which event study is to be performed. + a \pkg{zoo} matrix of \sQuote{outcome} or \sQuote{response} series. } \item{eventList}{ - \sQuote{data.frame} of two columns containing event dates to pass to - \code{\link{phys2eventtime}} function. \dQuote{outcome.unit} - consists of column names of series inside \dQuote{firm.returns}, and - \dQuote{event.when} is the respective event date. + a \code{data.frame} of two columns with event dates (with the column + name \dQuote{event.when}) and column names + of the \sQuote{response} series from \sQuote{firm.returns} (with the + column name \dQuote{outcome.unit}. } - \item{width}{integer of length 1, creates an event window to - study the impact (pre and post event) on the variable.} + \item{width}{an \sQuote{integer} of length 1 that specifies a + symmetric event window around the event date. + } \item{type}{ - a scalar of type \sQuote{character} specifying the market - model adjustment. See \sQuote{Details}. + a scalar of type \sQuote{character} specifying the type of data + adjustment required before conducting an event study analysis. See + \sQuote{Details}. } - \item{to.remap}{\sQuote{logical}, indicating whether to convert - event-window returns into cumulative sum, cumulative product, or - re-index.} + \item{to.remap}{\sQuote{logical}, indicating whether or not to remap + the data in \sQuote{firm.returns}. + } \item{remap}{ - \sQuote{character}, conversion function for remapping event-window - returns. Used when \dQuote{to.remap} is \sQuote{TRUE}. - } + \sQuote{character}, indicating the type of remap required, + \dQuote{cumsum}, \dQuote{cumprod}, or \dQuote{reindex}. Used when + \sQuote{to.remap} is \sQuote{TRUE}. + } \item{is.levels}{ - \sQuote{logical}, indicating the format of the data. Set it to - \sQuote{FALSE} if the data is in returns format, else \sQuote{TRUE}. + \sQuote{logical}, indicating whether data in \sQuote{firm.returns} + needs to be converted into percentage returns. If + \sQuote{TRUE}, \sQuote{firm.returns} will be converted into + percentage returns. } - %% FIXME: do you compute confidence interval or use it for computing? + \item{inference}{ - \sQuote{logical}, specifying whether to compute confidence interval - for the estimator. + \sQuote{logical}, specifying whether to undertake statistical + inference and compute confidence intervals. The default setting is + \sQuote{TRUE}. } \item{inference.strategy}{a \sQuote{character} scalar specifying the - inference strategy to compute confidence intervals. Is used only if - \dQuote{inference} is \sQuote{TRUE}. Currently supported options are - \dQuote{bootstrap} and \dQuote{wilcox}. Defaults to \dQuote{bootstrap}.} - + inference strategy to be used for estimating the confidence + interval. Presently, two methods are available: \dQuote{bootstrap} + and \dQuote{wilcox}. + } + \item{...}{ - further arguments to pass to the model. + All other arguments to be passed depends on whether \sQuote{type} + is \dQuote{marketResidual}, \dQuote{excessReturn}, or + \dQuote{lmAMM}. When \dQuote{None}, no additional arguments will be + needed. See \sQuote{Details}. } } \details{ + \dQuote{firm.returns} can contain only one series. To study a single + series, use \sQuote{[} with \code{drop = FALSE} for subsetting the + data set. See \code{\link{phys2eventtime}} for more details. - \dQuote{firm.returns} may contain only one series. For performing - analysis for a single series, use \sQuote{[} with \code{drop = - FALSE} for subsetting the data set. See \code{\link{phys2eventtime}} - for more details. - \dQuote{type} currently supports: \itemize{ \item{\dQuote{marketResidual}: uses \code{\link{marketResidual}} @@ -91,8 +100,9 @@ \item{\dQuote{lmAMM}: uses \code{\link{lmAMM}} to perform Augmented Market Model estimation.} - \item{\dQuote{None}: don't use any model.} + \item{\dQuote{None}: does not use any model.} } + Arguments to a model type can be sent inside \sQuote{...}. See \sQuote{Model arguments} section for details on accepted fields. @@ -100,9 +110,9 @@ \itemize{ \item \dQuote{cumsum}: cumulative sum, uses \code{\link{remap.cumsum}}. [Default] \item \dQuote{cumprod}: cumulative product, buy-hold-abnormal-return (BHAR), - uses \code{\link{remap.cumprod}}. + uses \code{\link{remap.cumprod}}. \item \dQuote{reindex}: re-indexes the event window by using - \code{\link{remap.event.reindex}}. + \code{\link{remap.event.reindex}}. } For computing confidence intervals, the function can either use @@ -113,13 +123,16 @@ \sQuote{...} is directly supplied to the model mentioned in the \dQuote{type} argument. See section on \sQuote{Model arguments} for more details. + + The argument \sQuote{width} in \code{\link{phys2eventtime}} has been + set to zero. } \section{\bold{Model arguments}}{ Each model can take extra arguments (supplied as \sQuote{...}) apart from mandatory ones for finer control over the analysis. Check the - respective function documentation for definitions. The arguments are - listed here: + respective function documentation for definitions. The arguments from + the relevant functions are listed here: \itemize{ \item \dQuote{marketResidual}: \cr @@ -137,24 +150,28 @@ } } - \value{ A list with class attribute \dQuote{es} holding the following elements: \item{eventstudy.output}{ - a \sQuote{matrix} containing mean/median estimate with - confidence interval; \sQuote{NULL} if there are no \dQuote{success} - \dQuote{outcomes}. + a \sQuote{matrix} containing mean (bootstrap) or median (with + wilcoxon) estimate with confidence interval; \sQuote{NULL} if there + are no \dQuote{success} \dQuote{outcomes}. } - \item{outcomes}{a character vector having outcome of each event date:} - - \itemize{ - \item{success: shows the successful use of event date.} - \item{wdatamissing: appears when width data is missing around the event.} - \item{wrongspan: if event date falls outside the range of physical date.} - \item{unitmissing: when the unit (firm name) is missing in the event list.} + \item{outcomes}{a character vector that is the output from + \code{\link{phys2eventtime}} containing details of the successful use + of an event: + + \itemize{ + \item{success: shows the successful use of event date.} + \item{wdatamissing: appears when width data is missing around the + event. This will not appear when this function is used since the + argument \sQuote{width} in \code{\link{phys2eventtime}} is set to zero.} + \item{wrongspan: if event date falls outside the range of physical date.} + \item{unitmissing: when the unit (firm name) is missing in the event list.} + } } \item{inference}{ @@ -170,7 +187,6 @@ a \sQuote{character} specifying the remapping technique used. Options are mentioned in \dQuote{remap} argument description. } - } \author{Vikram Bahure} @@ -201,8 +217,7 @@ remap = "cumsum", inference = TRUE, inference.strategy = "bootstrap") -print(es) -plot(es) +str(es) } \keyword{eventstudy} Modified: pkg/man/excessReturn.Rd =================================================================== --- pkg/man/excessReturn.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/excessReturn.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,18 +1,21 @@ \name{excessReturn} \alias{excessReturn} -\title{Estimate excess returns} +\title{Estimate excess returns over the market} -\description{ This function estimates excess returns. If the firm return - is \dQuote{firm.returns} and market return is \dQuote{market.returns}, - then output will be \dQuote{firm.returns} less - \dQuote{market.returns}. } +\description{ + This function estimates excess returns over the market. If the firm + return is \dQuote{firm.returns} and market return is + \dQuote{market.returns}, then output will be \dQuote{firm.returns} + less \dQuote{market.returns}. +} \usage{excessReturn(firm.returns, market.returns)} \arguments{ \item{firm.returns}{a \pkg{zoo} timeseries with firm returns from which excess returns from market are to be calculated.} + \item{market.returns}{a \pkg{zoo} object containing market index returns.} } Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/lmAMM.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -11,7 +11,7 @@ } \arguments{ - \item{firm.returns}{a \sQuote{zoo} vector of data for one + \item{firm.returns}{a univariate \sQuote{zoo} object of data for one regressor (firm). } Modified: pkg/man/manyfirmssubperiod.lmAMM.Rd =================================================================== --- pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,11 +1,12 @@ \name{manyfirmssubperiod.lmAMM} \alias{manyfirmssubperiod.lmAMM} -\title{Compute AMM for multiple firms across several periods} +\title{Estimate exposure for multiple regressors over multiple periods.} -\description{This function runs AMM for multiple firms at once using - the matrix of data obtained from \code{makeX}, and a matrix of LHS - variables.} +\description{\code{\link{manyfirmssubperiod.lmAMM}} estimates exposure + for multiple regressands over a set of regressors obtained by using + \sQuote{makeX} over multiple periods. + } \usage{ manyfirmssubperiod.lmAMM(firm.returns, @@ -17,32 +18,39 @@ } \arguments{ + \item{firm.returns}{a \sQuote{zoo} matrix of data for multiple + regressands (firms). + } - \item{firm.returns}{A \pkg{zoo} object of all firms on which AMM is to be - run.} - - \item{X}{a \pkg{zoo} object containing at least two regressors - generally obtained after applying the \dQuote{makeX} function.} - + \item{X}{a matrix of regressors obtained by using \sQuote{makeX}. + } + \item{lags}{an integer specifying 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 \sQuote{NULL}, then full period is considered.} + \item{dates}{ a \sQuote{Date} class vector, specifying break points in + the time series to be used for sub-period identification. + The default value is \sQuote{NULL} resulting in estimates + identical to \sQuote{lmAMM} used over multiple regressands. + } \item{periodnames}{a \sQuote{character} vector of names for each subperiod that has been marked by the \dQuote{dates} argument.} - \item{verbose}{Whether to print detailed output. Default is \sQuote{FALSE}} + \item{verbose}{\sQuote{logical}, indicating whether the function + should print detailed results. + } } -%% FIXME: \details section! -%% steps: -%% - calculates exposures and SDS -%% - runs AMM for each subperiod for each firm +\details{ + This function computes the exposure, and HAC adjusted standard errors + to linear augmented market models estimated for several regressands + across multiple periods. +} \section{Warning}{Do not have any space between names provided under - \dQuote{periodnames}.} + \dQuote{periodnames}. +} \author{Ajay Shah, Vimal Balasubramaniam} Modified: pkg/man/marketResidual.Rd =================================================================== --- pkg/man/marketResidual.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/marketResidual.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,22 +1,22 @@ \name{marketResidual} \alias{marketResidual} -\title{This function extracts market return from the firm return.} +\title{Extract residuals from a market model} -\description{This function extracts market return using regression from - the firm return to get the residual return. } +\description{This function extracts residuals from a market model using + function \code{stats:lm}.} \usage{marketResidual(firm.returns, market.returns)} \arguments{ - \item{firm.returns}{a \pkg{zoo} time series object with all firm returns.} + \item{firm.returns}{a \pkg{zoo} time series object (univariate or + otherwise) with firm returns.} \item{market.returns}{a \pkg{zoo} time series of market index returns.} } -\value{Market residual after extracting market returns from the firm - return.} +\value{Residual returns unexplained by market index returns.} \author{Vikram Bahure} Modified: pkg/man/remap.cumprod.Rd =================================================================== --- pkg/man/remap.cumprod.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/remap.cumprod.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,30 +1,34 @@ \name{remap.cumprod} \alias{remap.cumprod} -\title{Compute geometric returns.} +\title{Cumulative geometric values} -\description{This function computes the geometric returns for a given +\description{This function computes the cumulative geometric values for a given \pkg{zoo} object.} -\usage{remap.cumprod(z, is.pc = TRUE, is.returns = TRUE, base = 100)} +\usage{ + remap.cumprod(z, is.pc = FALSE, is.returns = TRUE, base = 100) +} \arguments{ + \item{z}{a \pkg{zoo} object indexed by event time obtained from + \code{\link{phys2eventtime}}.} - \item{z}{a \pkg{zoo} object indexed by event time, as returned from - \dQuote{phys2eventtime}.} + \item{is.pc}{\sQuote{logical}, whether input is a percentage. Default + value set to \sQuote{FALSE}.} - \item{is.pc}{\sQuote{logical}, whether input is a percentage.} + \item{is.returns}{\sQuote{logical}, whether input is a returns series.} - \item{is.returns}{\sQuote{logical}, whether input is returns.} - \item{base}{an integer specifying the base for cumulative product.} } -\value{A \pkg{zoo} series is returned with each column replaced by the - product of \dQuote{base} and the cumulative product of the column.} +\value{A \pkg{zoo} object with the cumulative product for each series, + representing a buy-hold return estimate. +} + \seealso{ -phys2eventtime + \code{\link{phys2eventtime}} } \examples{ @@ -39,4 +43,4 @@ is.returns = TRUE, base = 100) } - +head(eventtime[,1:5]) Modified: pkg/man/remap.cumsum.Rd =================================================================== --- pkg/man/remap.cumsum.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/remap.cumsum.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,31 +1,31 @@ \name{remap.cumsum} \alias{remap.cumsum} -\title{This function gives the cumulative total of the values (in - level or percentage form).} +\title{Cumulative values} \description{ - This function gives the cumulative total of the values. + This function remaps a time series into its cumulative summation. } \usage{ -remap.cumsum(z, is.pc = TRUE, base = 0) +remap.cumsum(z, is.pc = FALSE, base = 0) } \arguments{ - \item{z}{a \pkg{zoo} object indexed by event time, as returned from + \item{z}{a \pkg{zoo} object indexed by event time obtained from \dQuote{phys2eventtime}.} - \item{is.pc}{\sQuote{logical}, whether input is a percentage.} + \item{is.pc}{\sQuote{logical}, whether input is a percentage. Default + value set to \sQuote{FALSE}.} \item{base}{an integer specifying the base for cumulative sum.} } -\value{A \pkg{zoo} series is returned having each column replaced by - the cumulative sum of the column.} +\value{A \pkg{zoo} object with the cumulative summation for each series. +} \seealso{ - eventDays, eventstudyData, phys2eventtime + \code{\link{phys2eventtime}} } \examples{ @@ -37,4 +37,5 @@ width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) eventtime <- remap.cumsum(es.w, is.pc = FALSE, base = 0) +head(eventtime[,1:5]) } Modified: pkg/man/remap.event.reindex.Rd =================================================================== --- pkg/man/remap.event.reindex.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/remap.event.reindex.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -1,23 +1,25 @@ \name{remap.event.reindex} \alias{remap.event.reindex} -\title{Remaps the event date to 100 and remaps other values in event window} +\title{ + Reindex value within event window +} -%% FIXME: needs to be rewritten. -\description{This function remaps the event date to 100, and other values - relative to the remapped event date. +\description{ + Reset value at the beginning of the event window to a 100 and reindex thereon. } \usage{remap.event.reindex(z)} \arguments{ - \item{z}{z is a zoo object containing input data from phys2eventtime.} + \item{z}{z is a zoo object obtained from + \code{\link{phys2eventtime}}. } -\value{The function returns a zoo object which has been rescaled.} +\value{Rescaled returns value} \seealso{ -phys2eventtime + \code{\link{phys2eventtime}} } \examples{ data(StockPriceReturns) @@ -28,4 +30,5 @@ width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) eventtime <- remap.event.reindex(es.w) +head(eventtime[,1:5]) } Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-03 15:19:51 UTC (rev 283) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-03 15:20:27 UTC (rev 284) @@ -3,8 +3,8 @@ \title{Estimate exposure for a single regressor over multiple periods} -\description{This function estimates exposure for a single regressor - over a set of regressands obtained by using \sQuote{makeX} +\description{This function estimates exposure for a single regressand + over a set of regressors obtained by using \sQuote{makeX} over multiple periods. } @@ -20,15 +20,16 @@ \arguments{ \item{firm.returns}{a \sQuote{zoo} vector of data for one - regressor (firm). + regressand (firm). } - \item{X}{a matrix of regressands obtained by using \sQuote{makeX}. + \item{X}{a matrix of regressors obtained by using \sQuote{makeX}. See \sQuote{Details} when this is specified as a market model. } \item{nlags}{specifies a lag length required from the specified set - of regressands. When unspecified, the best lag using the AIC is used. + of regressors. When unspecified, the best lag using the AIC is + computed for the market model. } \item{verbose}{\sQuote{logical}, indicating whether the function From noreply at r-forge.r-project.org Thu Apr 3 19:06:22 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 3 Apr 2014 19:06:22 +0200 (CEST) Subject: [Eventstudies-commits] r285 - in pkg: . R man Message-ID: <20140403170622.B87ED187089@r-forge.r-project.org> Author: chiraganand Date: 2014-04-03 19:06:22 +0200 (Thu, 03 Apr 2014) New Revision: 285 Modified: pkg/DESCRIPTION pkg/NAMESPACE pkg/R/eventstudy.R pkg/R/inference.bootstrap.R pkg/R/marketResidual.R pkg/man/inference.bootstrap.Rd pkg/man/inference.wilcox.Rd pkg/man/manyfirmssubperiod.lmAMM.Rd pkg/man/remap.cumprod.Rd pkg/man/remap.event.reindex.Rd Log: Rd files updated and some syntax changes also complete. NAMESPACE updated to import various libraries and DESCRIPTION date upated. Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/DESCRIPTION 2014-04-03 17:06:22 UTC (rev 285) @@ -2,7 +2,7 @@ Type: Package Title: Event study analysis Version: 1.2 -Date: 2014-03-28 +Date: 2014-04-03 Author: Chirag Anand, Vikram Bahure, Vimal Balasubramaniam, Ajay Shah Maintainer: Vikram Bahure Depends: R (>= 2.12.0), zoo, xts, boot, testthat, sandwich Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/NAMESPACE 2014-04-03 17:06:22 UTC (rev 285) @@ -1,7 +1,9 @@ export(eventstudy, inference.bootstrap, inference.wilcox, phys2eventtime, remap.cumsum, remap.cumprod, remap.event.reindex, ees, eesPlot) + export(marketResidual, excessReturn) + export(subperiod.lmAMM, manyfirmssubperiod.lmAMM, lmAMM, makeX) @@ -13,3 +15,5 @@ S3method(plot, amm) S3method(plot, es) + +import(boot,sandwich,testthat,xts,zoo) Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/R/eventstudy.R 2014-04-03 17:06:22 UTC (rev 285) @@ -2,7 +2,7 @@ eventList, width = 10, is.levels = FALSE, - type = "None", + type = "marketResidual", to.remap = TRUE, remap = "cumsum", inference = TRUE, Modified: pkg/R/inference.bootstrap.R =================================================================== --- pkg/R/inference.bootstrap.R 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/R/inference.bootstrap.R 2014-04-03 17:06:22 UTC (rev 285) @@ -48,6 +48,7 @@ # This function does bootstrap inference for the entire # Ecar, i.e. main graph of the event study. inference.bootstrap <- function(es.w, to.plot=TRUE, + boot.run=1000, xlab = "Event time", ylab = "Cumulative returns of response series", main = "Event study plot") { @@ -55,7 +56,8 @@ colMeans(transposed[d,], na.rm=TRUE) } tmp <- t(as.matrix(es.w)) - b <- boot(tmp, Ecar, R=1000) + b <- boot(tmp, Ecar, R=boot.run) + results <- NULL for (i in 1:ncol(b$t)) { Modified: pkg/R/marketResidual.R =================================================================== --- pkg/R/marketResidual.R 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/R/marketResidual.R 2014-04-03 17:06:22 UTC (rev 285) @@ -15,7 +15,10 @@ fulldata <- merge(x,y,all=TRUE) fulldata <- window(fulldata,start=startdate,end=enddate) - + if (length(fulldata) == 0) { + warning("no common window found"); + return(NULL) + } ## Storing NA observations non.na.loc <- complete.cases(fulldata) fulldata <- fulldata[complete.cases(fulldata),] @@ -30,12 +33,16 @@ ## Checking if(NCOL(firm.returns)>1){ - result <- NULL - for(i in 1:NCOL(firm.returns)){ - res <- mm.residual(y=firm.returns[,i],x=market.returns) - result <- merge(result,res,all=TRUE) + result <- lapply(firm.returns, function(i) + { + mm.residual(y=i,x=market.returns) + }) + names(result) <- colnames(firm.returns) + chk <- which(do.call("c",lapply(result,is.null))==TRUE) + if(length(chk)!=0){ + result <- result[-chk] } - colnames(result) <- colnames(firm.returns) + result <- do.call("merge.zoo", result) } else { result <- mm.residual(y=firm.returns,x=market.returns) } Modified: pkg/man/inference.bootstrap.Rd =================================================================== --- pkg/man/inference.bootstrap.Rd 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/man/inference.bootstrap.Rd 2014-04-03 17:06:22 UTC (rev 285) @@ -1,16 +1,17 @@ \name{inference.bootstrap} \alias{inference.bootstrap} -\title{Do bootstrap inference for event study analysis} +\title{Bootstrap inference for event study estimator} \description{ - This function does bootstrap inference to generate distribution of - average of all the cumulative returns time-series. + This function obtains a boostrapped confidence interval for estimates + of magnitude over the event horizon. } \usage{ inference.bootstrap(es.w, to.plot = TRUE, + boot.run = 1000, xlab = "Event time", ylab = "Cumulative returns of response series", main = "Event study plot") @@ -18,11 +19,16 @@ \arguments{ \item{es.w}{ - a \pkg{zoo} series indexed by event time: the \dQuote{z.e} + a \pkg{zoo} object indexed by event time: the \dQuote{z.e} component of the list returned by the \code{\link{phys2eventtime}} function. } + \item{boot.run}{ + A \sQuote{numeric}, controlling the number of simulations required + for the bootstrap. + } + \item{to.plot}{a \sQuote{logical} indicating whether to generate an eventstudy plot of the inference estimated. Defaults to \sQuote{TRUE}. @@ -38,12 +44,6 @@ \sQuote{TRUE}.} } -%% FIXME: more details -\details{ - Function \sQuote{boot} from package \pkg{boot} is used for - bootstrapping with \emph{replicates} of 1000. -} - \value{ A \sQuote{matrix} with 3 columns, the lower confidence interval (CI), the mean, and the upper CI which are the result of bootstrap Modified: pkg/man/inference.wilcox.Rd =================================================================== --- pkg/man/inference.wilcox.Rd 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/man/inference.wilcox.Rd 2014-04-03 17:06:22 UTC (rev 285) @@ -20,15 +20,17 @@ \arguments{ - \item{es.w}{a \pkg{zoo} series indexed by event time. It is the - \dQuote{z.e} component of the list returned by function - \dQuote{phys2eventtime}.} + \item{es.w}{ + a \pkg{zoo} object indexed by event time: the \dQuote{z.e} + component of the list returned by the \code{\link{phys2eventtime}} + function. + } - \item{to.plot}{a \sQuote{logical}. indicating whether to generate an + \item{to.plot}{a \sQuote{logical} indicating whether to generate an eventstudy plot of the inference estimated. Defaults to \sQuote{TRUE}. } - + \item{xlab}{the x-axis label of the generated plot. Used if \dQuote{to.plot} is \sQuote{TRUE}.} @@ -39,7 +41,6 @@ \sQuote{TRUE}.} } -%% FIXME: add \details section? \value{A \sQuote{matrix} with 3 columns: the lower confidence interval (CI), the mean, and the upper CI which are the result of wilcox inference.} @@ -59,6 +60,5 @@ width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) eventtime <- remap.cumsum(es.w, is.pc = FALSE, base = 0) -infr <- inference.wilcox(es.w = eventtime, to.plot = FALSE) -head(infr) +inference.wilcox(es.w = eventtime, to.plot = FALSE) } Modified: pkg/man/manyfirmssubperiod.lmAMM.Rd =================================================================== --- pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-03 17:06:22 UTC (rev 285) @@ -1,10 +1,10 @@ \name{manyfirmssubperiod.lmAMM} \alias{manyfirmssubperiod.lmAMM} -\title{Estimate exposure for multiple regressors over multiple periods.} +\title{Estimate exposure for many regressands over multiple periods.} \description{\code{\link{manyfirmssubperiod.lmAMM}} estimates exposure - for multiple regressands over a set of regressors obtained by using + for many regressands over a set of regressors obtained by using \sQuote{makeX} over multiple periods. } Modified: pkg/man/remap.cumprod.Rd =================================================================== --- pkg/man/remap.cumprod.Rd 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/man/remap.cumprod.Rd 2014-04-03 17:06:22 UTC (rev 285) @@ -42,5 +42,6 @@ is.pc = TRUE, is.returns = TRUE, base = 100) +head(eventtime[,1:5]) } -head(eventtime[,1:5]) + Modified: pkg/man/remap.event.reindex.Rd =================================================================== --- pkg/man/remap.event.reindex.Rd 2014-04-03 15:20:27 UTC (rev 284) +++ pkg/man/remap.event.reindex.Rd 2014-04-03 17:06:22 UTC (rev 285) @@ -11,9 +11,10 @@ \usage{remap.event.reindex(z)} -\arguments{ +\arguments{ \item{z}{z is a zoo object obtained from - \code{\link{phys2eventtime}}. + \code{\link{phys2eventtime}}. + } } \value{Rescaled returns value} From noreply at r-forge.r-project.org Fri Apr 4 05:14:38 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 4 Apr 2014 05:14:38 +0200 (CEST) Subject: [Eventstudies-commits] r286 - pkg/R Message-ID: <20140404031438.CD625186957@r-forge.r-project.org> Author: vikram Date: 2014-04-04 05:14:03 +0200 (Fri, 04 Apr 2014) New Revision: 286 Modified: pkg/R/inference.bootstrap.R Log: Minor correction in plot.inference Modified: pkg/R/inference.bootstrap.R =================================================================== --- pkg/R/inference.bootstrap.R 2014-04-03 17:06:22 UTC (rev 285) +++ pkg/R/inference.bootstrap.R 2014-04-04 03:14:03 UTC (rev 286) @@ -29,16 +29,16 @@ # Plotting inference plot.inference <- function(inference, xlab="Event time", ylab="", main="", col.es="dark slate blue"){ - big <- max(abs(inference$eventstudy.output)) + big <- max(abs(inference)) hilo <- c(-big,big) - width <- (nrow(inference$eventstudy.output)-1)/2 - plot(-width:width, inference$eventstudy.output[,2], type="l", lwd=2, ylim=hilo, + width <- (nrow(inference)-1)/2 + plot(-width:width, inference[,2], type="l", lwd=2, ylim=hilo, col=col.es,xlab= xlab, ylab = ylab, main=paste(main)) - points(-width:width, inference$eventstudy.output[,2]) - lines(-width:width, inference$eventstudy.output[,"2.5%"], + points(-width:width, inference[,2]) + lines(-width:width, inference[,"2.5%"], lwd=1, lty=2, col=col.es) - lines(-width:width, inference$eventstudy.output[,"97.5%"], + lines(-width:width, inference[,"97.5%"], lwd=1, lty=2, col=col.es) abline(h=0,v=0) } From noreply at r-forge.r-project.org Tue Apr 8 19:15:19 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 8 Apr 2014 19:15:19 +0200 (CEST) Subject: [Eventstudies-commits] r287 - pkg/vignettes Message-ID: <20140408171519.AEAB6186DFB@r-forge.r-project.org> Author: chiraganand Date: 2014-04-08 19:15:19 +0200 (Tue, 08 Apr 2014) New Revision: 287 Added: pkg/vignettes/AMM.Rnw pkg/vignettes/AMM.bib Removed: pkg/vignettes/amm.Rnw pkg/vignettes/amm.bib Log: Renamed AMM vignette. Copied: pkg/vignettes/AMM.Rnw (from rev 286, pkg/vignettes/amm.Rnw) =================================================================== --- pkg/vignettes/AMM.Rnw (rev 0) +++ pkg/vignettes/AMM.Rnw 2014-04-08 17:15:19 UTC (rev 287) @@ -0,0 +1,176 @@ +\documentclass[a4paper,11pt]{article} +\usepackage{graphicx} +\usepackage{a4wide} +\usepackage[colorlinks,linkcolor=blue,citecolor=red]{hyperref} +\usepackage{natbib} +\usepackage{float} +\usepackage{tikz} +\usepackage{parskip} +\usepackage{amsmath} +\title{Augmented Market Models} +\author{Ajay Shah \and Vikram Bahure \and Chirag Anand} +\begin{document} +%\VignetteIndexEntry{eventstudies: Extreme events functionality} +% \VignetteDepends{} +% \VignetteKeywords{extreme event analysis} +% \VignettePackage{eventstudies} +\maketitle + +\begin{abstract} +The document demonstrates the application of Augmented market model +(AMM) from the paper \citet{patnaik2010amm} to extract currency +exposure and AMM residuals from the model. +\end{abstract} + +\SweaveOpts{engine=R,pdf=TRUE} +\section{Introduction} + +Augmented market models (AMM) extends the classical market model \citep{sharpe1964capm, lintner1965capm} to introduce additional right hand side variables like currency returns or interest rates to understand the effect of macro variations in addition to market movements on stock returns. The package provides functionality to estimate augmented market models as well as produce augmented market model residuals (AMM abnormal returns) stripped of market and macro variations to run event studies. The function set was originally written and applied in \citet{patnaik2010amm}. \citet{adler1984exposure} and \citet{jorion1990exchange} are the first papers to use augmented market models to study currency exposure. The standard currency exposure AMM is as follows + +\begin{equation} + r_j = \alpha_j + \beta_{1j} r_{M1} + \beta_{2j} r_{M2} + \epsilon +\end{equation} + +In the original usage of augmented market models, Currency exposure is +expressed as the regression coefficient on currency returns (M2). The +model uses firm stock price as the information set of firm positions +and it relates firm returns $r_j$ to market index movements $r_{M1}$ +and currency fluctuations $r_{M2}$. The coefficient $\beta_{2j}$ +measures the sensitivity of the valuation of firm $j$ to changes in +the exchange rate. This is a widely used technique with multiple +variations including asymmetric exposures. + +The AMM implementation in the package has some key innovations as compared to the original implementation of currency exposure AMM's by \citet{adler1984exposure} and \citet{jorion1990exchange}. +\begin{equation} + r_{jt} = \alpha + \beta_1 r_{M1,t} + + \sum_{i=0}^{k} a_i e_{t-i} + \epsilon_t +\end{equation} + +\begin{enumerate} +\item Exchange rate series is re-expressed as a series of innovations with an AIC selected AR process. Under this specification, an innovation $e_t$ on the currency market has an impact on the stock price at time $t$ and the following $k$ time periods. Under the above model, currency exposure is embedded in the vector of $a_i$ coefficients; it is no longer a simple scalar $\beta_2$ as was the case under the standard model +\item Heteroscedasticity in $r_{M1}$ \& $r_{M2}$ : This is resolved by + using a HAC estimator +\item Decomposition of market exposure from firm exposure: Market exposure issue solved by orthogonalising the market index time-series by first estimating a regression model explaining $r_{M1}$ as a function of past and present currency innovations, and extracting the residual from this regression. These residuals represent uncontaminated market returns +\end{enumerate} + +In the section below, we explain the estimation of currency exposure, +AMM residuals and performing event study analysis. In section \ref{sec:ce}, we +replicate the methodology used in \citet{patnaik2010amm} using the +package. In section \ref{sec:es}, we take the AMM methodology a step ahead to +extract residuals from AMM methodology which we use the to +perform traditional event study analysis. +% Need to talk more about generalisation used for variables other than currency + + +\section{Software approach}\label{sec:ce} +The package has functions which enable the user to compute linear +model AMM output, along with currency exposure, using the AMM +methodology employed in \citet{patnaik2010amm}. In the subsections +below we describe construction of data-set to input in \texttt{lmAMM} +function and further computing AMM output and currency exposure. + +\subsection{Constructing data set} +We need to construct usable data set, before performing AMM analysis +on firm returns using this package. There are two steps to be +followed constructing \texttt{X} (regressors) and firm returns +(regressands), to perform OLS as shown in the \citet{patnaik2010amm}. +\subsubsection{Regressors \& Regressands} +Regressors in the AMM equation are market returns and currency +returns, while regressands is firm returns. All the variables should +have balanced panel if not then merge the time series variable to get +one. \textit{AMMData} is an time series object with market returns as +\textit{Nifty} and currency returns as \textit{INR/USD}. If +currency exposure is to be estimated for different periods separately +then argument \textit{dates} will be helpful or else \textit{NULL} +will be provided to perform for full period. + +The function \textit{makeX} considers that +there is impact of currency on market returns and with the argument +\textit{market.returns.purge}, we orthogonalise the market returns to currency +returns before using AMM model. + +<<>>= +# Create RHS before running subperiod.lmAMM() +library(eventstudies) +data("AMMData") +nifty <- AMMData$index.nifty +inrusd <- AMMData$currency.inrusd +regressand <- AMMData[,c("Infosys","TCS")] +regressors <- makeX(nifty, others=inrusd, + switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, + dates=as.Date(c("2012-02-01","2013-01-01","2014-01-20")), verbose=FALSE) +@ + +\subsection{Augmented market model} +Augmented market model output with a class of \textit{amm} is +generated using the function \texttt{lmAMM}. This function takes firm +returns (regressand) and regressor as input. Output of \texttt{lmAMM} +function is a list object with linear model output of AMM, +currency exposure, standard deviation and significance of the +exposure. +<<>>= +## AMM residual to time series +timeseries.lmAMM <- 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.output.one <- lmAMM(regressand[,1],X=regressors,nlags=1) +amm.resid.one <- timeseries.lmAMM(firm.returns=regressand[,1], + X=regressors, verbose=FALSE, nlags=1) +summary(amm.output.one) + +## More than one firm + # Extracting and merging +tmp.resid <- sapply(colnames(regressand)[1:2],function(y) + timeseries.lmAMM(firm.returns=regressand[,y], + X=regressors, + verbose=FALSE, + nlags=1)) +amm.resid <- zoo(tmp.resid,as.Date(rownames(tmp.resid))) +@ + +All the basic functionality are available for object with class +\textit{amm}. \texttt{print},\texttt{summary} and \texttt{plot} +commands can be used to do preliminary analysis. The plot +\ref{fig:amm} compares the AMM residuals with abnormal firm returns. +\begin{figure}[t] + \begin{center} + \label{fig:amm} + \caption{Augment market model} + \setkeys{Gin}{width=0.8\linewidth} + \setkeys{Gin}{height=0.8\linewidth} +<>= +plot(amm.output.one) +@ + \end{center} + \label{fig:one} +\end{figure} + +\subsection{Getting currency exposure} +The output of \texttt{makeX} function is used in \textit{subperiod.lmAMM} and +\textit{lmAMM} function to get currency exposure of the firms and AMM +residuals respectively. In the example below, we demonstrate the use +of \textit{subperiod.lmAMM} function to estimate currency exposure for +firms. +% 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(subperiod.lmAMM)(firm.returns=regressand[,1], + X=regressors, + nlags=1, + verbose=TRUE, + dates= as.Date(c("2012-02-01", + "2013-01-01","2014-01-31"))) +str(firm.exposure) +@ + + We can also perform event study analysis, directly on AMM residuals + using \textit{eventstudy} function. which is presented in + \textit{eventstudies} vignette. + +\bibliographystyle{jss} \bibliography{amm} +\end{document} Copied: pkg/vignettes/AMM.bib (from rev 275, pkg/vignettes/amm.bib) =================================================================== --- pkg/vignettes/AMM.bib (rev 0) +++ pkg/vignettes/AMM.bib 2014-04-08 17:15:19 UTC (rev 287) @@ -0,0 +1,53 @@ + + at article{patnaik2010amm, + title={Does the currency regime shape unhedged currency exposure?}, + author={Patnaik, Ila and Shah, Ajay}, + journal={Journal of International Money and Finance}, + volume={29}, + number={5}, + pages={760-769}, + year={2010}, + publisher={Elsevier} +} + + at article{sharpe1964capm, + title={Capital asset Prices: A Theory of market equilibrium under conditions of risk}, + author={Sharpe, William F}, + journal={The Journal of Finance}, + volume={19}, + number={3}, + pages={425-442}, + year={1964}, + publisher={Wiley Online Library} +} + + at article{lintner1965capm, + title={The valuation of risk assets and the selection of risky investments in stock portfolios and capital budgets}, + author={Lintner, John}, + journal={The Review of Economics and Statistics}, + volume={47}, + number={1}, + pages={13-37}, + year={1965}, + publisher={JSTOR} +} + + at article{adler1984exposure, + title={Exposure to currency risk: definition and measurement}, + author={Adler, Michael and Dumas, Bernard}, + journal={Financial management}, + pages={41-50}, + year={1984}, + publisher={JSTOR} +} + + at article{jorion1990exchange, + title={The exchange-rate exposure of US multinationals}, + author={Jorion, Philippe}, + journal={Journal of Business}, + pages={331-345}, + year={1990}, + publisher={JSTOR} +} + + Deleted: pkg/vignettes/amm.Rnw =================================================================== --- pkg/vignettes/amm.Rnw 2014-04-04 03:14:03 UTC (rev 286) +++ pkg/vignettes/amm.Rnw 2014-04-08 17:15:19 UTC (rev 287) @@ -1,176 +0,0 @@ -\documentclass[a4paper,11pt]{article} -\usepackage{graphicx} -\usepackage{a4wide} -\usepackage[colorlinks,linkcolor=blue,citecolor=red]{hyperref} -\usepackage{natbib} -\usepackage{float} -\usepackage{tikz} -\usepackage{parskip} -\usepackage{amsmath} -\title{Augmented Market Models} -\author{Ajay Shah \and Vikram Bahure \and Chirag Anand} -\begin{document} -%\VignetteIndexEntry{eventstudies: Extreme events functionality} -% \VignetteDepends{} -% \VignetteKeywords{extreme event analysis} -% \VignettePackage{eventstudies} -\maketitle - -\begin{abstract} -The document demonstrates the application of Augmented market model -(AMM) from the paper \citet{patnaik2010amm} to extract currency -exposure and AMM residuals from the model. -\end{abstract} - -\SweaveOpts{engine=R,pdf=TRUE} -\section{Introduction} - -Augmented market models (AMM) extends the classical market model \citep{sharpe1964capm, lintner1965capm} to introduce additional right hand side variables like currency returns or interest rates to understand the effect of macro variations in addition to market movements on stock returns. The package provides functionality to estimate augmented market models as well as produce augmented market model residuals (AMM abnormal returns) stripped of market and macro variations to run event studies. The function set was originally written and applied in \citet{patnaik2010amm}. \citet{adler1984exposure} and \citet{jorion1990exchange} are the first papers to use augmented market models to study currency exposure. The standard currency exposure AMM is as follows - -\begin{equation} - r_j = \alpha_j + \beta_{1j} r_{M1} + \beta_{2j} r_{M2} + \epsilon -\end{equation} - -In the original usage of augmented market models, Currency exposure is -expressed as the regression coefficient on currency returns (M2). The -model uses firm stock price as the information set of firm positions -and it relates firm returns $r_j$ to market index movements $r_{M1}$ -and currency fluctuations $r_{M2}$. The coefficient $\beta_{2j}$ -measures the sensitivity of the valuation of firm $j$ to changes in -the exchange rate. This is a widely used technique with multiple -variations including asymmetric exposures. - -The AMM implementation in the package has some key innovations as compared to the original implementation of currency exposure AMM's by \citet{adler1984exposure} and \citet{jorion1990exchange}. -\begin{equation} - r_{jt} = \alpha + \beta_1 r_{M1,t} - + \sum_{i=0}^{k} a_i e_{t-i} + \epsilon_t -\end{equation} - -\begin{enumerate} -\item Exchange rate series is re-expressed as a series of innovations with an AIC selected AR process. Under this specification, an innovation $e_t$ on the currency market has an impact on the stock price at time $t$ and the following $k$ time periods. Under the above model, currency exposure is embedded in the vector of $a_i$ coefficients; it is no longer a simple scalar $\beta_2$ as was the case under the standard model -\item Heteroscedasticity in $r_{M1}$ \& $r_{M2}$ : This is resolved by - using a HAC estimator -\item Decomposition of market exposure from firm exposure: Market exposure issue solved by orthogonalising the market index time-series by first estimating a regression model explaining $r_{M1}$ as a function of past and present currency innovations, and extracting the residual from this regression. These residuals represent uncontaminated market returns -\end{enumerate} - -In the section below, we explain the estimation of currency exposure, -AMM residuals and performing event study analysis. In section \ref{sec:ce}, we -replicate the methodology used in \citet{patnaik2010amm} using the -package. In section \ref{sec:es}, we take the AMM methodology a step ahead to -extract residuals from AMM methodology which we use the to -perform traditional event study analysis. -% Need to talk more about generalisation used for variables other than currency - - -\section{Software approach}\label{sec:ce} -The package has functions which enable the user to compute linear -model AMM output, along with currency exposure, using the AMM -methodology employed in \citet{patnaik2010amm}. In the subsections -below we describe construction of data-set to input in \texttt{lmAMM} -function and further computing AMM output and currency exposure. - -\subsection{Constructing data set} -We need to construct usable data set, before performing AMM analysis -on firm returns using this package. There are two steps to be -followed constructing \texttt{X} (regressors) and firm returns -(regressands), to perform OLS as shown in the \citet{patnaik2010amm}. -\subsubsection{Regressors \& Regressands} -Regressors in the AMM equation are market returns and currency -returns, while regressands is firm returns. All the variables should -have balanced panel if not then merge the time series variable to get -one. \textit{AMMData} is an time series object with market returns as -\textit{Nifty} and currency returns as \textit{INR/USD}. If -currency exposure is to be estimated for different periods separately -then argument \textit{dates} will be helpful or else \textit{NULL} -will be provided to perform for full period. - -The function \textit{makeX} considers that -there is impact of currency on market returns and with the argument -\textit{market.returns.purge}, we orthogonalise the market returns to currency -returns before using AMM model. - -<<>>= -# Create RHS before running subperiod.lmAMM() -library(eventstudies) -data("AMMData") -nifty <- AMMData$index.nifty -inrusd <- AMMData$currency.inrusd -regressand <- AMMData[,c("Infosys","TCS")] -regressors <- makeX(nifty, others=inrusd, - switch.to.innov=TRUE, market.returns.purge=TRUE, nlags=1, - dates=as.Date(c("2012-02-01","2013-01-01","2014-01-20")), verbose=FALSE) -@ - -\subsection{Augmented market model} -Augmented market model output with a class of \textit{amm} is -generated using the function \texttt{lmAMM}. This function takes firm -returns (regressand) and regressor as input. Output of \texttt{lmAMM} -function is a list object with linear model output of AMM, -currency exposure, standard deviation and significance of the -exposure. -<<>>= -## AMM residual to time series -timeseries.lmAMM <- 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.output.one <- lmAMM(regressand[,1],X=regressors,nlags=1) -amm.resid.one <- timeseries.lmAMM(firm.returns=regressand[,1], - X=regressors, verbose=FALSE, nlags=1) -summary(amm.output.one) - -## More than one firm - # Extracting and merging -tmp.resid <- sapply(colnames(regressand)[1:2],function(y) - timeseries.lmAMM(firm.returns=regressand[,y], - X=regressors, - verbose=FALSE, - nlags=1)) -amm.resid <- zoo(tmp.resid,as.Date(rownames(tmp.resid))) -@ - -All the basic functionality are available for object with class -\textit{amm}. \texttt{print},\texttt{summary} and \texttt{plot} -commands can be used to do preliminary analysis. The plot -\ref{fig:amm} compares the AMM residuals with abnormal firm returns. -\begin{figure}[t] - \begin{center} - \label{fig:amm} - \caption{Augment market model} - \setkeys{Gin}{width=0.8\linewidth} - \setkeys{Gin}{height=0.8\linewidth} -<>= -plot(amm.output.one) -@ - \end{center} - \label{fig:one} -\end{figure} - -\subsection{Getting currency exposure} -The output of \texttt{makeX} function is used in \textit{subperiod.lmAMM} and -\textit{lmAMM} function to get currency exposure of the firms and AMM -residuals respectively. In the example below, we demonstrate the use -of \textit{subperiod.lmAMM} function to estimate currency exposure for -firms. -% 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(subperiod.lmAMM)(firm.returns=regressand[,1], - X=regressors, - nlags=1, - verbose=TRUE, - dates= as.Date(c("2012-02-01", - "2013-01-01","2014-01-31"))) -str(firm.exposure) -@ - - We can also perform event study analysis, directly on AMM residuals - using \textit{eventstudy} function. which is presented in - \textit{eventstudies} vignette. - -\bibliographystyle{jss} \bibliography{amm} -\end{document} Deleted: pkg/vignettes/amm.bib =================================================================== --- pkg/vignettes/amm.bib 2014-04-04 03:14:03 UTC (rev 286) +++ pkg/vignettes/amm.bib 2014-04-08 17:15:19 UTC (rev 287) @@ -1,53 +0,0 @@ - - at article{patnaik2010amm, - title={Does the currency regime shape unhedged currency exposure?}, - author={Patnaik, Ila and Shah, Ajay}, - journal={Journal of International Money and Finance}, - volume={29}, - number={5}, - pages={760-769}, - year={2010}, - publisher={Elsevier} -} - - at article{sharpe1964capm, - title={Capital asset Prices: A Theory of market equilibrium under conditions of risk}, - author={Sharpe, William F}, - journal={The Journal of Finance}, - volume={19}, - number={3}, - pages={425-442}, - year={1964}, - publisher={Wiley Online Library} -} - - at article{lintner1965capm, - title={The valuation of risk assets and the selection of risky investments in stock portfolios and capital budgets}, - author={Lintner, John}, - journal={The Review of Economics and Statistics}, - volume={47}, - number={1}, - pages={13-37}, - year={1965}, - publisher={JSTOR} -} - - at article{adler1984exposure, - title={Exposure to currency risk: definition and measurement}, - author={Adler, Michael and Dumas, Bernard}, - journal={Financial management}, - pages={41-50}, - year={1984}, - publisher={JSTOR} -} - - at article{jorion1990exchange, - title={The exchange-rate exposure of US multinationals}, - author={Jorion, Philippe}, - journal={Journal of Business}, - pages={331-345}, - year={1990}, - publisher={JSTOR} -} - - From noreply at r-forge.r-project.org Thu Apr 17 12:05:55 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 17 Apr 2014 12:05:55 +0200 (CEST) Subject: [Eventstudies-commits] r288 - pkg/man Message-ID: <20140417100555.9F441187631@r-forge.r-project.org> Author: vikram Date: 2014-04-17 12:05:54 +0200 (Thu, 17 Apr 2014) New Revision: 288 Modified: pkg/man/excessReturn.Rd pkg/man/lmAMM.Rd pkg/man/marketResidual.Rd Log: Modification in manual example output Modified: pkg/man/excessReturn.Rd =================================================================== --- pkg/man/excessReturn.Rd 2014-04-08 17:15:19 UTC (rev 287) +++ pkg/man/excessReturn.Rd 2014-04-17 10:05:54 UTC (rev 288) @@ -28,6 +28,9 @@ data(NiftyIndex) er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = NiftyIndex) +output <- merge(er.result$Infosys,StockPriceReturns$Infosys,NiftyIndex,all=FALSE) +colnames(output) <- c("excess.return","raw.returns","nifty.returns") +tail(output) } \keyword{excessReturn} Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-08 17:15:19 UTC (rev 287) +++ pkg/man/lmAMM.Rd 2014-04-17 10:05:54 UTC (rev 288) @@ -90,9 +90,14 @@ market.returns.purge = FALSE, verbose = FALSE) -a <- lmAMM(firm.returns, X, nlags = 0, verbose = FALSE) +amm.result <- lmAMM(firm.returns, X, nlags = 0, verbose = FALSE) +names(amm.result) +amm.residual <- residuals(amm.result) +amm.result <- zoo(amm.residual,as.Date(names(amm.residual))) -print(a) +output <- merge(amm.result,StockPriceReturns$Infosys,NiftyIndex,all=FALSE) +colnames(output) <- c("amm.residual","raw.returns","nifty.returns") +tail(output) } \keyword{lmAMM} Modified: pkg/man/marketResidual.Rd =================================================================== --- pkg/man/marketResidual.Rd 2014-04-08 17:15:19 UTC (rev 287) +++ pkg/man/marketResidual.Rd 2014-04-17 10:05:54 UTC (rev 288) @@ -26,6 +26,9 @@ mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = NiftyIndex) +output <- merge(mm.result$Infosys,StockPriceReturns$Infosys,NiftyIndex,all=FALSE) +colnames(output) <- c("market.residual","raw.returns","nifty.returns") +tail(output) } From noreply at r-forge.r-project.org Thu Apr 17 12:52:25 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 17 Apr 2014 12:52:25 +0200 (CEST) Subject: [Eventstudies-commits] r289 - pkg/man Message-ID: <20140417105226.040BE1875CA@r-forge.r-project.org> Author: vikram Date: 2014-04-17 12:52:25 +0200 (Thu, 17 Apr 2014) New Revision: 289 Modified: pkg/man/phys2eventtime.Rd Log: Modified phys2eventtime manual example Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-17 10:05:54 UTC (rev 288) +++ pkg/man/phys2eventtime.Rd 2014-04-17 10:52:25 UTC (rev 289) @@ -78,6 +78,13 @@ result <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) -str(result) + +c.no <- as.numeric(colnames(result$z.e)) +cnames <- SplitDates[c.no[1],] +phys.output <- as.numeric(result$z.e[as.character(c(-5:5)),as.character(c.no[1])]) +loc <- which(index(StockPriceReturns)%in%SplitDates[c.no[1],"event.when"]) +raw.data <- as.numeric(StockPriceReturns[c((loc-5):(loc+5)),SplitDates[c.no[1],"outcome.unit"]]) +check.output <- cbind(raw.data,phys.output) +check.output } \keyword{phys2eventime} From noreply at r-forge.r-project.org Thu Apr 17 13:04:41 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 17 Apr 2014 13:04:41 +0200 (CEST) Subject: [Eventstudies-commits] r290 - pkg/man Message-ID: <20140417110441.4965018765C@r-forge.r-project.org> Author: vikram Date: 2014-04-17 13:04:40 +0200 (Thu, 17 Apr 2014) New Revision: 290 Modified: pkg/man/remap.cumsum.Rd Log: Modified manual example for remapping Modified: pkg/man/remap.cumsum.Rd =================================================================== --- pkg/man/remap.cumsum.Rd 2014-04-17 10:52:25 UTC (rev 289) +++ pkg/man/remap.cumsum.Rd 2014-04-17 11:04:40 UTC (rev 290) @@ -21,6 +21,11 @@ \item{base}{an integer specifying the base for cumulative sum.} } +\details{This function remaps a time series into ints cumulative summation. + Function assigns first value as zero in the event window (-width) before cumulating the values. + +} + \value{A \pkg{zoo} object with the cumulative summation for each series. } @@ -37,5 +42,8 @@ width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) eventtime <- remap.cumsum(es.w, is.pc = FALSE, base = 0) +check.output <- cbind(es.w[,1],eventtime[,1]) +colnames(check.output) <- c("abnormal.returns","cumulative.abnormal.returns") +check.output head(eventtime[,1:5]) } From noreply at r-forge.r-project.org Tue Apr 22 07:22:17 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 22 Apr 2014 07:22:17 +0200 (CEST) Subject: [Eventstudies-commits] r291 - pkg/man Message-ID: <20140422052217.81CFF186A53@r-forge.r-project.org> Author: vikram Date: 2014-04-22 07:22:17 +0200 (Tue, 22 Apr 2014) New Revision: 291 Modified: pkg/man/ees.Rd pkg/man/eesPlot.Rd pkg/man/excessReturn.Rd pkg/man/inference.bootstrap.Rd pkg/man/inference.wilcox.Rd pkg/man/lmAMM.Rd pkg/man/makeX.Rd pkg/man/marketResidual.Rd pkg/man/phys2eventtime.Rd pkg/man/remap.cumprod.Rd pkg/man/remap.cumsum.Rd pkg/man/remap.event.reindex.Rd pkg/man/subperiod.lmAMM.Rd Log: Modified manual examples Modified: pkg/man/ees.Rd =================================================================== --- pkg/man/ees.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/ees.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -89,11 +89,12 @@ \author{Vikram Bahure} - \examples{ library(eventstudies) data(EESData) -input <- EESData$sp500 ## Input S&P 500 as the univariate series -output <- ees(input, prob.value = 5) ## Estimate 5\% tails. +## Input S&P 500 as the univariate series +input <- EESData$sp500 +## Constructing summary statistics for 5% tail values (5% on both sides) +output <- ees(input, prob.value = 5) str(output) } Modified: pkg/man/eesPlot.Rd =================================================================== --- pkg/man/eesPlot.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/eesPlot.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -69,6 +69,7 @@ \examples{ library(eventstudies) data(EESData) +## Generating event study plots (using modified event study methodology) eesPlot(z = EESData, response.series.name = "nifty", event.series.name = "sp500", Modified: pkg/man/excessReturn.Rd =================================================================== --- pkg/man/excessReturn.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/excessReturn.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -26,10 +26,14 @@ \examples{ data(StockPriceReturns) data(NiftyIndex) + +## Excess return er.result <- excessReturn(firm.returns = StockPriceReturns, market.returns = NiftyIndex) -output <- merge(er.result$Infosys,StockPriceReturns$Infosys,NiftyIndex,all=FALSE) -colnames(output) <- c("excess.return","raw.returns","nifty.returns") + +## Checking output: Comparing excess return, raw returns, nifty returns +output <- merge(er.result$Infosys, StockPriceReturns$Infosys, NiftyIndex,all=FALSE) +colnames(output) <- c("excess.return", "raw.returns", "nifty.returns") tail(output) } Modified: pkg/man/inference.bootstrap.Rd =================================================================== --- pkg/man/inference.bootstrap.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/inference.bootstrap.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -59,7 +59,7 @@ \examples{ data(StockPriceReturns) data(SplitDates) - +## Converting physical dates to event time frame es.results <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) @@ -67,8 +67,10 @@ start = -5, end = +5) +## Cumulating event window eventtime <- remap.cumsum(es.w, is.pc = FALSE, base = 0) +## Constructing confidence interval using bootstrap inference strategy inference.bootstrap(es.w = eventtime, to.plot = FALSE) } Modified: pkg/man/inference.wilcox.Rd =================================================================== --- pkg/man/inference.wilcox.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/inference.wilcox.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -55,10 +55,14 @@ \examples{ data(StockPriceReturns) data(SplitDates) +## Converting physical dates to event time frame es.results <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) + +## Cumulating event window eventtime <- remap.cumsum(es.w, is.pc = FALSE, base = 0) +## Constructing confidence interval using wilcoxon inference strategy inference.wilcox(es.w = eventtime, to.plot = FALSE) } Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/lmAMM.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -90,13 +90,16 @@ market.returns.purge = FALSE, verbose = FALSE) +## Augmented market model residual amm.result <- lmAMM(firm.returns, X, nlags = 0, verbose = FALSE) names(amm.result) amm.residual <- residuals(amm.result) amm.result <- zoo(amm.residual,as.Date(names(amm.residual))) -output <- merge(amm.result,StockPriceReturns$Infosys,NiftyIndex,all=FALSE) -colnames(output) <- c("amm.residual","raw.returns","nifty.returns") +## Checking output: Comparing augmented market model residual, raw returns, nifty returns +output <- merge(amm.result, StockPriceReturns$Infosys, NiftyIndex, + all=FALSE) +colnames(output) <- c("amm.residual", "raw.returns", "nifty.returns") tail(output) } Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/makeX.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -76,10 +76,10 @@ \examples{ data("AMMData") - market.returns <- AMMData$index.nifty currency.returns <- AMMData$currency.inrusd +## Constructing regressors (independent variables) for AMM X <- makeX(market.returns, others = currency.returns, switch.to.innov = FALSE, Modified: pkg/man/marketResidual.Rd =================================================================== --- pkg/man/marketResidual.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/marketResidual.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -24,10 +24,14 @@ data(StockPriceReturns) data(NiftyIndex) +## Market model residual mm.result <- marketResidual(firm.returns = StockPriceReturns, market.returns = NiftyIndex) -output <- merge(mm.result$Infosys,StockPriceReturns$Infosys,NiftyIndex,all=FALSE) -colnames(output) <- c("market.residual","raw.returns","nifty.returns") + +## Checking output: Comparing market model residual, raw returns, nifty returns +output <- merge(mm.result$Infosys, StockPriceReturns$Infosys, NiftyIndex, + all=FALSE) +colnames(output) <- c("market.residual", "raw.returns", "nifty.returns") tail(output) } Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/phys2eventtime.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -75,16 +75,19 @@ \examples{ data(StockPriceReturns) data(SplitDates) + +## Converting physical dates to event time result <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) +## Checking conversion to event time frame for first successful event date c.no <- as.numeric(colnames(result$z.e)) cnames <- SplitDates[c.no[1],] -phys.output <- as.numeric(result$z.e[as.character(c(-5:5)),as.character(c.no[1])]) -loc <- which(index(StockPriceReturns)%in%SplitDates[c.no[1],"event.when"]) -raw.data <- as.numeric(StockPriceReturns[c((loc-5):(loc+5)),SplitDates[c.no[1],"outcome.unit"]]) -check.output <- cbind(raw.data,phys.output) +phys.output <- as.numeric(result$z.e[as.character(c(-5:5)), as.character(c.no[1])]) +loc <- which(index(StockPriceReturns)%in%SplitDates[c.no[1], "event.when"]) +raw.data <- as.numeric(StockPriceReturns[c((loc-5):(loc+5)), SplitDates[c.no[1], "outcome.unit"]]) +check.output <- cbind(raw.data, phys.output) check.output } \keyword{phys2eventime} Modified: pkg/man/remap.cumprod.Rd =================================================================== --- pkg/man/remap.cumprod.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/remap.cumprod.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -34,14 +34,23 @@ \examples{ data(StockPriceReturns) data(SplitDates) + +## Converting to event time frame es.results <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) + +## Cumulating (geometric product) event window output eventtime <- remap.cumprod(es.w, is.pc = TRUE, is.returns = TRUE, base = 100) + +## Comparing abnormal returns (AR) and cumulative (geometric) abnormal returns (CAR) +check.output <- cbind(es.w[,1], eventtime[,1]) +colnames(check.output) <- c("abnormal.returns", "cumulative.abnormal.returns") +check.output head(eventtime[,1:5]) } Modified: pkg/man/remap.cumsum.Rd =================================================================== --- pkg/man/remap.cumsum.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/remap.cumsum.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -37,13 +37,18 @@ data(StockPriceReturns) data(SplitDates) +## Converting to event time frame es.results <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) + +## Cumulating (arithmetic) event window output eventtime <- remap.cumsum(es.w, is.pc = FALSE, base = 0) -check.output <- cbind(es.w[,1],eventtime[,1]) -colnames(check.output) <- c("abnormal.returns","cumulative.abnormal.returns") + +## Comparing abnormal returns (AR) and cumulative abnormal returns (CAR) +check.output <- cbind(es.w[,1], eventtime[,1]) +colnames(check.output) <- c("abnormal.returns", "cumulative.abnormal.returns") check.output head(eventtime[,1:5]) } Modified: pkg/man/remap.event.reindex.Rd =================================================================== --- pkg/man/remap.event.reindex.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/remap.event.reindex.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -26,10 +26,13 @@ data(StockPriceReturns) data(SplitDates) +## Converting to event time frame es.results <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) es.w <- window(es.results$z.e, start = -5, end = +5) + +## Reindexing event time (t=0) to 100 eventtime <- remap.event.reindex(es.w) head(eventtime[,1:5]) } Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-17 11:04:40 UTC (rev 290) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-22 05:22:17 UTC (rev 291) @@ -72,6 +72,7 @@ market.returns <- AMMData$index.nifty currency.returns <- AMMData$currency.inrusd +## Constructing regressors for AMM regressors <- makeX(market.returns, others = currency.returns, switch.to.innov = TRUE, From noreply at r-forge.r-project.org Mon Apr 28 12:37:32 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 28 Apr 2014 12:37:32 +0200 (CEST) Subject: [Eventstudies-commits] r292 - pkg/man Message-ID: <20140428103732.B55971875B0@r-forge.r-project.org> Author: vikram Date: 2014-04-28 12:37:32 +0200 (Mon, 28 Apr 2014) New Revision: 292 Modified: pkg/man/lmAMM.Rd Log: Minor edit Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-22 05:22:17 UTC (rev 291) +++ pkg/man/lmAMM.Rd 2014-04-28 10:37:32 UTC (rev 292) @@ -78,6 +78,8 @@ \examples{ data("AMMData") +data(StockPriceReturns) +data(NiftyIndex) firm.returns <- AMMData[,"Infosys"] market.returns <- AMMData[,"index.nifty"] From noreply at r-forge.r-project.org Mon Apr 28 13:28:35 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 28 Apr 2014 13:28:35 +0200 (CEST) Subject: [Eventstudies-commits] r293 - in pkg: man vignettes Message-ID: <20140428112835.D113D18705D@r-forge.r-project.org> Author: chiraganand Date: 2014-04-28 13:28:35 +0200 (Mon, 28 Apr 2014) New Revision: 293 Modified: pkg/man/phys2eventtime.Rd pkg/vignettes/AMM.Rnw Log: Fixed phys2eventtime example, correct bib entry name in AMM vignette. Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-28 10:37:32 UTC (rev 292) +++ pkg/man/phys2eventtime.Rd 2014-04-28 11:28:35 UTC (rev 293) @@ -85,8 +85,9 @@ c.no <- as.numeric(colnames(result$z.e)) cnames <- SplitDates[c.no[1],] phys.output <- as.numeric(result$z.e[as.character(c(-5:5)), as.character(c.no[1])]) -loc <- which(index(StockPriceReturns)%in%SplitDates[c.no[1], "event.when"]) -raw.data <- as.numeric(StockPriceReturns[c((loc-5):(loc+5)), SplitDates[c.no[1], "outcome.unit"]]) +loc <- which(index(StockPriceReturns) \%in\% SplitDates[c.no[1], "event.when"]) +raw.data <- as.numeric(StockPriceReturns[c((loc-5):(loc+5)), + SplitDates[c.no[1], "outcome.unit"]]) check.output <- cbind(raw.data, phys.output) check.output } Modified: pkg/vignettes/AMM.Rnw =================================================================== --- pkg/vignettes/AMM.Rnw 2014-04-28 10:37:32 UTC (rev 292) +++ pkg/vignettes/AMM.Rnw 2014-04-28 11:28:35 UTC (rev 293) @@ -172,5 +172,5 @@ using \textit{eventstudy} function. which is presented in \textit{eventstudies} vignette. -\bibliographystyle{jss} \bibliography{amm} +\bibliographystyle{jss} \bibliography{AMM} \end{document} From noreply at r-forge.r-project.org Wed Apr 30 04:13:21 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 04:13:21 +0200 (CEST) Subject: [Eventstudies-commits] r294 - in pkg: R man Message-ID: <20140430021321.B3A01184573@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 04:13:21 +0200 (Wed, 30 Apr 2014) New Revision: 294 Modified: pkg/R/eventstudy.R pkg/R/lmAMM.R pkg/man/lmAMM.Rd Log: Add axis labels if not provided, fixed AMM variable name in the example. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2014-04-28 11:28:35 UTC (rev 293) +++ pkg/R/eventstudy.R 2014-04-30 02:13:21 UTC (rev 294) @@ -147,11 +147,32 @@ object$outcomes } -plot.es <- function(x, ...){ +plot.es <- function(x, xlab = NULL, ylab = NULL, ...){ big <- max(abs(x$eventstudy.output)) hilo <- c(-big,big) width <- (nrow(x$eventstudy.output)-1)/2 - plot(-width:width, x$eventstudy.output[,2], type="l", lwd=2, ylim=hilo, ...) + + ## assign own labels if they're missing + if (is.null(ylab)) { + if (x$remap == "cumsum") { + remapLabel <- "Cum." + } else if (x$remap == "cumprod") { + remapLabel <- "Cum. product" + } else if (x$remap == "reindex") { + remapLabel <- "Re-index" + } else { + remapLabel <- "" + } + ylab <- paste0("(", remapLabel, ")", " change in response series (%)") + } + + if (is.null(xlab)) { + xlab <- "Event time" + } + + plot(-width:width, x$eventstudy.output[,2], type="l", lwd=2, ylim=hilo, + xlab = xlab, ylab = ylab, ...) + points(-width:width, x$eventstudy.output[,2]) lines(-width:width, x$eventstudy.output[,"2.5%"], lwd=1, lty=2, ...) Modified: pkg/R/lmAMM.R =================================================================== --- pkg/R/lmAMM.R 2014-04-28 11:28:35 UTC (rev 293) +++ pkg/R/lmAMM.R 2014-04-30 02:13:21 UTC (rev 294) @@ -337,13 +337,24 @@ print.default(x$exposures) } -plot.amm <- function(x, ...){ +plot.amm <- function(x, xlab = NULL, ylab = NULL, ...){ tmp.x <- zoo(as.numeric(resid(x)), as.Date(names(resid(x)))) tmp.f <- zoo(x$model$firm.returns, index(tmp.x)) tmp <- merge(tmp.x,tmp.f) colnames(tmp) <- c("amm.residuals","firm.returns") - plot(tmp, screen=1, lty=1:2, lwd=2, col=c("indian red", "navy blue"),ylab="", - xlab="") - legend("topleft",legend=c("AMM residual","Firm returns"),lty=1:2, lwd=2, + + ## assign own labels if they're missing + if (is.null(ylab)) { + ylab <- paste0("AMM residuals") + } + + if (is.null(xlab)) { + xlab <- "" + } + + plot(tmp, screen=1, lty=1:2, lwd=2, col=c("indian red", "navy blue"), + ylab = ylab, xlab = xlab, ...) + + legend("topleft",legend=c("AMM residual","Firm returns"), lty=1:2, lwd=2, col=c("indian red", "navy blue"), bty='n') } Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-28 11:28:35 UTC (rev 293) +++ pkg/man/lmAMM.Rd 2014-04-30 02:13:21 UTC (rev 294) @@ -96,10 +96,10 @@ amm.result <- lmAMM(firm.returns, X, nlags = 0, verbose = FALSE) names(amm.result) amm.residual <- residuals(amm.result) -amm.result <- zoo(amm.residual,as.Date(names(amm.residual))) +amm.residual <- zoo(amm.residual,as.Date(names(amm.residual))) ## Checking output: Comparing augmented market model residual, raw returns, nifty returns -output <- merge(amm.result, StockPriceReturns$Infosys, NiftyIndex, +output <- merge(amm.residual, StockPriceReturns$Infosys, NiftyIndex, all=FALSE) colnames(output) <- c("amm.residual", "raw.returns", "nifty.returns") tail(output) From noreply at r-forge.r-project.org Wed Apr 30 06:27:08 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 06:27:08 +0200 (CEST) Subject: [Eventstudies-commits] r295 - pkg/R Message-ID: <20140430042708.171B51872C0@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 06:27:07 +0200 (Wed, 30 Apr 2014) New Revision: 295 Modified: pkg/R/eventstudy.R Log: Fixed lmAMM call for multiple firms, fixed lmAMM for single firm: handle univariate series gracefully. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2014-04-30 02:13:21 UTC (rev 294) +++ pkg/R/eventstudy.R 2014-04-30 04:27:07 UTC (rev 295) @@ -11,7 +11,7 @@ # type = "marketResidual", "excessReturn", "AMM", "None" ## arguments to the model extra.var <- list(...) - + if (type == "None" && !is.null(firm.returns)) { outputModel <- firm.returns } @@ -23,6 +23,11 @@ ### Run models ## AMM if (type == "lmAMM") { + if (is.null(ncol(firm.returns))) { + stop("firm.returns should be a zoo series with at least one column. Use '[' with 'drop = FALSE'.") + } + firmNames <- colnames(firm.returns) + ## AMM residual to time series timeseriesAMM <- function(firm.returns, X, verbose = FALSE, nlags = 1) { tmp <- resid(lmAMM(firm.returns = firm.returns, @@ -53,7 +58,8 @@ verbose = FALSE, nlags = 1) }) - outputModel <- do.call("merge",tmp.resid) + outputModel <- zoo(tmp.resid, + order.by = as.Date(rownames(tmp.resid))) } } ## end AMM @@ -71,7 +77,13 @@ index(outputModel) <- as.Date(index(outputModel)) ### Convert to event frame - es <- phys2eventtime(z=outputModel, events=eventList, width=0) + ## change the dimensions if there is only one firm + if (is.null(ncol(outputModel))) { + attr(outputModel, "dim") <- c(length(outputModel), 1) + attr(outputModel, "dimnames") <- list(NULL, firmNames) + colnames(outputModel) <- firmNames + } + es <- phys2eventtime(z = outputModel, events=eventList, width=0) if (is.null(es$z.e) || length(es$z.e) == 0) { es.w <- NULL From noreply at r-forge.r-project.org Wed Apr 30 06:29:44 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 06:29:44 +0200 (CEST) Subject: [Eventstudies-commits] r296 - pkg/man Message-ID: <20140430042944.F23D21872FA@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 06:29:44 +0200 (Wed, 30 Apr 2014) New Revision: 296 Modified: pkg/man/eventstudy.Rd pkg/man/lmAMM.Rd Log: Added plotting to examples, added eventstudy example using lmAMM. Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2014-04-30 04:27:07 UTC (rev 295) +++ pkg/man/eventstudy.Rd 2014-04-30 04:29:44 UTC (rev 296) @@ -4,7 +4,7 @@ \title{Event study analysis} \description{ - \sQuote{eventstudy} provides a easy interface that integrates all + \sQuote{eventstudy} provides an easy interface that integrates all functionalities of package \pkg{eventstudies} to undertake event study analysis. It allows the user to specify the type of data adjustment to be done (using the augmented market model functionalities of the @@ -30,10 +30,9 @@ } \item{eventList}{ - a \code{data.frame} of two columns with event dates (with the column - name \dQuote{event.when}) and column names - of the \sQuote{response} series from \sQuote{firm.returns} (with the - column name \dQuote{outcome.unit}. + a \code{data.frame} of two columns with event dates (colname: + \dQuote{event.when}) and column names of the \sQuote{response} + series from \sQuote{firm.returns} (colname \dQuote{outcome.unit}). } \item{width}{an \sQuote{integer} of length 1 that specifies a @@ -218,6 +217,30 @@ inference = TRUE, inference.strategy = "bootstrap") str(es) +plot(es) + +## Event study using Augment Market Model +data("AMMData") +events <- data.frame(outcome.unit = "Infosys", + event.when = c("2012-03-01", "2012-04-01"), + stringsAsFactors = FALSE) + +es <- eventstudy(firm.returns = AMMData[, "Infosys", drop = FALSE], + eventList = events, + width = 10, + type = "lmAMM", + to.remap = TRUE, + remap = "cumsum", + inference = TRUE, + inference.strategy = "bootstrap", + ## model args + market.returns = AMMData[, "index.nifty"], + others = AMMData[, "currency.inrusd"], + switch.to.innov = FALSE, + market.returns.purge = FALSE + ) +str(es) +plot(es) } \keyword{eventstudy} Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-30 04:27:07 UTC (rev 295) +++ pkg/man/lmAMM.Rd 2014-04-30 04:29:44 UTC (rev 296) @@ -94,15 +94,17 @@ ## Augmented market model residual amm.result <- lmAMM(firm.returns, X, nlags = 0, verbose = FALSE) -names(amm.result) +plot(amm.result) + amm.residual <- residuals(amm.result) amm.residual <- zoo(amm.residual,as.Date(names(amm.residual))) ## Checking output: Comparing augmented market model residual, raw returns, nifty returns output <- merge(amm.residual, StockPriceReturns$Infosys, NiftyIndex, - all=FALSE) -colnames(output) <- c("amm.residual", "raw.returns", "nifty.returns") -tail(output) + all = FALSE) +colnames(output) <- c("AMM Residual", "Raw Returns", "Nifty Returns") +tail(output) +plot(output) } \keyword{lmAMM} From noreply at r-forge.r-project.org Wed Apr 30 06:40:10 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 06:40:10 +0200 (CEST) Subject: [Eventstudies-commits] r297 - pkg/R Message-ID: <20140430044011.049D51811F4@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 06:40:10 +0200 (Wed, 30 Apr 2014) New Revision: 297 Modified: pkg/R/eventstudy.R Log: Made print and summary functions same, summary is calling print, can be changed at a later time. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2014-04-30 04:29:44 UTC (rev 296) +++ pkg/R/eventstudy.R 2014-04-30 04:40:10 UTC (rev 297) @@ -144,19 +144,18 @@ ######################### ## Functions for class es ######################### + print.es <- function(x, ...){ - cat("The", x$inference, "inference output for CI and", - colnames(x$eventstudy.output)[2], "response:", "\n") - print.default(x$eventstudy.output) + cat("Event study", colnames(x$eventstudy.output)[2], "response with", + x$inference, "inference for CI:\n") + print(x$eventstudy.output) + cat("\n","Event outcome has",length(which(x$outcomes=="success")), + "successful outcomes out of", length(x$outcomes),"events:","\n") + x$outcomes } summary.es <- function(object, ...){ - cat("Event study", colnames(object$eventstudy.output)[2], "response with", - object$inference, "inference for CI:\n") - print(object$eventstudy.output) - cat("\n","Event outcome has",length(which(object$outcomes=="success")), - "successful outcomes out of", length(object$outcomes),"events:","\n") - object$outcomes + print.es(object, ...) } plot.es <- function(x, xlab = NULL, ylab = NULL, ...){ From noreply at r-forge.r-project.org Wed Apr 30 07:32:12 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 07:32:12 +0200 (CEST) Subject: [Eventstudies-commits] r298 - pkg/R Message-ID: <20140430053212.77E1E187380@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 07:32:12 +0200 (Wed, 30 Apr 2014) New Revision: 298 Modified: pkg/R/eventstudy.R Log: Fixed calling of makeX from eventstudy function, fixed default print method. Modified: pkg/R/eventstudy.R =================================================================== --- pkg/R/eventstudy.R 2014-04-30 04:40:10 UTC (rev 297) +++ pkg/R/eventstudy.R 2014-04-30 05:32:12 UTC (rev 298) @@ -37,11 +37,7 @@ tmp.res <- zoo(x = tmp, order.by = as.Date(names(tmp))) } ## Estimating AMM regressors - regressors <- makeX(market.returns = extra.var$market.returns, - others = extra.var$others, - switch.to.innov = extra.var$switch.to.innov, - market.returns.purge = extra.var$market.returns.purge, - nlags = extra.var$nlags) + regressors <- makeX(...) if(NCOL(firm.returns)==1){ ## One firm outputModel <- timeseriesAMM(firm.returns = firm.returns, @@ -83,6 +79,7 @@ attr(outputModel, "dimnames") <- list(NULL, firmNames) colnames(outputModel) <- firmNames } + es <- phys2eventtime(z = outputModel, events=eventList, width=0) if (is.null(es$z.e) || length(es$z.e) == 0) { @@ -151,7 +148,7 @@ print(x$eventstudy.output) cat("\n","Event outcome has",length(which(x$outcomes=="success")), "successful outcomes out of", length(x$outcomes),"events:","\n") - x$outcomes + print(x$outcomes) } summary.es <- function(object, ...){ @@ -159,6 +156,10 @@ } plot.es <- function(x, xlab = NULL, ylab = NULL, ...){ + if (NCOL(x$eventstudy.output) < 3) { + cat("Error: No confidence bands available to plot.\n") + return(invisible(NULL)) + } big <- max(abs(x$eventstudy.output)) hilo <- c(-big,big) width <- (nrow(x$eventstudy.output)-1)/2 From noreply at r-forge.r-project.org Wed Apr 30 07:33:29 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 07:33:29 +0200 (CEST) Subject: [Eventstudies-commits] r299 - pkg/man Message-ID: <20140430053329.1190A1873AA@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 07:33:28 +0200 (Wed, 30 Apr 2014) New Revision: 299 Modified: pkg/man/eventstudy.Rd pkg/man/lmAMM.Rd Log: Use the default args in lmAMM example. Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2014-04-30 05:32:12 UTC (rev 298) +++ pkg/man/eventstudy.Rd 2014-04-30 05:33:28 UTC (rev 299) @@ -236,7 +236,6 @@ ## model args market.returns = AMMData[, "index.nifty"], others = AMMData[, "currency.inrusd"], - switch.to.innov = FALSE, market.returns.purge = FALSE ) str(es) Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-30 05:32:12 UTC (rev 298) +++ pkg/man/lmAMM.Rd 2014-04-30 05:33:28 UTC (rev 299) @@ -78,8 +78,8 @@ \examples{ data("AMMData") -data(StockPriceReturns) -data(NiftyIndex) +data("StockPriceReturns") +data("NiftyIndex") firm.returns <- AMMData[,"Infosys"] market.returns <- AMMData[,"index.nifty"] From noreply at r-forge.r-project.org Wed Apr 30 20:56:29 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 30 Apr 2014 20:56:29 +0200 (CEST) Subject: [Eventstudies-commits] r300 - pkg/man Message-ID: <20140430185629.78531187095@r-forge.r-project.org> Author: chiraganand Date: 2014-04-30 20:56:29 +0200 (Wed, 30 Apr 2014) New Revision: 300 Modified: pkg/man/ees.Rd pkg/man/eesPlot.Rd pkg/man/eventstudy.Rd pkg/man/inference.bootstrap.Rd pkg/man/inference.wilcox.Rd pkg/man/lmAMM.Rd pkg/man/makeX.Rd pkg/man/manyfirmssubperiod.lmAMM.Rd pkg/man/phys2eventtime.Rd pkg/man/remap.cumprod.Rd pkg/man/remap.cumsum.Rd pkg/man/remap.event.reindex.Rd pkg/man/subperiod.lmAMM.Rd Log: Modified author names in the man pages. Modified: pkg/man/ees.Rd =================================================================== --- pkg/man/ees.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/ees.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -87,7 +87,7 @@ } -\author{Vikram Bahure} +\author{Vikram Bahure, Vimal Balasubramaniam} \examples{ library(eventstudies) Modified: pkg/man/eesPlot.Rd =================================================================== --- pkg/man/eesPlot.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/eesPlot.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -66,6 +66,8 @@ and also available at http://macrofinance.nipfp.org.in/releases/PatnaikShahSingh2013_Foreign_Investors.html } +\author{Vikram Bahure, Vimal Balasubramaniam} + \examples{ library(eventstudies) data(EESData) Modified: pkg/man/eventstudy.Rd =================================================================== --- pkg/man/eventstudy.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/eventstudy.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -188,7 +188,7 @@ } } -\author{Vikram Bahure} +\author{Ajay Shah, Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} \seealso{ \code{\link{lmAMM}}, \code{\link{marketResidual}}, @@ -235,8 +235,8 @@ inference.strategy = "bootstrap", ## model args market.returns = AMMData[, "index.nifty"], - others = AMMData[, "currency.inrusd"], - market.returns.purge = FALSE + others = AMMData[, c("currency.inrusd", "call.money.rate")], + market.returns.purge = TRUE ) str(es) plot(es) Modified: pkg/man/inference.bootstrap.Rd =================================================================== --- pkg/man/inference.bootstrap.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/inference.bootstrap.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -56,6 +56,8 @@ \code{\link{inference.wilcox}} } +\author{Vikram Bahure, Vimal Balasubramaniam} + \examples{ data(StockPriceReturns) data(SplitDates) Modified: pkg/man/inference.wilcox.Rd =================================================================== --- pkg/man/inference.wilcox.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/inference.wilcox.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -45,7 +45,7 @@ \value{A \sQuote{matrix} with 3 columns: the lower confidence interval (CI), the mean, and the upper CI which are the result of wilcox inference.} -\author{Vikram Bahure} +\author{Vikram Bahure, Vimal Balasubramaniam} \seealso{ \code{\link{phys2eventtime}} Modified: pkg/man/lmAMM.Rd =================================================================== --- pkg/man/lmAMM.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/lmAMM.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -69,7 +69,7 @@ \item{nlags}{shows the lag length provided by user.} } -\author{Ajay Shah, Vimal Balasubramaniam} +\author{Ajay Shah, Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} \seealso{ \code{\link{makeX}} Modified: pkg/man/makeX.Rd =================================================================== --- pkg/man/makeX.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/makeX.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -72,7 +72,7 @@ \value{a time-series object of regressors is returned.} -\author{Ajay Shah, Vimal Balasubramaniam} +\author{Ajay Shah, Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} \examples{ data("AMMData") Modified: pkg/man/manyfirmssubperiod.lmAMM.Rd =================================================================== --- pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/manyfirmssubperiod.lmAMM.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -52,7 +52,7 @@ \dQuote{periodnames}. } -\author{Ajay Shah, Vimal Balasubramaniam} +\author{Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} \seealso{ \code{\link{lmAMM}} Modified: pkg/man/phys2eventtime.Rd =================================================================== --- pkg/man/phys2eventtime.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/phys2eventtime.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -72,6 +72,8 @@ \code{\link{findInterval}} } +\author{Ajay Shah, Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} + \examples{ data(StockPriceReturns) data(SplitDates) @@ -80,10 +82,12 @@ result <- phys2eventtime(z = StockPriceReturns, events = SplitDates, width = 5) +print(result$z.e[as.character(-3:3)]) +print(result$outcomes) ## Checking conversion to event time frame for first successful event date c.no <- as.numeric(colnames(result$z.e)) -cnames <- SplitDates[c.no[1],] +cnames <- SplitDates[c.no[1], ] phys.output <- as.numeric(result$z.e[as.character(c(-5:5)), as.character(c.no[1])]) loc <- which(index(StockPriceReturns) \%in\% SplitDates[c.no[1], "event.when"]) raw.data <- as.numeric(StockPriceReturns[c((loc-5):(loc+5)), Modified: pkg/man/remap.cumprod.Rd =================================================================== --- pkg/man/remap.cumprod.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/remap.cumprod.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -31,6 +31,8 @@ \code{\link{phys2eventtime}} } +\author{Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} + \examples{ data(StockPriceReturns) data(SplitDates) Modified: pkg/man/remap.cumsum.Rd =================================================================== --- pkg/man/remap.cumsum.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/remap.cumsum.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -33,6 +33,8 @@ \code{\link{phys2eventtime}} } +\author{Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} + \examples{ data(StockPriceReturns) data(SplitDates) Modified: pkg/man/remap.event.reindex.Rd =================================================================== --- pkg/man/remap.event.reindex.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/remap.event.reindex.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -22,6 +22,9 @@ \seealso{ \code{\link{phys2eventtime}} } + +\author{Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} + \examples{ data(StockPriceReturns) data(SplitDates) Modified: pkg/man/subperiod.lmAMM.Rd =================================================================== --- pkg/man/subperiod.lmAMM.Rd 2014-04-30 05:33:28 UTC (rev 299) +++ pkg/man/subperiod.lmAMM.Rd 2014-04-30 18:56:29 UTC (rev 300) @@ -60,7 +60,7 @@ } } -\author{Vimal Balasubramaniam} +\author{Chirag Anand, Vikram Bahure, Vimal Balasubramaniam} \seealso{ \code{\link{lmAMM}}}