[Eventstudies-commits] r416 - pkg/inst/tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 8 17:07:37 CEST 2015


Author: sargam_jain
Date: 2015-04-08 17:07:37 +0200 (Wed, 08 Apr 2015)
New Revision: 416

Added:
   pkg/inst/tests/test_functionality_inference.R
   pkg/inst/tests/test_userinput_inference.bootstrap.R
   pkg/inst/tests/test_userinput_remap.R
Log:
Test cases for inference and remap functions.

Added: pkg/inst/tests/test_functionality_inference.R
===================================================================
--- pkg/inst/tests/test_functionality_inference.R	                        (rev 0)
+++ pkg/inst/tests/test_functionality_inference.R	2015-04-08 15:07:37 UTC (rev 416)
@@ -0,0 +1,52 @@
+library(testthat)
+context("functionality")
+
+## 1. Test for class of arguments
+
+
+
+test_that("functionality for inference functions", {
+  library(eventstudies)
+  ## Data of Stock Prices
+  test.data0 <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17,
+                           35.89, 36.19, 37.1317, 36.7033, 37.7933,
+                           37.8533, 285.325, 292.6, 290.025, 286.2,
+                           290.075, 295.05, 289.325, 285.625, 293.7,
+                           298.5, 289.05, 704.5438, 708.35, 735.835,
+                           710.625, 711.65, 731.012, 727.575,
+                           715.0187, 724.2, 713.1875, 695.1812),
+                         .Dim = c(11L, 3L),
+                         .Dimnames = list( NULL, c("ITC",
+                           "Reliance", "TCS")),
+                         index = structure(c(12418,
+                           12419, 12422, 12423, 12424,
+                           12425, 12426, 12429, 12430,
+                           12431, 12432),
+                           class = "Date"),
+                         class = "zoo")
+  test.data0 <- diff(log(test.data0))
+
+  ## List of events
+  test.eventslist0 <- data.frame(name=c("ITC","Reliance","TCS",
+                                   "ITC","Reliance","Junk"),
+                                 when=as.Date(c("2004-01-02",
+                                   "2004-01-08", "2004-01-14",
+                                   "2005-01-15", "2004-01-01",
+                                   "2005-01-01")))
+  test.eventslist0$name <- as.character(test.eventslist0$name)
+  
+  cat("\nTesting for class of arguments")
+  esConvertNormal0 <- phys2eventtime(z = test.data0,
+                                     events = test.eventslist0,
+                                     width = 1)
+  es.test.w0 <- window(esConvertNormal0$z.e,
+                       start = -1,
+                       end = +1)
+  
+  test.eventtime0 <- remap.cumsum(es.test.w0, is.pc = FALSE,
+                                  base = 0)
+  test.eventtime1 <- coredata(test.eventtime0)
+
+  test.boot1 <- inference.bootstrap(es.w = test.eventtime1,
+                                    to.plot = FALSE)
+  

Added: pkg/inst/tests/test_userinput_inference.bootstrap.R
===================================================================
--- pkg/inst/tests/test_userinput_inference.bootstrap.R	                        (rev 0)
+++ pkg/inst/tests/test_userinput_inference.bootstrap.R	2015-04-08 15:07:37 UTC (rev 416)
@@ -0,0 +1,75 @@
+library(testthat)
+context("userinput")
+
+## 1. Test for normal values
+## 2. Test for univariate zoo object: one firm data
+
+
+test_that("userinput for inference functions", {
+    library(eventstudies)
+    ## Data of Stock Prices
+    test.data <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17,
+                             35.89, 36.19, 37.1317, 36.7033, 37.7933,
+                             37.8533, 285.325, 292.6, 290.025, 286.2,
+                             290.075, 295.05, 289.325, 285.625, 293.7,
+                             298.5, 289.05, 704.5438, 708.35, 735.835,
+                             710.625, 711.65, 731.012, 727.575,
+                             715.0187, 724.2, 713.1875, 695.1812),
+                           .Dim = c(11L, 3L),
+                           .Dimnames = list( NULL, c("ITC",
+                             "Reliance", "TCS")),
+                           index = structure(c(12418,
+                             12419, 12422, 12423, 12424,
+                             12425, 12426, 12429, 12430,
+                             12431, 12432),
+                             class = "Date"),
+                           class = "zoo")
+    test.data <- diff(log(test.data))
+    ## List of events
+    test.eventslist <- data.frame(name=c("ITC","Reliance","TCS",
+                                    "ITC","Reliance","Junk"),
+                                  when=as.Date(c("2004-01-02",
+                                    "2004-01-08", "2004-01-14",
+                                    "2005-01-15", "2004-01-01",
+                                    "2005-01-01")))
+    test.eventslist$name <- as.character(test.eventslist$name)
+
+### Testing function for normal values of width
+    
+    cat("\nTesting for normal input values")
+    esConvertNormal0 <- phys2eventtime(z = test.data,
+                                       events = test.eventslist,
+                                       width = 1)
+    es.test.w0 <- window(esConvertNormal0$z.e,
+                         start = -1,
+                         end = +1)
+
+    test.eventtime0 <- remap.cumsum(es.test.w0, is.pc = FALSE,
+                                    base = 0)
+
+    test.boot0 <- inference.bootstrap(es.w = test.eventtime0,
+                                     to.plot = FALSE)
+
+    test.boot1 <- inference.wilcox(es.w = test.eventtime0,
+                                     to.plot = FALSE)
+
+### Testing function for univariate series: one firm
+    
+    cat("\nTesting for univariate series in zoo object")
+    esConvertNormal1 <- phys2eventtime(z = test.data,
+                                       events = test.eventslist,
+                                       width = 4)
+    es.test.w1 <- window(esConvertNormal1$z.e,
+                         start = -4,
+                         end = +4)
+
+    test.eventtime1 <- remap.cumsum(es.test.w1, is.pc = FALSE,
+                                    base = 0)
+
+    test.boot2 <- inference.bootstrap(es.w = test.eventtime1,
+                                      to.plot = FALSE)
+
+    test.boot3 <- inference.wilcox(es.w = test.eventtime1,
+                                   to.plot = FALSE)
+
+  })

