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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 28 06:38:16 CEST 2012


Author: bodanker
Date: 2012-06-28 06:38:16 +0200 (Thu, 28 Jun 2012)
New Revision: 1078

Modified:
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/osFUNs.R
   pkg/quantstrat/R/rules.R
Log:
- fixed midnight timestamp / timespan format bug in other functions. Some
  locations still use paste/as.character, but they should be okay. Biggest
  problem is when "::" is on LHS.


Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2012-06-27 21:52:30 UTC (rev 1077)
+++ pkg/quantstrat/R/orders.R	2012-06-28 04:38:16 UTC (rev 1078)
@@ -284,10 +284,11 @@
 
     # subset by time and symbol
     if(!is.null(timestamp)& length(timestamp)>=1){
-        timespan<-paste("::",timestamp,sep='')
+        timespan <- format(timestamp, "::%Y-%m-%d %H:%M:%OS6")
     } else {
         # construct the timespan of the entire series
-        timespan=paste(index(first(orderbook),index(last(orderbook)),sep='::'))
+        timespan <- paste(format(index(first(orderbook)), "%Y-%m-%d %H:%M:%OS6"),
+                          format(index( last(orderbook)), "%Y-%m-%d %H:%M:%OS6"), sep="::")
     }
 
     statustimestamp=NA # new orders don't have a status time

Modified: pkg/quantstrat/R/osFUNs.R
===================================================================
--- pkg/quantstrat/R/osFUNs.R	2012-06-27 21:52:30 UTC (rev 1077)
+++ pkg/quantstrat/R/osFUNs.R	2012-06-28 04:38:16 UTC (rev 1078)
@@ -73,7 +73,7 @@
 getPosLimit <- function(portfolio, symbol, timestamp){
     portf<-getPortfolio(portfolio)
     # try to get on timestamp, otherwise find the most recent
-    toDate = paste('::', timestamp, sep="")
+    toDate = format(timestamp, '::%Y-%m-%d %H:%M:%OS6')
     PosLimit = last(portf$symbols[[symbol]]$PosLimit[toDate])
     return(PosLimit)
 }

Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2012-06-27 21:52:30 UTC (rev 1077)
+++ pkg/quantstrat/R/rules.R	2012-06-28 04:38:16 UTC (rev 1078)
@@ -545,7 +545,7 @@
                         }
                         tmpqty<-as.numeric(tmpqty)
                         tmpprice<-as.numeric(ordersubset[onum,'Order.Price'])
-                        tmpidx<-as.character(index(ordersubset[onum,])) #this is the time the order was entered
+                        tmpidx <- format(index(ordersubset[onum,]), "%Y-%m-%d %H:%M:%OS6") #this is the time the order was entered
                         #print(tmpidx)
                         if(isBBOmktdata) {
                             if(tmpqty > 0){ # positive quantity 'buy'
@@ -560,9 +560,9 @@
                         if(is.null(firsttime)) firsttime<-timestamp
                         nextidx<-min(dindex[dindex>curIndex])
                         if(length(nextidx)){
-                            nextstamp<-(as.character(index(mktdata[nextidx,])))
+                            nextstamp <- format(index(mktdata[nextidx,]), "%Y-%m-%d %H:%M:%OS6")
                             #print(nextstamp)
-                            timespan<-paste(firsttime,"::",nextstamp,sep='')
+                            timespan <- paste(format(firsttime, "%Y-%m-%d %H:%M:%OS6"),"::",nextstamp,sep='')
                             #get the subset of prices
                             mkt_price_series <-getPrice(mktdata[timespan],prefer=prefer)
                             col<-first(colnames(mkt_price_series))
@@ -584,8 +584,9 @@
                             #print(firsttime)
                             # find first index where we would move an order
                             orderidx<-first(which(move_order)) 
-                            if(is.null(tmpidx)) tmpidx<-as.character(index(move_order[orderidx,]))
-                            trailspan<-paste(firsttime,"::",tmpidx,sep='')
+                            if(is.null(tmpidx))
+                                tmpidx <- format(index(move_order[orderidx,]), "%Y-%m-%d %H:%M:%OS6")
+                            trailspan <- paste(format(firsttime, "%Y-%m-%d %H:%M:%OS6"),"::",tmpidx,sep='')
                             #make sure we don't cross before then 
                             # use sigThreshold
                             cross<-sigThreshold(data=mkt_price_series, label='tmptrail',column=col,threshold=tmpprice,relationship=relationship)
@@ -667,7 +668,7 @@
                         } else {
                             #(mktdata, portfolio, symbol, timestamp, slippageFUN=NULL)
                             if (isTRUE(path.dep)){
-				timespan <- format(index(mktdata)[curIndex], "::%Y-%m-%d %H:%M:%S %OS6")
+				timespan <- format(timestamp, "::%Y-%m-%d %H:%M:%OS6")
                             } else timespan=NULL
                             ruleOrderProc(portfolio=portfolio, symbol=symbol, mktdata=mktdata, timespan=timespan, ...)
                         }



More information about the Blotter-commits mailing list