[Highfrequency-commits] r108 - in pkg/highfrequency: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 11 11:46:58 CEST 2014


Author: kboudt
Date: 2014-09-11 11:46:57 +0200 (Thu, 11 Sep 2014)
New Revision: 108

Modified:
   pkg/highfrequency/DESCRIPTION
   pkg/highfrequency/R/realized.R
   pkg/highfrequency/man/highfrequency-package.Rd
   pkg/highfrequency/man/selectexchange.Rd
   pkg/highfrequency/man/tradescleanup.Rd
Log:


Modified: pkg/highfrequency/DESCRIPTION
===================================================================
--- pkg/highfrequency/DESCRIPTION	2014-09-05 11:17:06 UTC (rev 107)
+++ pkg/highfrequency/DESCRIPTION	2014-09-11 09:46:57 UTC (rev 108)
@@ -2,14 +2,14 @@
 Version: 0.4
 Date: 2014-08-31
 Title: highfrequency
-Author: Jonathan Cornelissen, Kris Boudt, Scott Payseur 
-Maintainer: Jonathan Cornelissen
-        <Jonathan.cornelissen at econ.kuleuven.be>
+Author:  Jonathan Cornelissen, Kris Boudt,  Scott Payseur 
+Maintainer: Kris Boudt
+        <Kris.Boudt at econ.kuleuven.be>
 Description: The highfrequency package contains an extensive toolkit for the use of highfrequency financial data in R. It contains functionality to manage, clean and match highfrequency trades and quotes data. Furthermore, it enables users to: calculate easily various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity. 
 License: GPL (>= 2)
 Depends: R (>= 2.12.0), xts, zoo
 Suggests: robustbase, cubature, mvtnorm, chron, timeDate,
         quantmod, MASS, sandwich, numDeriv, FKF, BMS, rugarch
 Contributors: Giang Nguyen, Maarten Schermer
-Thanks: A special thanks for additional contributions from Chris Blakely
+Thanks: A special thanks for additional contributions from Chris Blakely, Brian Peterson, Eric Zivot and GSoC
 LazyLoad: yes

Modified: pkg/highfrequency/R/realized.R
===================================================================
--- pkg/highfrequency/R/realized.R	2014-09-05 11:17:06 UTC (rev 107)
+++ pkg/highfrequency/R/realized.R	2014-09-11 09:46:57 UTC (rev 108)
@@ -3096,72 +3096,121 @@
  matchtq = function(...){matchTradesQuotes(...)};                          
 
 ##################### Total cleanup functions formerly in RTAQ ################################
