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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 16 13:36:14 CET 2014


Author: opentrades
Date: 2014-01-16 13:36:14 +0100 (Thu, 16 Jan 2014)
New Revision: 1583

Modified:
   pkg/quantstrat/R/ruleOrderProc.R
Log:
- fixed broken tif code:
-- time format now accepts both %H:%M:%S and %H:%M:%0S
-- expiration now based on comparison with timestamp i.o. index(ordersubset)



Modified: pkg/quantstrat/R/ruleOrderProc.R
===================================================================
--- pkg/quantstrat/R/ruleOrderProc.R	2014-01-15 15:20:22 UTC (rev 1582)
+++ pkg/quantstrat/R/ruleOrderProc.R	2014-01-16 12:36:14 UTC (rev 1583)
@@ -65,13 +65,21 @@
   OpenOrders.i<-getOrders(portfolio=portfolio, symbol=symbol, status="open", timespan=timespan, ordertype=ordertype, which.i=TRUE)
 
   #extract time in force for open orders
-  tif <- ordersubset[OpenOrders.i, 'Time.In.Force']
-  if(any(!tif=='')){
-    if (class(index(ordersubset))=='Date') tif <- as.Date(tif)
-    else tif <- strptime(tif, format='%Y-%m-%d %H:%M:%0S')
+  tif.xts <- ordersubset[OpenOrders.i, 'Time.In.Force']
+  if(any(!tif.xts==''))
+  {
+    if (class(index(ordersubset))=='Date')
+        tif <- as.Date(tif.xts)
+    else
+    {
+        tif <- strptime(tif.xts, format='%Y-%m-%d %H:%M:%0S')
+        if(is.na(tif))
+		tif <- strptime(tif.xts, format='%Y-%m-%d %H:%M:%S')
+    }
+
     #check which ones should be expired
-    ExpiredOrders.i<-which(tif<index(ordersubset[OpenOrders.i]))
-    #mark them expired
+    ExpiredOrders.i<-which(tif<timestamp)
+
     ordersubset[OpenOrders.i[ExpiredOrders.i], "Order.Status"] = 'expired'  
     ordersubset[OpenOrders.i[ExpiredOrders.i], "Order.StatusTime"]<-ordersubset[OpenOrders.i[ExpiredOrders.i], "Time.In.Force"]
   }



More information about the Blotter-commits mailing list