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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 25 15:58:04 CET 2010


Author: braverock
Date: 2010-02-25 15:58:04 +0100 (Thu, 25 Feb 2010)
New Revision: 262

Modified:
   pkg/quantstrat/R/orders.R
Log:
- improve ordertime to be less sensitive to frequency and time zone

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2010-02-25 14:44:35 UTC (rev 261)
+++ pkg/quantstrat/R/orders.R	2010-02-25 14:58:04 UTC (rev 262)
@@ -149,7 +149,6 @@
     if(is.null(threshold)) threshold=NA #NA is not ignored byc() like NULL is
     if(!length(grep(status,c("open", "closed", "canceled","replaced")))==1) stop(paste("order status:",status,' must be one of "open", "closed", "canceled", or "replaced"'))
     # TODO do we need to check for collision, and increment timestamp?  or alternately update?
-    statustimestamp=NA # new orders don't have a status time
     
     # subset by time and symbol
     if(!is.null(timestamp)& length(timestamp)>=1){
@@ -160,8 +159,11 @@
     }
     
     if(isTRUE(replace)) updateOrders(portfolio=portfolio, symbol=symbol,timespan=timespan, ordertype=ordertype, side=side, oldstatus="open", newstatus="replaced", statustimestamp=timestamp)
+    statustimestamp=NA # new orders don't have a status time
     # insert new order
-    order<-xts(as.matrix(t(c(qty, price, ordertype, side, threshold, status, statustimestamp))),order.by=(as.POSIXct(timestamp)+delay))
+    if(is.timeBased(timestamp)) ordertime<-timestamp+delay
+    else ordertime<-as.POSIXct(timestamp)+delay
+    order<-xts(as.matrix(t(c(qty, price, ordertype, side, threshold, status, statustimestamp))),order.by=(ordertime))
     colnames(order) <- c("Order.Qty","Order.Price","Order.Type","Order.Side","Order.Threshold","Order.Status","Order.StatusTime")
     orderbook[[symbol]]<-rbind(orderbook[[symbol]],order)
     



More information about the Blotter-commits mailing list