[Blotter-commits] r1067 - in pkg/quantstrat: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 23 19:36:28 CEST 2012


Author: braverock
Date: 2012-06-23 19:36:28 +0200 (Sat, 23 Jun 2012)
New Revision: 1067

Modified:
   pkg/quantstrat/R/ruleOrderProc.R
   pkg/quantstrat/R/ruleSignal.R
   pkg/quantstrat/man/ruleOrderProc.Rd
Log:
- don't execute an exit all order on the wrong orderside of the current position
- update roxygen documentation

Modified: pkg/quantstrat/R/ruleOrderProc.R
===================================================================
--- pkg/quantstrat/R/ruleOrderProc.R	2012-06-23 16:46:05 UTC (rev 1066)
+++ pkg/quantstrat/R/ruleOrderProc.R	2012-06-23 17:36:28 UTC (rev 1067)
@@ -5,12 +5,11 @@
 #' but would need to be replaced for production use.  It provides the interface 
 #' for taking the order book and determining when orders become trades.
 #'  
-#' For the purposes of backtesting, and compatibility with the trade accounting in
-#' \code{blotter}, this function will not allow a transaction to cross your current 
+#' In this version, in contrast with an earlier version, 
+#' this function will allow a transaction to cross your current 
 #' position through zero.  The accounting rules for realizing gains in such cases 
-#' are more complicated than we wish to support.  Also, many brokers will break, revise,
-#' or split such transactions for the same reason. If you wish to do a "stop and reverse" 
-#' system, first stop (flatten), and then reverse (initiate a new position).
+#' are quite complicated, so blotter will split this transaction into two transactions.  
+#' Many brokers will break, revise, or split such transactions for the same reason.
 #' 
 #' This function would need to be revised or replaced for connection to a live trading infrastructure.
 #' In a production mode, you would replace the \code{\link{addOrder}} function 
@@ -88,8 +87,14 @@
             orderPrice <- as.numeric(ordersubset[ii,"Order.Price"])
             orderQty <- ordersubset[ii,"Order.Qty"]
             if(orderQty=='all'){
-                # this has to be an exit or risk order, so 
+                # this has to be an exit or risk order, so: 
                 orderQty=-1*getPosQty(Portfolio=portfolio,Symbol=symbol,Date=timestamp)
+                orderside<-ordersubset[ii, "Order.Side"]
+                if(((orderQty>0 && orderside=='long') || (orderQty<0 && orderside=='short')))
+                {
+                    #warning('trying to exit/all position but orderQty sign is wrong')
+                    orderQty = 0		
+                }
             }
             orderQty<-as.numeric(orderQty)
             if(orderQty==0) next() #nothing to do, move along

Modified: pkg/quantstrat/R/ruleSignal.R
===================================================================
--- pkg/quantstrat/R/ruleSignal.R	2012-06-23 16:46:05 UTC (rev 1066)
+++ pkg/quantstrat/R/ruleSignal.R	2012-06-23 17:36:28 UTC (rev 1067)
@@ -153,21 +153,8 @@
 	{
 		orderqty <- osFUN(strategy=strategy, data=data, timestamp=timestamp, orderqty=orderqty, ordertype=ordertype, orderside=orderside, portfolio=portfolio, symbol=symbol,...=...,ruletype=ruletype, orderprice=as.numeric(orderprice))
     }
-#		if(ruletype=='risk' || ruletype=='exit')
-#		{
-#			if(orderqty==0)	# cancel any open orders from orderset associated with this exit/risk order
-#				updateOrders(portfolio, symbol, oldstatus="open", newstatus='canceled', statustimestamp=timestamp, orderset=orderset)
-#
-#			if(((orderqty>0 && orderside=='long') || (orderqty<0 && orderside=='short')))
-#			{
-#				warning('trying to exit/all position but orderqty sign is wrong')
-#				orderqty = NULL		# dirty trick to suppress adding order below JH; (why?)
-#			}
-#		}
-#
-#        }
 
-	if(!is.null(orderqty) && orderqty!=0 && !is.null(orderprice)) #orderqty could have length > 1
+	if(!is.null(orderqty) && orderqty!=0 && !is.null(orderprice)) #orderprice 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, ...=..., prefer=prefer, TxnFees=TxnFees,label=label)
         }

Modified: pkg/quantstrat/man/ruleOrderProc.Rd
===================================================================
--- pkg/quantstrat/man/ruleOrderProc.Rd	2012-06-23 16:46:05 UTC (rev 1066)
+++ pkg/quantstrat/man/ruleOrderProc.Rd	2012-06-23 17:36:28 UTC (rev 1067)
@@ -38,15 +38,13 @@
   orders become trades.
 }
 \details{
-  For the purposes of backtesting, and compatibility with
-  the trade accounting in \code{blotter}, this function
-  will not allow a transaction to cross your current
-  position through zero.  The accounting rules for
-  realizing gains in such cases are more complicated than
-  we wish to support.  Also, many brokers will break,
-  revise, or split such transactions for the same reason.
-  If you wish to do a "stop and reverse" system, first stop
-  (flatten), and then reverse (initiate a new position).
+  In this version, in contrast with an earlier version,
+  this function will allow a transaction to cross your
+  current position through zero.  The accounting rules for
+  realizing gains in such cases are quite complicated, so
+  blotter will split this transaction into two
+  transactions. Many brokers will break, revise, or split
+  such transactions for the same reason.
 
   This function would need to be revised or replaced for
   connection to a live trading infrastructure. In a



More information about the Blotter-commits mailing list