[Blotter-commits] r1261 - in pkg/quantstrat: . R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 22 03:43:22 CET 2012


Author: opentrades
Date: 2012-11-22 03:43:21 +0100 (Thu, 22 Nov 2012)
New Revision: 1261

Added:
   pkg/quantstrat/R/ruleRevoke.R
Removed:
   pkg/quantstrat/R/ruleCancel.R
Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/demo/luxor-3.11.R
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/getOrders.Rd
   pkg/quantstrat/man/ruleSignal.Rd
   pkg/quantstrat/man/updateOrders.Rd
Log:
introduced 'revoked' order status
changed ruleCancel() to ruleRevoke(); revokes all open orders when pos==0
useful eg. with timespan in add.rule() to close open enter orders at end of day



Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/DESCRIPTION	2012-11-22 02:43:21 UTC (rev 1261)
@@ -12,7 +12,26 @@
 Maintainer: Brian G. Peterson <brian at braverock.com>
 Description: Specify, build, and back-test quantitative
     financial trading and portfolio strategies
-Contributors: Yu Chen, Joe Dunn, Dirk Eddelbuettel, Jeffrey A. Ryan, Garrett See   
+Contributors: Yu Chen, Joe Dunn, Dirk Eddelbuettel, Jeffrey A. Ryan, Garrett See
 LazyLoad: yes
 License: GPL-3
 ByteCompile: FALSE
+Collate:
+    'applyStrategy.rebalancing.R'
+    'indicators.R'
+    'initialize.R'
+    'match.names.R'
+    'orders.R'
+    'osFUNs.R'
+    'parameters.R'
+    'paramsets.R'
+    'rebalance.rules.R'
+    'ruleOrderProc.R'
+    'ruleRevoke.R'
+    'rules.R'
+    'ruleSignal.R'
+    'signals.R'
+    'strategy.R'
+    'tradeGraphs.R'
+    'utils.R'
+    'wrapup.R'

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/NAMESPACE	2012-11-22 02:43:21 UTC (rev 1261)
@@ -27,9 +27,9 @@
 export(osMaxPos)
 export(osNoOp)
 export(rm.strat)
-export(ruleCancel)
+export(ruleOrderProc)
 export(rulePctEquity)
-export(ruleOrderProc)
+export(ruleRevoke)
 export(ruleSignal)
 export(save.strategy)
 export(setParameterConstraint)

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/R/orders.R	2012-11-22 02:43:21 UTC (rev 1261)
@@ -68,7 +68,7 @@
 #' 
 #' @param portfolio text name of the portfolio to associate the order book with
 #' @param symbol identfier of the instrument to find orders for.  The name of any associated price objects (xts prices, usually OHLC) should match these
-#' @param status one of "open", "closed", "canceled", or "replaced", default "open"
+#' @param status one of "open", "closed", "canceled", "revoked", or "replaced", default "open"
 #' @param timespan xts-style character timespan to be the period to find orders of the given status and ordertype
 #' @param ordertype one of NULL, "market","limit","stoplimit", "stoptrailing" or "iceberg" default NULL
 #' @param side one of NULL, "long" or "short", default NULL 
@@ -88,7 +88,7 @@
 	    ordersubset<-orderbook[[portfolio]][[symbol]]
 
     #data quality checks
