[Eventstudies-commits] r226 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Mar 26 18:39:05 CET 2014
Author: chiraganand
Date: 2014-03-26 18:39:05 +0100 (Wed, 26 Mar 2014)
New Revision: 226
Modified:
pkg/R/eventstudy.R
Log:
Fixed the code to use lmAMM, fixed reading of extra args for the model, changed code formatting.
Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R 2014-03-26 17:30:54 UTC (rev 225)
+++ pkg/R/eventstudy.R 2014-03-26 17:39:05 UTC (rev 226)
@@ -9,7 +9,8 @@
inference.strategy = "bootstrap",
...) {
# type = "marketResidual", "excessReturn", "AMM", "None"
- extra.var <- unlist(...)
+ extra.var <- list(...)
+
if (type == "None" && !is.null(firm.returns)) {
outputModel <- firm.returns
}
@@ -20,34 +21,40 @@
### Run models
## AMM
- if (type == "AMM") {
+ if (type == "lmAMM") {
## AMM residual to time series
- timeseriesAMM <- function(firm.returns,X,verbose=FALSE,nlags=1){
- tmp <- resid(lmAMM(firm.returns,X,nlags))
- tmp.res <- zoo(tmp,as.Date(names(tmp)))
+ timeseriesAMM <- function(firm.returns, X, verbose = FALSE, nlags = 1) {
+ tmp <- resid(lmAMM(firm.returns = firm.returns,
+ X = X,
+ nlags = nlags,
+ verbose = FALSE))
+ 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,
- market.returns.purge=extra.var$market.returns.purge,
- nlags=extra.var$nlags,
- switch.to.innov=extra.var$switch.to.innov)
+ 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)
if(NCOL(firm.returns)==1){
## One firm
- outputModel <- timeseriesAMM(firm.returns,X=regressors,
- verbose=FALSE, nlags=1)
-
+ outputModel <- timeseriesAMM(firm.returns = firm.returns,
+ X = regressors,
+ verbose = FALSE,
+ nlags = 1)
} else {
## More than one firm
# Extracting and merging
- tmp.resid <- sapply(colnames(firm.returns),function(y)
- timeseriesAMM(firm.returns[,y],
- X=regressors,
- verbose=FALSE,
- nlags=1))
+ tmp.resid <- sapply(colnames(firm.returns), function(y)
+ {
+ timeseriesAMM(firm.returns = firm.returns[,y],
+ X = regressors,
+ verbose = FALSE,
+ nlags = 1)
+ })
outputModel <- do.call("merge",tmp.resid)
- }
- }
+ }
+ } ## end AMM
## marketResidual
if (type == "marketResidual") {
More information about the Eventstudies-commits
mailing list