[Eventstudies-commits] r361 - in pkg: R inst/tests man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri May 16 22:45:56 CEST 2014
Author: chiraganand
Date: 2014-05-16 22:45:56 +0200 (Fri, 16 May 2014)
New Revision: 361
Modified:
pkg/R/eventstudy.R
pkg/inst/tests/test_inr_inference.R
pkg/inst/tests/test_interfaces.R
pkg/man/eventstudy.Rd
pkg/vignettes/eventstudies.Rnw
Log:
Modified the eventstudy interface, changed the man pages and test cases.
Modified: pkg/R/eventstudy.R
===================================================================
--- pkg/R/eventstudy.R 2014-05-16 12:37:58 UTC (rev 360)
+++ pkg/R/eventstudy.R 2014-05-16 20:45:56 UTC (rev 361)
@@ -7,16 +7,20 @@
remap = "cumsum",
inference = TRUE,
inference.strategy = "bootstrap",
- ...) {
+ model.args = NULL) {
if (type == "None" && !is.null(firm.returns)) {
outputModel <- firm.returns
- if (length(list(...)) != 0) {
+ if (length(model.args) != 0) {
warning(deparse("type"), " = ", deparse("None"),
" does not take extra arguments, ignoring them.")
}
}
+ if (type != "None" && is.null(model.args)) {
+ stop("modelArgs cannot be NULL when type is not None.")
+ }
+
if (is.levels == TRUE) {
firm.returns <- diff(log(firm.returns)) * 100
}
@@ -26,38 +30,48 @@
stop("firm.returns should be a zoo series with at least one column. Use '[' with 'drop = FALSE'.")
}
firmNames <- colnames(firm.returns)
- ## Extracting elipsis values
- extra.var <- list(...)
- cat("I am here:", extra.var$nlags, "\n")
### Run models
## AMM
if (type == "lmAMM") {
- ## AMM residual to time series
- timeseriesAMM <- function(firm.returns, X, verbose = FALSE) {
- tmp <- resid(lmAMM(firm.returns = firm.returns,
- X = X,
- verbose = FALSE, nlags = extra.var$nlags))
- tmp.res <- zoo(x = tmp, order.by = as.Date(names(tmp)))
+
+ ## Estimating AMM regressors
+ args.makeX <- model.args[names(model.args) %in% formalArgs(makeX)]
+ if (!is.null(model.args$nlag.makeX)) {
+ args.makeX$nlags <- model.args$nlag.makeX
}
- ## Estimating AMM regressors
- regressors <- makeX(...)
+ regressors <- do.call(makeX, args.makeX)
+
+ args.lmAMM <- model.args[names(model.args) %in% formalArgs(lmAMM)]
+ args.lmAMM$X <- regressors
+
+ if (!is.null(model.args$nlag.lmAMM)) {
+ args.lmAMM$nlags <- model.args$nlag.lmAMM
+ }
+
if(NCOL(firm.returns)==1){
## One firm
- outputModel <- timeseriesAMM(firm.returns = firm.returns,
- X = regressors,
- verbose = FALSE)
-
+ args.lmAMM$firm.returns <- firm.returns
+ tmp <- resid(do.call(lmAMM, args.lmAMM))
+ if (is.null(tmp)) {
+ cat("lmAMM() returned NULL\n")
+ return(NULL)
+ }
+ outputModel <- zoo(x = tmp, order.by = as.Date(names(tmp)))
+
} else {
## More than one firm
# Extracting and merging
tmp.resid <- lapply(colnames(firm.returns), function(y)
{
- timeseriesAMM(firm.returns = firm.returns[,y],
- X = regressors,
- verbose = FALSE)
-
- })
+ args.lmAMM$firm.returns <- firm.returns[, y]
+ tmp <- resid(do.call(lmAMM, args.lmAMM))
+ if (is.null(tmp)) {
+ cat("lmAMM() returned NULL\n")
+ return(NULL)
+ }
+ return(zoo(x = tmp, order.by = as.Date(names(tmp))))
+ })
names(tmp.resid) <- colnames(firm.returns)
outputModel <- do.call(merge.zoo, tmp.resid)
}
@@ -65,12 +79,12 @@
## marketResidual
if (type == "marketResidual") {
- outputModel <- marketResidual(firm.returns, ...)
+ outputModel <- marketResidual(firm.returns, model.args$market.returns)
}
## excessReturn
if (type == "excessReturn") {
- outputModel <- excessReturn(firm.returns, ...)
+ outputModel <- excessReturn(firm.returns, model.args$market.returns)
}
### Converting index outputModel to Date
Modified: pkg/inst/tests/test_inr_inference.R
===================================================================
--- pkg/inst/tests/test_inr_inference.R 2014-05-16 12:37:58 UTC (rev 360)
+++ pkg/inst/tests/test_inr_inference.R 2014-05-16 20:45:56 UTC (rev 361)
@@ -7,13 +7,13 @@
inr_returns <- diff(log(INR))[-1]
-eventslist <- data.frame(name=rep("inr",10),
- when=as.Date(c(
+eventslist <- data.frame(when=as.Date(c(
"2010-04-20","2010-07-02","2010-07-27",
"2010-09-16","2010-11-02","2011-01-25",
"2011-03-17","2011-05-03","2011-06-16",
"2011-07-26")
- )
+ ),
+ name=rep("inr",10)
)
event_time_data <- phys2eventtime(inr_returns[, , drop = FALSE] , eventslist,width=10)
Modified: pkg/inst/tests/test_interfaces.R
===================================================================
--- pkg/inst/tests/test_interfaces.R 2014-05-16 12:37:58 UTC (rev 360)
+++ pkg/inst/tests/test_interfaces.R 2014-05-16 20:45:56 UTC (rev 361)
@@ -21,7 +21,7 @@
test_es <- eventstudy(firm.returns = test_returns,
eventList = test_events,
width = 3,
- market.returns = NiftyIndex)
+ model.args = list(market.returns = NiftyIndex))
expect_that(expected_mean, equals(test_es$eventstudy.output[, "Mean"]))
expect_that(expected_outcomes, equals(test_es$outcomes))
@@ -65,8 +65,8 @@
eventList = test_events,
width = 3,
type = "lmAMM",
- market.returns = NiftyIndex[index(USDINR)],
- others = test_others, nlags = 1)
+ model.args = list(market.returns = NiftyIndex[index(USDINR)],
+ others = test_others))
expect_that(expected_mean, equals(test_es$eventstudy.output[, "Mean"]))
expect_that(expected_outcomes, equals(test_es$outcomes))
@@ -88,7 +88,7 @@
eventList = test_events,
width = 3,
type = "excessReturn",
- market.returns = NiftyIndex)
+ model.args = list(market.returns = NiftyIndex))
expect_that(expected_mean, equals(test_es$eventstudy.output[, "Mean"]))
expect_that(expected_outcomes, equals(test_es$outcomes))
Modified: pkg/man/eventstudy.Rd
===================================================================
--- pkg/man/eventstudy.Rd 2014-05-16 12:37:58 UTC (rev 360)
+++ pkg/man/eventstudy.Rd 2014-05-16 20:45:56 UTC (rev 361)
@@ -21,7 +21,7 @@
remap = "cumsum",
inference = TRUE,
inference.strategy = "bootstrap",
- ...)
+ model.args = NULL)
}
\arguments{
@@ -74,7 +74,7 @@
and \dQuote{wilcox}.
}
- \item{...}{
+ \item{model.args}{
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
@@ -104,7 +104,7 @@
\item{\dQuote{None}: does not use any model.}
}
- Arguments to a model type can be sent inside \sQuote{...}. See
+ Arguments to a model type can be sent inside \sQuote{model.args}. See
\sQuote{Model arguments} section for details on accepted
fields.
@@ -122,7 +122,7 @@
\code{\link{inference.bootstrap}} and \code{\link{inference.wilcox}}
for more details.
- \sQuote{...} is directly supplied to the model mentioned in the
+ \sQuote{model.args} is directly supplied to the model mentioned in the
\dQuote{type} argument. See section on \sQuote{Model arguments} for
more details.
@@ -131,7 +131,7 @@
}
\section{\bold{Model arguments}}{
- Each model can take extra arguments (supplied as \sQuote{...}) apart
+ Each model can take extra arguments (supplied as \sQuote{model.args}) apart
from mandatory ones for finer control over the analysis. Check the
respective function documentation for definitions. The arguments from
the relevant functions are listed here:
@@ -146,11 +146,12 @@
- others \cr
- switch.to.innov \cr
- market.returns.purge \cr
- - nlags \cr
+ - nlag.makeX \cr
+ - nlag.lmAMM \cr
- dates \cr
- verbose \cr
- Note: arguments are directly passed to \sQuote{makeX}, see
+ Note: arguments (except nlag.lmAMM) are directly passed to \sQuote{makeX}, see
\code{\link{lmAMM}} for more details. \cr
}
}
@@ -243,7 +244,9 @@
remap = "cumsum",
inference = TRUE,
inference.strategy = "bootstrap",
- market.returns = OtherReturns[, "NiftyIndex"],
+ model.args = list(
+ market.returns = OtherReturns[, "NiftyIndex"]
+ )
)
str(es)
plot(es)
@@ -262,9 +265,13 @@
inference = TRUE,
inference.strategy = "bootstrap",
# model arguments
- market.returns = OtherReturns[, "NiftyIndex"],
- others = OtherReturns[, c("USDINR", "CallMoneyRate")],
- market.returns.purge = TRUE, nlags = 1
+ model.args = list(
+ market.returns = OtherReturns[, "NiftyIndex"],
+ others = OtherReturns[, c("USDINR", "CallMoneyRate")],
+ market.returns.purge = TRUE,
+ nlag.makeX = 5,
+ nlag.lmAMM = NULL
+ )
)
str(es)
plot(es)
Modified: pkg/vignettes/eventstudies.Rnw
===================================================================
--- pkg/vignettes/eventstudies.Rnw 2014-05-16 12:37:58 UTC (rev 360)
+++ pkg/vignettes/eventstudies.Rnw 2014-05-16 20:45:56 UTC (rev 361)
@@ -178,7 +178,7 @@
remap = "cumsum",
inference = TRUE,
inference.strategy = "bootstrap",
- market.returns=OtherReturns$NiftyIndex
+ model.args = list(market.returns=OtherReturns$NiftyIndex)
)
@
@@ -236,12 +236,13 @@
remap = "cumsum",
inference = TRUE,
inference.strategy = "bootstrap",
- market.returns=OtherReturns$NiftyIndex,
- others=OtherReturns$USDINR,
- market.returns.purge=TRUE,
- nlags = 1
+ model.args = list(
+ market.returns=OtherReturns$NiftyIndex,
+ others=OtherReturns$USDINR,
+ market.returns.purge=TRUE
+ )
)
-@
+@
Here the additional regressor on the augmented market model is the
returns on the exchange rate, which is the slot `\texttt{USDINR}' in
More information about the Eventstudies-commits
mailing list