+
+
 tradesCleanup = function(from,to,datasource,datadestination,ticker,exchanges,tdataraw=NULL,report=TRUE,selection="median",...){
   
-  nresult = rep(0,5);
-  if(is.null(tdataraw)){
-    dates = timeSequence(from,to, format = "%Y-%m-%d", FinCenter = "GMT");
-    dates = dates[isBizday(dates, holidays = holidayNYSE(2004:2010))];
-    
-    for(j in 1:length(dates)){
-      datasourcex = paste(datasource,"/",dates[j],sep="");
-      datadestinationx = paste(datadestination,"/",dates[j],sep="");
-      
-      for(i in 1:length(ticker)){
-        dataname = paste(ticker[i],"_trades.RData",sep="");
-        load(paste(datasourcex,"/",dataname,sep=""));
-        
-        if(class(tdata)[1]!="try-error"){
-          exchange = exchanges[i];  
+  nresult = rep(0, 5)
+  if(!is.list(exchanges)){ exchanges = as.list(exchanges)}
+  if (is.null(tdataraw)) {
+    dates = timeSequence(from, to, format = "%Y-%m-d")
+    dates = dates[isBizday(dates, holidays=holidayNYSE(1960:2040))]
+    for (j in 1:length(dates)) {
+      datasourcex = paste(datasource, "/", dates[j], sep = "")
+      datadestinationx = paste(datadestination, "/", dates[j], sep = "")
+      for (i in 1:length(ticker)) {
+        dataname = paste(ticker[i], "_trades.RData", sep = "");
+        if(file.exists(paste(datasourcex, "/", dataname, sep = ""))){
+          load(paste(datasourcex, "/", dataname, sep = ""))
+          if (class(tdata)[1] != "try-error") {            
+            exchange = exchanges[[i]]            
+            if(length(tdata$PRICE)>0){
+              tdata = .check_data(tdata);
+              nresult[1] = nresult[1] + dim(tdata)[1]
+            }else{tdata=NULL;}
+            
+            if(length(tdata$PRICE)>0){
+              tdata = try(nozeroprices(tdata))
+              nresult[2] = nresult[2] + dim(tdata)[1];
+            }else{tdata=NULL;}
+            
+            
+            if(length(tdata$PRICE)>0){
+              tdata = try(selectexchange(tdata, exch = exchange))
+              nresult[3] = nresult[3] + dim(tdata)[1]
+            }else{tdata=NULL;}
+            
+            
+            if(length(tdata$PRICE)>0){
+              tdata = try(salescond(tdata))
+              nresult[4] = nresult[4] + dim(tdata)[1]
+            }else{tdata=NULL;}
+            
+            
+            if(length(tdata$PRICE)>0){
+              tdata = try(mergeTradesSameTimestamp(tdata, selection = selection))
+              nresult[5] = nresult[5] + dim(tdata)[1];
+            }else{tdata=NULL;}
+            
+            
+            
+            save(tdata, file = paste(datadestinationx,"/", dataname, sep = ""))
+          }
+          if (class(tdata) == "try-error") {
+            abc = 1
+            save(abc, file = paste(datadestinationx, "/missing_", 
+                                   ticker[i], ".RData", sep = ""))
+          }
           
-          tdata = .check_data(tdata);  nresult[1]= nresult[1]+dim(tdata)[1];
-          
-          ##actual clean-up: 
-          ##general:
-          tdata = try(nozeroprices(tdata));  nresult[2]= nresult[2]+dim(tdata)[1];
-          tdata = try(selectexchange(tdata,exch=exchange));  nresult[3]= nresult[3]+dim(tdata)[1];
-          
-          ##trade specific:
-          tdata = try(salescond(tdata));   nresult[4] = nresult[4] + dim(tdata)[1];
-          tdata = try(mergeTradesSameTimestamp(tdata,selection=selection));   nresult[5] = nresult[5] + dim(tdata)[1];
-          
-          save(tdata, file = paste(datadestinationx,"/",dataname,sep=""));
+        }else{
+          next;
         }
-        
-        if(class(tdata)=="try-error")  {
-          abc=1;
-          save(abc, file = paste(datadestinationx,"/missing_",ticker[i],".RData",sep=""));
-        }
-      }
+      }   
     }
-    if(report==TRUE){
-      names(nresult) = c("initial number","no zero prices","select exchange",
-                         "sales condition","merge same timestamp");
+    if (report == TRUE) {
+      names(nresult) = c("initial number", "no zero prices", 
+                         "select exchange", "sales condition", "merge same timestamp")
       return(nresult)
     }
   }
-  
-  if(!is.null(tdataraw)){
-    if(class(tdataraw)[1]!="try-error"){
-      if(length(exchanges)>1){print("The argument exchanges contains more than 1 element. Please select a single exchange, in case you provide tdataraw.")}
-      tdata=tdataraw; rm(tdataraw);  
-      tdata = .check_data(tdata);  nresult[1]= nresult[1]+dim(tdata)[1];
+  if (!is.null(tdataraw)) {
+    if (class(tdataraw)[1] != "try-error") {
+      if (length(exchanges) > 1) {
+        print("The argument exchanges contains more than 1 element. Please select a single exchange, in case you provide tdataraw.")
+      }
+      exchange = exchanges[[1]];
       
-      ##actual clean-up: 
-      ##general:
-      tdata = try(nozeroprices(tdata));  nresult[2]= nresult[2]+dim(tdata)[1];
-      tdata = try(selectexchange(tdata,exch=exchanges));  nresult[3]= nresult[3]+dim(tdata)[1];
+      tdata = tdataraw
+      rm(tdataraw)
       
-      ##trade specific:
-      tdata = try(salescond(tdata));   nresult[4] = nresult[4] + dim(tdata)[1];
-      tdata = try(mergeTradesSameTimestamp(tdata,selection=selection));   nresult[5] = nresult[5] + dim(tdata)[1];
       
-      if(report==TRUE){
-        names(nresult) = c("initial number","no zero prices","select exchange",
-                           "sales condition","merge same timestamp");
-        return(list(tdata=tdata,report=nresult))
+      if(length(tdata)>0){
+        tdata = .check_data(tdata);
+        nresult[1] = nresult[1] + dim(tdata)[1]
+      }else{tdata=NULL;}
+      
+      if(length(tdata)>0){
+        tdata = try(nozeroprices(tdata))
+        nresult[2] = nresult[2] + dim(tdata)[1];
+      }else{tdata=NULL;}
+      
+      
+      if(length(tdata)>0){
+        tdata = try(selectexchange(tdata, exch = exchange))
+        nresult[3] = nresult[3] + dim(tdata)[1]
+      }else{tdata=NULL;}
+      
+      
+      if(length(tdata)>0){
+        tdata = try(salescond(tdata))
+        nresult[4] = nresult[4] + dim(tdata)[1]
+      }else{tdata=NULL;}
+      
+      
+      if(length(tdata)>0){
+        tdata = try(mergeTradesSameTimestamp(tdata, selection = selection))
+        nresult[5] = nresult[5] + dim(tdata)[1];
+      }else{tdata=NULL;}
+      
+      
+      if (report == TRUE) {
+        names(nresult) = c("initial number", "no zero prices", 
+                           "select exchange", "sales condition", "merge same timestamp")
+        return(list(tdata = tdata, report = nresult))
       }
-      if(report!=TRUE){return(tdata)}
+      if (report != TRUE) {
+        return(tdata)
+      }
     }
   }
   
@@ -3360,7 +3409,8 @@
 selectExchange = function(data,exch="N"){ 
   data = .check_data(data);
   ###FUNCTION TO SELECT THE OBSERVATIONS OF A SINGLE EXCHANGE: selectexchange
-  filteredts = data[data$EX==exch];
+  #filteredts = data[data$EX==exch];
+  filteredts = data[is.element(data$EX , exch)]
   return(filteredts);
 }
 

Modified: pkg/highfrequency/man/highfrequency-package.Rd
===================================================================
--- pkg/highfrequency/man/highfrequency-package.Rd	2014-09-05 11:17:06 UTC (rev 107)
+++ pkg/highfrequency/man/highfrequency-package.Rd	2014-09-11 09:46:57 UTC (rev 108)
@@ -18,13 +18,13 @@
 }
 
 \author{
-Jonathan Cornelissen, Kris Boudt, Scott Payseur
+Jonathan Cornelissen,  Kris Boudt, Scott Payseur
 
-Maintainer: Jonathan Cornelissen <Jonathan.cornelissen at econ.kuleuven.be>
+Maintainer: Kris Boudt <Kris.Boudt at econ.kuleuven.be>
 
 Contributors: Giang Nguyen, Maarten Schermers.
 
-Thanks: A special thanks for additional contributions from Chris Blakely.
+Thanks: A special thanks for additional contributions from Chris Blakely, Brian Peterson, Eric Zivot and GSoC.
 }
 
 \keyword{ package }

Modified: pkg/highfrequency/man/selectexchange.Rd
===================================================================
--- pkg/highfrequency/man/selectexchange.Rd	2014-09-05 11:17:06 UTC (rev 107)
+++ pkg/highfrequency/man/selectexchange.Rd	2014-09-11 09:46:57 UTC (rev 108)
@@ -15,7 +15,7 @@
 \arguments{
   \item{data}{ an xts object containing the time series data. 
 The object should have a column "EX", indicating the exchange by its symbol.}
-  \item{exch}{ The symbol of the stock exchange that should be selected. 
+  \item{exch}{ The (vector of) symbol(s) of the stock exchange(s) that should be selected. 
 By default the NYSE is chosen (exch="N"). Other exchange symbols are:
 \itemize{
 \item A: AMEX
@@ -41,4 +41,4 @@
 }
 
 \author{ Jonathan Cornelissen and Kris Boudt}
-\keyword{ cleaning }
\ No newline at end of file
+\keyword{ cleaning }

Modified: pkg/highfrequency/man/tradescleanup.Rd
===================================================================
--- pkg/highfrequency/man/tradescleanup.Rd	2014-09-05 11:17:06 UTC (rev 107)
+++ pkg/highfrequency/man/tradescleanup.Rd	2014-09-11 09:46:57 UTC (rev 108)
@@ -31,8 +31,8 @@
 \item{datasource}{character indicating the folder in which the original data is stored.}
 \item{datadestination}{character indicating the folder in which the cleaned data is stored.}
 \item{ticker}{vector of tickers for which the data should be cleaned, e.g. ticker = c("AAPL","AIG")}
-\item{exchanges}{vector of stock exchange symbols for all tickers in vector "ticker". It thus should have the same length as the vector ticker.
-Only data from one exchanges will be retained for each stock respectively, e.g. exchanges = c("Q","N")
+\item{exchanges}{list of vectors of stock exchange(s) for all tickers in vector "ticker". It thus should have the same length as the vector ticker.
+E.g. in case of two stocks; exchanges = list("N", c("Q","T")).
 The possible exchange symbols are:
 \itemize{
 \item A: AMEX
@@ -70,7 +70,7 @@
 data("sample_tdataraw");
 head(sample_tdataraw);
 dim(sample_tdataraw);
-tdata_afterfirstcleaning = tradesCleanup(tdataraw=sample_tdataraw,exchanges="N");
+tdata_afterfirstcleaning = tradesCleanup(tdataraw=sample_tdataraw,exchanges=list("N") );
 tdata_afterfirstcleaning$report; 
 barplot(tdata_afterfirstcleaning$report);
 dim(tdata_afterfirstcleaning$tdata);
@@ -91,4 +91,4 @@
 }
 
 \author{ Jonathan Cornelissen and Kris Boudt}
-\keyword{ cleaning }
\ No newline at end of file
+\keyword{ cleaning }



More information about the Highfrequency-commits mailing list