[Blotter-commits] r1712 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 2 18:48:46 CET 2015


Author: bodanker
Date: 2015-11-02 18:48:45 +0100 (Mon, 02 Nov 2015)
New Revision: 1712

Modified:
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/ruleOrderProc.R
Log:
Fix TIF handling when mktdata index is Date

Calling as.Date on an xts object does not work, because as.Date.default
is dispatched and doesn't know how to handle xts objects. Use coredata
to extract the TIF string from the xts object before calling as.Date.

Address Brian's TODO FIXME to convert timestamp to POSIXct before
adding the numeric time.in.force (documented to be in seconds).


Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2015-11-02 01:37:38 UTC (rev 1711)
+++ pkg/quantstrat/R/orders.R	2015-11-02 17:48:45 UTC (rev 1712)
@@ -386,11 +386,10 @@
         else
         {
             if(is.numeric(time.in.force))
-                time.in.force <- timestamp + time.in.force
+                time.in.force <- as.POSIXct(timestamp) + time.in.force
 
             time.in.force <- format(time.in.force, "%Y-%m-%d %H:%M:%OS")
-            #TODO FIXME this line probably needs to be sensitive to the index of the market data, Date vs POSIXct
-  }
+        }
     }
 
     #set up the other parameters

Modified: pkg/quantstrat/R/ruleOrderProc.R
===================================================================
--- pkg/quantstrat/R/ruleOrderProc.R	2015-11-02 01:37:38 UTC (rev 1711)
+++ pkg/quantstrat/R/ruleOrderProc.R	2015-11-02 17:48:45 UTC (rev 1712)
@@ -69,13 +69,13 @@
   if(any(!tif.xts==''))
   {
     if (any(indexClass(ordersubset)=='Date'))
-        tif <- as.Date(tif.xts)
+        tif <- as.Date(coredata(tif.xts))
     else
     {
-        tif <- strptime(tif.xts, format='%Y-%m-%d %H:%M:%OS')
+        tif <- strptime(coredata(tif.xts), format='%Y-%m-%d %H:%M:%OS')
         tif.na <- is.na(tif)
         if(any(tif.na))
-            tif[tif.na] <- strptime(tif.xts[tif.na], format='%Y-%m-%d %H:%M:%S')
+            tif[tif.na] <- strptime(coredata(tif.xts[tif.na]), format='%Y-%m-%d %H:%M:%S')
     }
 
     #check which ones should be expired



More information about the Blotter-commits mailing list