-    if(!is.null(status) & !length(grep(status,c("open", "closed", "canceled","replaced")))==1) stop(paste("order status:",status,' must be one of "open", "closed", "canceled", or "replaced"'))
+    if(!is.null(status) & !length(grep(status,c("open", "closed", "canceled", "revoked","replaced")))==1) stop(paste("order status:",status,' must be one of "open", "closed", "canceled", "revoked", or "replaced"'))
     if(!is.null(ordertype)) {
         if(is.na(charmatch(ordertype,c("market","limit","stoplimit","stoptrailing","iceberg")))){
             stop(paste("ordertype:",ordertype,' must be one of "market","limit","stoplimit", "stoptrailing" or "iceberg"'))
@@ -200,7 +200,7 @@
 #' @param side one of either "long" or "short" 
 #' @param threshold numeric threshold to apply to limit, stoplimit, stoptrailing and iceberg orders, default NULL
 #' @param orderset set a tag identifying the orderset
-#' @param status one of "open", "closed", "canceled", or "replaced", default "open"
+#' @param status one of "open", "closed", "canceled", "revoked", or "replaced", default "open"
 #' @param statustimestamp timestamp of a status update, will be blank when order is initiated 
 #' @param delay what delay to add to timestamp when inserting the order into the order book, in seconds
 #' @param tmult if TRUE, threshold is a percent multiplier for \code{price}, not a scalar. Threshold is converted to a scalar by multiplying it with the price, then added to the price just like a scalar threshold. 
@@ -306,7 +306,7 @@
 
     if(is.null(threshold)) threshold=NA  #NA is not ignored like NULL is 
 
-    if(!length(grep(status,c("open", "closed", "canceled","replaced",'rejected')))==1) stop(paste("order status:",status,' must be one of "open", "closed", "canceled", "replaced", or "rejected"'))
+    if(!length(grep(status,c("open", "closed", "canceled", "revoked","replaced",'rejected')))==1) stop(paste("order status:",status,' must be one of "open", "closed", "canceled", "revoked", "replaced", or "rejected"'))
     # TODO do we need to check for collision, and increment timestamp?  or alternately update?
 
     # subset by time and symbol
@@ -390,7 +390,7 @@
 #' the case of a traditional Cancel/Replace, because of a trailing stop, or in the
 #' case of a partial fill that needs to enter a replaced order for the remainder. 
 #' 
-#' When a risk event or over-limit event happens, typically open orders will be 'canceled'.  
+#' When a risk event or over-limit event happens, typically open orders will be 'revoked'.  
 #' Possibly new orders will be added to close open positions.  
 #' Many models will also want to run a process at the close of market that will cancel all open orders. 
 #' 
@@ -404,8 +404,8 @@
 #' @param side one of NULL, "long" or "short", default NULL 
 #' @param qtysign one of NULL, -1,0,1 ; could be useful when all qty's are reported as positive numbers and need to be identified other ways, default NULL
 #' @param orderset set a tag identifying the orderset
-#' @param oldstatus one of NULL, "open", "closed", "canceled", or "replaced", default "open"
-#' @param newstatus one of "open", "closed", "canceled", or "replaced"
+#' @param oldstatus one of NULL, "open", "closed", "canceled", "revoked", or "replaced", default "open"
+#' @param newstatus one of "open", "closed", "canceled", "revoked", or "replaced"
 #' @param statustimestamp timestamp of a status update, will be blank when order is initiated
 #' @seealso addOrder
 #' @seealso getOrders
@@ -425,10 +425,10 @@
                  )
 { 
     #data quality checks
-    if(!is.null(oldstatus) && !length(grep(oldstatus,c("open", "closed", "canceled","replaced",'rejected')))==1) 
-        stop(paste("old order status:",oldstatus,' must be one of "open", "closed", "canceled", "replaced", or "rejected"'))
-    if(!length(grep(newstatus,c("open", "closed", "canceled","replaced",'rejected')))==1) 
-        stop(paste("new order status:",newstatus,' must be one of "open", "closed", "canceled", "replaced", or "rejected"'))
+    if(!is.null(oldstatus) && !length(grep(oldstatus,c("open", "closed", "canceled", "revoked","replaced",'rejected')))==1) 
+        stop(paste("old order status:",oldstatus,' must be one of "open", "closed", "canceled", "revoked", "replaced", or "rejected"'))
+    if(!length(grep(newstatus,c("open", "closed", "canceled", "revoked","replaced",'rejected')))==1) 
+        stop(paste("new order status:",newstatus,' must be one of "open", "closed", "canceled", "revoked", "replaced", or "rejected"'))
     if(!is.null(side) && !length(grep(side,c('long','short')))==1) 
         stop(paste("side:",side," must be one of 'long' or 'short'"))
     if(!is.null(qtysign) && (qtysign != -1 && qtysign != 1 && qtysign != 0))

Deleted: pkg/quantstrat/R/ruleCancel.R
===================================================================
--- pkg/quantstrat/R/ruleCancel.R	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/R/ruleCancel.R	2012-11-22 02:43:21 UTC (rev 1261)
@@ -1,51 +0,0 @@
-#' rule to cancel an unfilled limit order on a signal
-#' 
-#' As described elsewhere in the documentation, quantstrat models 
-#' \emph{orders}.  All orders in quantstrat are GTC orders, which means that
-#' unfilled limit orders have to be cancelled manually or replaced by other orders.
-#' 
-#' This function is used for canceling the orders based on a signal.
-#' 
-#' @param data an xts object containing market data.  depending on rules, may need to be in OHLCV or BBO formats, and may include indicator and signal information
-#' @param timestamp timestamp coercible to POSIXct that will be the time the order will be inserted on 
-#' @param sigcol column name to check for signal
-#' @param sigval signal value to match against
-#' @param orderside one of either "long" or "short", default NULL, see details 
-#' @param orderset tag to identify an orderset
-#' @param portfolio text name of the portfolio to place orders in
-#' @param symbol identifier of the instrument to cancel orders for
-#' @param ruletype must be 'risk' for ruleCancel, see \code{\link{add.rule}}
-#' @author Niklas Kolster
-#' @seealso \code{\link{osNoOp}} , \code{\link{add.rule}}
-#' @export
-ruleCancel <- function(data=mktdata, timestamp, sigcol, sigval, orderside=NULL, orderset=NULL, portfolio, symbol, ruletype)
-{
- 
-
-  if (ruletype!='risk') {
-    stop(paste('Ruletype can only be risk'))
-  }
-  
-  if(is.null(orderset)) orderset=NA
-    
-  updateOrder(portfolio=portfolio, 
-              symbol=symbol, 
-              timespan=timespan,
-              orderset=orderset, 
-              newstatus='canceled'
-             )
-  
-}
-
-###############################################################################
-# R (http://r-project.org/) Quantitative Strategy Model Framework
-#
-# Copyright (c) 2012
-# Niklas Kolster
-#
-# This library is distributed under the terms of the GNU Public License (GPL)
-# for full details see the file COPYING
-#
-# $Id$
-#
-###############################################################################

Added: pkg/quantstrat/R/ruleRevoke.R
===================================================================
--- pkg/quantstrat/R/ruleRevoke.R	                        (rev 0)
+++ pkg/quantstrat/R/ruleRevoke.R	2012-11-22 02:43:21 UTC (rev 1261)
@@ -0,0 +1,53 @@
+#' rule to revoke an unfilled limit order on a signal
+#' 
+#' As described elsewhere in the documentation, quantstrat models 
+#' \emph{orders}.  All orders in quantstrat are GTC orders, which means that
+#' unfilled limit orders have to be revokeled manually or replaced by other orders.
+#' 
+#' This function is used for revokeing the orders based on a signal.
+#' 
+#' @param data an xts object containing market data.  depending on rules, may need to be in OHLCV or BBO formats, and may include indicator and signal information
+#' @param timestamp timestamp coercible to POSIXct that will be the time the order will be inserted on 
+#' @param sigcol column name to check for signal
+#' @param sigval signal value to match against
+#' @param orderside one of either "long" or "short", default NULL, see details 
+#' @param orderset tag to identify an orderset
+#' @param portfolio text name of the portfolio to place orders in
+#' @param symbol identifier of the instrument to revoke orders for
+#' @param ruletype must be 'risk' for ruleRevoke, see \code{\link{add.rule}}
+#' @author Niklas Kolster, Jan Humme
+#' @seealso \code{\link{osNoOp}} , \code{\link{add.rule}}
+#' @export
+ruleRevoke <- function(data=mktdata, timestamp, sigcol, sigval, orderside=NULL, orderset=NULL, portfolio, symbol, ruletype)
+{
+    if(ruletype!='risk') stop('Ruletype for ruleRevoke must be risk')
+
+    pos <- getPosQty(portfolio, symbol, timestamp)
+    if(pos == 0)
+    {
+        #if(is.null(orderset)) orderset=NA
+
+        updateOrders(portfolio=portfolio, 
+                  symbol=symbol, 
+                  timespan=timespan,
+                  side=orderside,
+                  orderset=orderset, 
+                  oldstatus='open', 
+                  newstatus='revoked',
+                  statustimestamp=timestamp
+        )
+    }
+}
+
+###############################################################################
+# R (http://r-project.org/) Quantitative Strategy Model Framework
+#
+# Copyright (c) 2012
+# Niklas Kolster, Jan Humme
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: ruleRevoke.R 1233 2012-11-01 12:52:25Z braverock $
+#
+###############################################################################

Modified: pkg/quantstrat/demo/luxor-3.11.R
===================================================================
--- pkg/quantstrat/demo/luxor-3.11.R	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/demo/luxor-3.11.R	2012-11-22 02:43:21 UTC (rev 1261)
@@ -15,4 +15,4 @@
 currency(c('GBP', 'USD'))
 exchange_rate(c('GBPUSD'), tick_size=0.0001)
 
-chart.ME('luxor', type='MAE', scale='cash')
+chart.ME('luxor', 'GBPUSD', type='MAE', scale='cash')

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/man/addOrder.Rd	2012-11-22 02:43:21 UTC (rev 1261)
@@ -5,7 +5,7 @@
   addOrder(portfolio, symbol, timestamp, qty, price,
     ordertype, side, threshold = NULL, orderset = "",
     status = "open", statustimestamp = "", prefer = NULL,
-    delay = 1e-05, tmult = FALSE, replace = TRUE,
+    delay = 0.00001, tmult = FALSE, replace = TRUE,
     return = FALSE, ..., TxnFees = 0, label = "")
 }
 \arguments{
@@ -35,8 +35,8 @@
 
   \item{orderset}{set a tag identifying the orderset}
 
-  \item{status}{one of "open", "closed", "canceled", or
-  "replaced", default "open"}
+  \item{status}{one of "open", "closed", "canceled",
+  "revoked", or "replaced", default "open"}
 
   \item{statustimestamp}{timestamp of a status update, will
   be blank when order is initiated}

Modified: pkg/quantstrat/man/getOrders.Rd
===================================================================
--- pkg/quantstrat/man/getOrders.Rd	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/man/getOrders.Rd	2012-11-22 02:43:21 UTC (rev 1261)
@@ -14,8 +14,8 @@
   for.  The name of any associated price objects (xts
   prices, usually OHLC) should match these}
 
-  \item{status}{one of "open", "closed", "canceled", or
-  "replaced", default "open"}
+  \item{status}{one of "open", "closed", "canceled",
+  "revoked", or "replaced", default "open"}
 
   \item{timespan}{xts-style character timespan to be the
   period to find orders of the given status and ordertype}

Modified: pkg/quantstrat/man/ruleSignal.Rd
===================================================================
--- pkg/quantstrat/man/ruleSignal.Rd	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/man/ruleSignal.Rd	2012-11-22 02:43:21 UTC (rev 1261)
@@ -5,7 +5,7 @@
   ruleSignal(mktdata = mktdata, timestamp, sigcol, sigval,
     orderqty = 0, ordertype, orderside = NULL,
     orderset = NULL, threshold = NULL, tmult = FALSE,
-    replace = TRUE, delay = 1e-04, osFUN = "osNoOp",
+    replace = TRUE, delay = 0.0001, osFUN = "osNoOp",
     pricemethod = c("market", "opside", "active"),
     portfolio, symbol, ..., ruletype, TxnFees = 0,
     prefer = NULL, sethold = FALSE, label = "")

Modified: pkg/quantstrat/man/updateOrders.Rd
===================================================================
--- pkg/quantstrat/man/updateOrders.Rd	2012-11-22 02:05:41 UTC (rev 1260)
+++ pkg/quantstrat/man/updateOrders.Rd	2012-11-22 02:43:21 UTC (rev 1261)
@@ -31,10 +31,10 @@
   \item{orderset}{set a tag identifying the orderset}
 
   \item{oldstatus}{one of NULL, "open", "closed",
-  "canceled", or "replaced", default "open"}
+  "canceled", "revoked", or "replaced", default "open"}
 
-  \item{newstatus}{one of "open", "closed", "canceled", or
-  "replaced"}
+  \item{newstatus}{one of "open", "closed", "canceled",
+  "revoked", or "replaced"}
 
   \item{statustimestamp}{timestamp of a status update, will
   be blank when order is initiated}
@@ -53,7 +53,7 @@
   remainder.
 
   When a risk event or over-limit event happens, typically
-  open orders will be 'canceled'. Possibly new orders will
+  open orders will be 'revoked'. Possibly new orders will
   be added to close open positions. Many models will also
   want to run a process at the close of market that will
   cancel all open orders.



More information about the Blotter-commits mailing list