Added: pkg/inst/tests/test_userinput_remap.R
===================================================================
--- pkg/inst/tests/test_userinput_remap.R	                        (rev 0)
+++ pkg/inst/tests/test_userinput_remap.R	2015-04-08 15:07:37 UTC (rev 416)
@@ -0,0 +1,78 @@
+library(testthat)
+context("userinput")
+
+## 1. Testing remap.cumsum for univariate series i.e. only one firm
+## 2. Testing remap.cumprod for univariate series i.e. only one firm
+## 3. Testing remap.cumsum for percentage and absolute returns
+## 4. Testing remap.cumprod for percentage and absolute returns
+
+test_that("userinput for remap.functions", {
+  library(eventstudies)
+  ## Data of Stock Prices
+  test.data <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17,
+                           35.89, 36.19, 37.1317, 36.7033, 37.7933,
+                           37.8533, 285.325, 292.6, 290.025, 286.2,
+                           290.075, 295.05, 289.325, 285.625, 293.7,
+                           298.5, 289.05, 704.5438, 708.35, 735.8375,
+                           710.625, 711.65, 731.025, 727.575, 715.187,
+                           724.2, 713.1875, 695.1812),
+                         .Dim = c(11L, 3L),
+                         .Dimnames = list( NULL, c("ITC", "Reliance",
+                           "TCS")), index = structure(c(12418,
+                                      12419, 12422, 12423, 12424,
+                                      12425, 12426, 12429, 12430,
+                                      12431, 12432),
+                                      class = "Date"),
+                         class = "zoo")
+  test.data <- diff(log(test.data))
+  ## List of events
+  test.eventslist <- data.frame(name=c("ITC","Reliance","TCS",
+                                  "ITC","Reliance","Junk"),
+                                when=as.Date(c("2004-01-02",
+                                  "2004-01-08", "2004-01-14",
+                                  "2005-01-15", "2004-01-01",
+                                  "2005-01-01")))
+  test.eventslist$name <- as.character(test.eventslist$name)
+
+  ## Converting in the window format, as returned by phys2eventtime
+
+  esConvertNormal0 <- phys2eventtime(z = test.data,
+                                     events = test.eventslist,
+                                     width = 2)
+  esConvertNormal1 <- phys2eventtime(z = test.data,
+                                     events = test.eventslist,
+                                     width = 1)
+  es.test.w0 <- window(esConvertNormal0$z.e, start = -4, end = +4)
+  es.test.w1 <- window(esConvertNormal1$z.e, start = -1, end = +1)
+
+  ### Testing remap.cumsum for univariate series i.e. only one firm
+
+  cat("\nTesting for univariate series in remap.cumsum")
+  es.test.remap0 <- remap.cumsum(es.test.w0, is.pc = FALSE, base = 0)
+  es.test.remap1 <- remap.cumsum(es.test.w1, is.pc = FALSE, base = 0)
+
+  ### Testing remap.cumprod for univariate series i.e. only one firm
+
+  cat("\nTesting for univariate series in remap.cumsum")
+  es.test.remap2 <- remap.cumprod(es.test.w0, is.pc = FALSE,
+                                  base = 100)
+  es.test.remap3 <- remap.cumprod(es.test.w1, is.pc = FALSE,
+                                  base = 100)
+
+  ### Testing remap.cumsum for percentage and absolute returns
+  
+  cat("\nTesting for percentage and absolute returns in remap.cumsum")
+  
+  es.test.remap4 <- remap.cumsum(es.test.w0, is.pc = TRUE, base = 0)
+  
+  es.test.remap5 <- remap.cumsum(es.test.w0, is.pc = FALSE, base = 0)
+
+  ### Testing remap.cumprod for percentage and absolute returns
+  
+  cat("\nTesting for percentage and absolute returns in remap.cumprod")
+  
+  es.test.remap4 <- remap.cumsum(es.test.w0, is.pc = TRUE, base = 100)
+  
+  es.test.remap5 <- remap.cumsum(es.test.w0, is.pc = FALSE,
+                                 base = 100)
+})



More information about the Eventstudies-commits mailing list