[Blotter-commits] r451 - in pkg/quantstrat: . man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 13 19:35:04 CET 2010


Author: braverock
Date: 2010-11-13 19:35:04 +0100 (Sat, 13 Nov 2010)
New Revision: 451

Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/man/add.rule.Rd
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/applyRules.Rd
   pkg/quantstrat/man/applyStrategy.Rd
   pkg/quantstrat/man/getOrders.Rd
   pkg/quantstrat/man/ruleOrderProc.Rd
   pkg/quantstrat/man/strategy.Rd
Log:
- update docs, DESCRIPTION, NAMESPACE

Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/DESCRIPTION	2010-11-13 18:35:04 UTC (rev 451)
@@ -5,7 +5,7 @@
 Date: $Date$
 Author: Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey A.
     Ryan, Joshua Ulrich
-Depends: xts(>= 0.7-6.1),TTR(>= 0.2),blotter(>= 0.7),
+Depends: xts(>= 0.7-6.1),TTR(>= 0.2),blotter(>= 0.7.2),
     FinancialInstrument, quantmod (>= 0.3-14)
 Suggests: PerformanceAnalytics,PortfolioAnalytics
 Maintainer: Jeffrey A. Ryan <jeff.a.ryan at gmail.com>

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/NAMESPACE	2010-11-13 18:35:04 UTC (rev 451)
@@ -23,4 +23,5 @@
 export(ruleSignal)
 export(osNoOp)
 export(addPosLimit)
+export(getPosLimit)
 export(osMaxPos)

Modified: pkg/quantstrat/man/add.rule.Rd
===================================================================
--- pkg/quantstrat/man/add.rule.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/add.rule.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -56,7 +56,7 @@
 For quantstrat to be able to (largly) vectorize the execution of path-dependent 
 rule evaluation, the rule function is presumed to have a function signature 
 like that of \code{\link{ruleSignal}}, specifically the arguments \code{sigcol} 
-and \code{sigval}.  If these are present and function in a way similar to 
+and \code{sigval}.  If these are present and function in a manner similar to 
 \code{\link{ruleSignal}} we can do some preprocessing to significantly reduce the 
 dimensionality of the index we need to loop over.  The speedup is the ratio of 
 (symbols*total observations)/signal observations, so it can be significant for many strategies.}

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/addOrder.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -77,6 +77,7 @@
 
 Conversion to a live trading environment will also likely require a new version of 
 \code{\link{applyStrategy}} to provide the event loop interface and interact with \code{mktdata}.}
+\concept{backtest}
 \arguments{\item{portfolio}{text name of the portfolio to associate the order book with}
 \item{symbol}{identfier of the instrument to find orders for.  The name of any associated price objects (xts prices, usually OHLC) should match these}
 \item{timestamp}{timestamp coercible to POSIXct that will be the time to search for orders before this time}

Modified: pkg/quantstrat/man/applyRules.Rd
===================================================================
--- pkg/quantstrat/man/applyRules.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/applyRules.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -9,7 +9,60 @@
 and then again in stepping over the time indexes of the mktdata object.
 
 Individual rule functions may need to use <<- to place \code{hold} and \code{holdtill}
-variables into play.  These would be most likely implemented by risk rules.}
+variables into play.  These would be most likely implemented by risk rules.
+
+\code{quantstrat} has a significant amount of logic devoted to handling 
+path-dependent rule execution.  Most of that code/logic resides in this
+function.  
+
+This function, along with \code{\link{ruleOrderProc}}, \code{\link{addOrder}}, and 
+\code{\link{applyStrategy}} will likely need to be replaced to connect to a live 
+market infrastructure. 
+
+\section{Dimension Reduction for Performance}{
+In evaluation of path-dependent rules, the simplest method, 
+and the one we used initially, is to check the rules on every observation 
+in the time series of market data.  
+There are cases where this will still be required, but we hope to limit them as much as possible.
+Looping in \R is generally discouraged, and on high frequency data for 
+strategy evaluation it can produce completely unacceptable results.
+
+The solution we've employed makes use of what we know about the strategy and
+the orders the strategy places (or may place) to reduce the dimensionality of the problem.
+
+As discussed in \code{\link{add.rule}}, the first step in this dimension 
+reduction is to look for places in the time series where signals may cause the strategy to 
+enter or change orders.  This creates an index of timestamps that must be evaluated.
+This index should be significantly shorter than the full number of observations.    
+\code{quantstrat} will always run \code{applyRules} on each of these indices
+where we've previously figured out that the strategy might want to do something.
+
+The next step in dimension reduction works on the order book.  
+If there are open orders, we need to figure out when they might get filled.  
+For market orders, this is the next observation.  For limit orders, we can 
+locate the index timestamps after the order is placed to see when the
+order might cross.  We will add this index to the list of indices to be 
+evaluated.  There is of course no guarantee that the order will still be 
+open at that time, that trading will not be on \code{hold} because of a risk rule, 
+or that something else hasn't interfered.  Adding the index to the list only tells
+the loop inside \code{applyRules} that rules (including order processing rules) 
+need to be checked at that index, to see if anything needs to happen.
+
+For trailing orders, the picture is somewhat more complicated.  Trailing orders
+\emph{may} move on each new observation, per the method described in 
+\code{\link{addOrder}}. To speed up evaluation of when such an
+order may cross, we need to combine the possible crossing logic for 
+the limit orders, above, with some additional logic to handle the 
+trailing orders. We begin by evaluating when the order price might 
+be moved. We then examine the market data between the current index and 
+the point at which the order may move. if there is a (possible) cross, 
+we insert that index into the indices for examination.  If not, we insert 
+the index of the next probably move.
+
+It should be noted that this dimension reduction methodology does 'look ahead'
+in the data.  This 'look ahead' is only done \emph{after} the order has been 
+entered in the normal path-dependent process, and so should not introduce biases.     
+}}
 \seealso{\code{\link{add.rule}} \code{\link{applyStrategy}}}
 \arguments{\item{portfolio}{text name of the portfolio to associate the order book with}
 \item{symbol}{identfier of the instrument to find orders for.  The name of any associated price objects (xts prices, usually OHLC) should match these}

Modified: pkg/quantstrat/man/applyStrategy.Rd
===================================================================
--- pkg/quantstrat/man/applyStrategy.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/applyStrategy.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -1,7 +1,8 @@
 \name{applyStrategy}
 \alias{applyStrategy}
 \title{apply the strategy to arbitrary market data...}
-\usage{applyStrategy(strategy, portfolios, mktdata, parameters, ...)}
+\usage{applyStrategy(strategy, portfolios, mktdata, parameters, ...,
+    verbose=TRUE)}
 \description{apply the strategy to arbitrary market data}
 \details{if \code{mktdata} is NULL, the default, the mktdata variable will be populated 
 for each symbol via a call to get (getSymbols??, not yet)}
@@ -9,4 +10,5 @@
 \item{portfolios}{a list of portfolios to apply the strategy to}
 \item{mktdata}{an xts object containing market data.  depending on indicators, may need to be in OHLCV or BBO formats, default NULL}
 \item{parameters}{named list of parameters to be applied during evaluation of the strategy, default NULL}
-\item{...}{any other passthru parameters}}
+\item{...}{any other passthru parameters}
+\item{verbose}{if TRUE, return output list}}

