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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 14 19:28:03 CEST 2012


Author: opentrades
Date: 2012-06-14 19:28:03 +0200 (Thu, 14 Jun 2012)
New Revision: 1046

Modified:
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/ruleSignal.R
   pkg/quantstrat/R/rules.R
Log:
fixed bug in handling prefer for market orders



Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2012-06-10 22:13:32 UTC (rev 1045)
+++ pkg/quantstrat/R/orders.R	2012-06-14 17:28:03 UTC (rev 1046)
@@ -40,8 +40,8 @@
         orders<-list()
         orders[[portfolio]]<-list()
     }
-    ordertemplate<-xts(as.matrix(t(c(0,NA,"init","long",0,"closed",as.character(as.POSIXct(initDate)),1,0,''))),order.by=as.POSIXct(initDate), ...=...)
-    colnames(ordertemplate) <- c("Order.Qty","Order.Price","Order.Type","Order.Side","Order.Threshold","Order.Status","Order.StatusTime","Order.Set","Txn.Fees","Rule")
+    ordertemplate<-xts(as.matrix(t(c(0,NA,"init","long",0,"closed",as.character(as.POSIXct(initDate)),'','',0,''))),order.by=as.POSIXct(initDate), ...=...)
+    colnames(ordertemplate) <- c("Order.Qty","Order.Price","Order.Type","Order.Side","Order.Threshold","Order.Status","Order.StatusTime","Prefer", "Order.Set","Txn.Fees","Rule")
 
     if(is.null(symbols)) {
         pfolio<-getPortfolio(portfolio)
@@ -209,7 +209,7 @@
 #' @seealso updateOrders
 #' @concept order book
 #' @export
-addOrder <- function(portfolio, symbol, timestamp, qty, price, ordertype, side, orderset='', threshold=NULL, status="open", statustimestamp='' , delay=.00001, tmult=FALSE, replace=TRUE, return=FALSE, ..., TxnFees=0,label='')
+addOrder <- function(portfolio, symbol, timestamp, qty, price, ordertype, side, orderset='', threshold=NULL, status="open", statustimestamp='' , prefer='', delay=.00001, tmult=FALSE, replace=TRUE, return=FALSE, ..., TxnFees=0,label='')
 {
     # get order book
     #orderbook <- getOrderBook(portfolio)
@@ -287,6 +287,7 @@
                                     threshold[i], 
                                     status, 
                                     statustimestamp, 
+				    prefer,
                                     orderset[i], 
                                     TxnFees, label))), 
                                 order.by=(ordertime))
@@ -294,7 +295,7 @@
         else orders <- rbind(orders,neworder)
     }
 
-    if(ncol(orders)!=10) {
+    if(ncol(orders)!=11) {
         print("bad order(s):")
         print(orders)
         return()

Modified: pkg/quantstrat/R/ruleSignal.R
===================================================================
--- pkg/quantstrat/R/ruleSignal.R	2012-06-10 22:13:32 UTC (rev 1045)
+++ pkg/quantstrat/R/ruleSignal.R	2012-06-14 17:28:03 UTC (rev 1046)
@@ -46,7 +46,6 @@
 #' @export
 ruleSignal <- function(data=mktdata, timestamp, sigcol, sigval, orderqty=0, ordertype, orderside=NULL, orderset=NULL, threshold=NULL, tmult=FALSE, replace=TRUE, delay=0.0001, osFUN='osNoOp', pricemethod=c('market','opside','active'), portfolio, symbol, ..., ruletype, TxnFees=0, prefer=NULL, sethold=FALSE, label='')
 {
-
     if(!is.function(osFUN)) osFUN<-match.fun(osFUN)
     #print(paste(symbol,timestamp, sigval))
     #print(data[timestamp][,sigcol])
@@ -162,7 +161,7 @@
 
 	if(!is.null(orderqty) && orderqty!=0 && !is.null(orderprice)) #orderqty could have length > 1
 	{
-		addOrder(portfolio=portfolio, symbol=symbol, timestamp=timestamp, qty=orderqty, price=as.numeric(orderprice), ordertype=ordertype, side=orderside, orderset=orderset, threshold=threshold, status="open", replace=replace , delay=delay, tmult=tmult, ...=..., TxnFees=TxnFees,label=label)
+		addOrder(portfolio=portfolio, symbol=symbol, timestamp=timestamp, qty=orderqty, price=as.numeric(orderprice), ordertype=ordertype, side=orderside, orderset=orderset, threshold=threshold, status="open", replace=replace , delay=delay, tmult=tmult, ...=..., prefer=prefer, TxnFees=TxnFees,label=label)
         }
     }
     if(sethold) hold <<- TRUE

Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2012-06-10 22:13:32 UTC (rev 1045)
+++ pkg/quantstrat/R/rules.R	2012-06-14 17:28:03 UTC (rev 1046)
@@ -285,11 +285,9 @@
 
             .formals  <- formals(fun)
             
-            if(hasArg(prefer)) .formals$prefer=match.call(expand.dots=TRUE)$prefer
-            
             onames <- names(.formals)
             rule$arguments$timestamp = timestamp
-			rule$arguments$ruletype  = ruletype
+            rule$arguments$ruletype  = ruletype
             rule$arguments$label = rule$label
             pm <- pmatch(names(rule$arguments), onames, nomatch = 0L)
             # if (any(pm == 0L)) message(paste("some arguments stored for",rule$name,"do not match"))
@@ -310,6 +308,9 @@
                 .formals[pm] <- nargs[pm > 0L]
             }
             .formals$... <- NULL
+
+	    # any rule-specific prefer-parameters should override global prefer parameter
+	    if(!is.null(rule$arguments$prefer)) .formals$prefer = rule$arguments$prefer
             
             tmp_val<-do.call(fun,.formals)
 



More information about the Blotter-commits mailing list