[Blotter-commits] r1348 - pkg/FinancialInstrument/inst/parser

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 9 16:33:07 CET 2013


Author: gsee
Date: 2013-01-09 16:33:07 +0100 (Wed, 09 Jan 2013)
New Revision: 1348

Modified:
   pkg/FinancialInstrument/inst/parser/download.TrueFX.R
Log:
 download.TrueFX.R script uses fastPOSIXct if the fasttime package is installed.  Thanks to Hideyoshi Maeda for the suggestion!


Modified: pkg/FinancialInstrument/inst/parser/download.TrueFX.R
===================================================================
--- pkg/FinancialInstrument/inst/parser/download.TrueFX.R	2013-01-06 22:07:51 UTC (rev 1347)
+++ pkg/FinancialInstrument/inst/parser/download.TrueFX.R	2013-01-09 15:33:07 UTC (rev 1348)
@@ -36,6 +36,15 @@
 require(foreach)
 require(doMC)
 
+use.fasttime <- if (require(fasttime)) {
+  TRUE
+} else {
+  message("This would be faster if the fasttime package were installed")
+  message("see http://www.rforge.net/fasttime/")
+  FALSE
+}
+#use.data.table <- require(data.table) # for fread()... not sure this will work with doMC
+
 ################################################################################
 # Begin User Parameters #
 #########################
@@ -81,6 +90,19 @@
 dir.create(sec_dir <- paste0(base_dir, "sec/"), mode="0755", 
            showWarnings=FALSE)
 
+# If fasttime is loaded, use fastPOSIXct, else use as.POSIXct
+PosixFun <- if (use.fasttime) {
+  function(x) {
+    xx <- paste(paste(substring(x, 1, 4), substring(x, 5, 6), 
+                      substring(x, 7, 8), sep="-"), substring(x, 10))
+    fastPOSIXct(xx, "GMT")
+  }
+} else {
+  function(x) {
+    as.POSIXct(x, format="%Y%m%d %H:%M:%OS", tz="GMT")
+  }
+}
+
 # set some options
 if (is.null(getOption("digits.secs"))) options(digits.secs=6)
 oldTZ <- Sys.getenv("TZ")
@@ -110,7 +132,7 @@
   unlink(uzf)
   id <- sub("/", "", fr[1, 1])
   cat("making index for ", id, "\n")
-  idx <- as.POSIXct(fr[, 2], format="%Y%m%d %H:%M:%OS", tz="GMT")
+  idx <- PosixFun(fr[, 2])
   obj <- xts(fr[, 3:4], idx, tzone="GMT")
   #colnames(obj) <- paste(id, c("Bid.Price", "Ask.Price"), sep=".")
   colnames(obj) <- c("Bid.Price", "Ask.Price")



More information about the Blotter-commits mailing list