Modified: pkg/quantstrat/man/getOrders.Rd
===================================================================
--- pkg/quantstrat/man/getOrders.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/getOrders.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -12,7 +12,7 @@
 \arguments{\item{portfolio}{text name of the portfolio to associate the order book with}
 \item{symbol}{identfier of the instrument to find orders 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{timespan}{xts-style character timespan to be the period to find orders of the given status and ordertype, not yet used here}
+\item{timespan}{xts-style character timespan to be the period to find orders of the given status and ordertype, not yet used}
 \item{ordertype}{one of NULL, "market","limit","stoplimit", "stoptrailing", or "iceberg" default NULL}
 \item{side}{one of NULL, "long" or "short", default NULL}
 \item{which.i}{if TRUE, return the row index numbers rather than the order rows matching the criteria, default FALSE}}

Modified: pkg/quantstrat/man/ruleOrderProc.Rd
===================================================================
--- pkg/quantstrat/man/ruleOrderProc.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/ruleOrderProc.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -24,7 +24,7 @@
 
 Note that this function is called by default in the 'orders' slot of the 
 \code{\link{applyRules}} processing.  If you have defined another order 
-processing rule, it with \emph{replace} this function.  If you want your 
+processing rule, it will \emph{replace} this function.  If you want your 
 custom order rule and ruleOrderProc to both be called, you will need
 explicitly add a rule to call ruleOrderProc either before or after your 
 custom order processing function. 
@@ -33,6 +33,7 @@
 and requests appreciated.}
 \concept{fill simulator}
 \concept{orders}
+\concept{backtest}
 \arguments{\item{portfolio}{text name of the portfolio to associate the order book with}
 \item{symbol}{identfier of the instrument to find orders for.  The name of any associated price objects (xts prices, usually OHLC or BBO) should match these}
 \item{mktdata}{an xts object containing market data.  depending on indicators, may need to be in OHLCV or BBO formats, default NULL}

Modified: pkg/quantstrat/man/strategy.Rd
===================================================================
--- pkg/quantstrat/man/strategy.Rd	2010-11-13 18:30:40 UTC (rev 450)
+++ pkg/quantstrat/man/strategy.Rd	2010-11-13 18:35:04 UTC (rev 451)
@@ -5,6 +5,6 @@
 \description{constructor for objects of type 'strategy'}
 \arguments{\item{name}{character string naming the strategy}
 \item{...}{any other passthru parameters}
-\item{assets}{optional list of assets to apply the strategy to}
+\item{assets}{optional list of assets to apply the strategy to, should normally be defined in the portfolio, not here}
 \item{constraints}{optional portfolio constraints object matching assets}
 \item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE}}



More information about the Blotter-commits mailing list