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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 13 19:15:56 CEST 2010


Author: braverock
Date: 2010-07-13 19:15:56 +0200 (Tue, 13 Jul 2010)
New Revision: 351

Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/R/indicators.R
   pkg/quantstrat/R/signals.R
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/ruleOrderProc.Rd
   pkg/quantstrat/man/ruleSignal.Rd
   pkg/quantstrat/man/stratBBands.Rd
Log:
- update docs

Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/DESCRIPTION	2010-07-13 17:15:56 UTC (rev 351)
@@ -3,11 +3,15 @@
 Title: Quantitative Strategy Model Framework
 Version: 0.2
 Date: 2010-02-06
-Author: Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey A. Ryan, Joshua Ulrich
-Depends: xts(>= 0.7-0),TTR(>= 0.2),blotter(>= 0.4), FinancialInstrument, quantmod (>= 0.3-14)
+Author: Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey A.
+    Ryan, Joshua Ulrich
+Depends: xts(>= 0.7-0),TTR(>= 0.2),blotter(>= 0.4),
+    FinancialInstrument, quantmod (>= 0.3-14)
 Suggests: PerformanceAnalytics,PortfolioAnalytics
 Maintainer: Jeffrey A. Ryan <jeff.a.ryan at gmail.com>
-Description: Specify, build, and back-test quantitative financial trading and portfolio strategies
+Description: Specify, build, and back-test quantitative financial
+    trading and portfolio strategies
 LazyLoad: yes
 License: GPL-3
-Collate: 'indicators.R' 'match.names.R' 'orders.R' 'parameters.R' 'rules.R' 'signals.R' 'strategy.R' 'traderules.R'
+Collate: 'indicators.R' 'match.names.R' 'orders.R' 'parameters.R'
+    'rules.R' 'signals.R' 'strategy.R' 'traderules.R'

Modified: pkg/quantstrat/R/indicators.R
===================================================================
--- pkg/quantstrat/R/indicators.R	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/R/indicators.R	2010-07-13 17:15:56 UTC (rev 351)
@@ -1,5 +1,17 @@
 
 #' add an indicator to a strategy
+#'
+#' Indicators are typically standard technical or statistical analysis outputs, 
+#' such as moving averages, bands, or pricing models.
+#'
+#' Indicators are always path-independent, and should be constructed from vectorized functions where possible.
+#'
+#' Indicators are applied before signals and rules, and the output of indicators 
+#' may be used as inputs to construct signals or fire rules.
+#'
+#' 
+#'
+#'
 #' @param strategy an object of type 'strategy' to add the indicator to
 #' @param name name of the indicator, must correspond to an R function
 #' @param arguments default arguments to be passed to an indicator function when executed

Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/R/signals.R	2010-07-13 17:15:56 UTC (rev 351)
@@ -241,8 +241,8 @@
             'lteq'=,
             'le'     = {ret_sig = data[,colNum] <= threshold}
     )
+    if(isTRUE(cross)) ret_sig <- diff(ret_sig)==1
     colnames(ret_sig)<-label
-    if(isTRUE(cross)) ret_sig <- diff(ret_sig)==1
     return(ret_sig)
 }
 

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/man/addOrder.Rd	2010-07-13 17:15:56 UTC (rev 351)
@@ -5,7 +5,17 @@
     threshold, status="open", replace=TRUE, statustimestamp="",
     delay=1e-05)}
 \description{add an order to the order book}
-\details{By default, this function will locate and replace any 'open' order(s) 
+\details{It is important to understand that all the order functionality included in \code{quantstrat}
+exists to more closely model a real trading environment both in backtesting and in production.
+Many backtesting systems make a set of assumptions about instant execution, 
+and we have chosen not to do this in quantstrat, because real quantitative 
+trading systems do not have instant execution.  They make decisions 
+(the Rules) and then enter orders (the province of this function in backtesting),
+during which there is some \code{delay} between receiving the data that fires the 
+Signal and Rule, and the time the order reaches the market, and then those orders 
+MAY become transactions if market prices and liquidity cooperate.  
+
+By default, this function will locate and replace any 'open' order(s) 
 on the requested portfolio/symbol that have the same type and side.  
 This is the equivalent of what is sometimes called an 
 OCO (Order Cancels Other) order.  If you do not want the function to 
@@ -20,7 +30,24 @@
 The 'stoptrailing' order type is the only order type that makes use of the order \code{threshold}, which 
 is the difference either positive or negative from the current price when the order is entered.  
 Some markets and brokers recognize a stop that triggers a market order, when the stop is triggered, 
-a market order will be executed at the then-prevailing price.  We have not modeled this type of order.}
+a market order will be executed at the then-prevailing price.  We have not modeled this type of order.   
+
+If you ever wanted to move from a backtesting mode to a production mode, 
+this function (and the linked funtion \code{\link{ruleOrderProc}}) would 
+need to be replaced by functions that worked against your execution environment.  
+Basically, the execution environment must provide three interfaces in a live 
+trading environment:
+
+\enumerate{
+\item a market data interface to provide updated market data, usually accessed in an event loop
+
+\item an order interface for sending orders (and canceling or updating them) to the market
+
+\item a fill interface that reports the transaction details when an order has been filled 
+}
+
+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}.}
 \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/ruleOrderProc.Rd
===================================================================
--- pkg/quantstrat/man/ruleOrderProc.Rd	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/man/ruleOrderProc.Rd	2010-07-13 17:15:56 UTC (rev 351)
@@ -4,6 +4,9 @@
 \usage{ruleOrderProc(portfolio, symbol, mktdata, timespan, ordertype, ...,
     slippageFUN)}
 \description{process open orders at time t, generating transactions or new orders}
+\details{This function is meant to be sufficient for backtesting most strategies, 
+but would need to be replaced for production use.  It provides the interface 
+for taking the order book and determining when orders become trades.}
 \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{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/ruleSignal.Rd
===================================================================
--- pkg/quantstrat/man/ruleSignal.Rd	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/man/ruleSignal.Rd	2010-07-13 17:15:56 UTC (rev 351)
@@ -19,7 +19,7 @@
 \item{timestamp}{timestamp coercible to POSIXct that will be the time the order will be inserted on}
 \item{sigcol}{column name to check for signal}
 \item{sigval}{signal value to match against}
-\item{orderqty}{numeric quantity of the desired order, modified by osFUN}
+\item{orderqty}{numeric quantity of the desired order, or 'all', modified by osFUN}
 \item{ordertype}{one of "market","limit","stoplimit", or "stoptrailing"}
 \item{orderside}{one of either "long" or "short", default NULL, see details}
 \item{threshold}{numeric or function threshold to apply to trailing stop orders, default NULL, see Details}

Modified: pkg/quantstrat/man/stratBBands.Rd
===================================================================
--- pkg/quantstrat/man/stratBBands.Rd	2010-07-13 15:45:58 UTC (rev 350)
+++ pkg/quantstrat/man/stratBBands.Rd	2010-07-13 17:15:56 UTC (rev 351)
@@ -9,6 +9,13 @@
 \section{Indicators}{
     This strategy uses only a single indicator, comprised of the TTR function \code{BBands}.
     Parameters for this indicator include number of MA periods, and the size of the bands in standard deviations.
+
+    If constructed from scratch, the indicators would consist of:
+    \describe{
+	\item{moving average}{a moving average parameterized by MA type (simple, expontnetial, Kalman, etc.) and MA periods to smooth over}
+	\item{upper band}{ the upper band constructed classically by standard deviations from the moving average, or alternately by some other upper band generating function, and parameterized chiefly by the amplitude of the band, typically number of standard deviations from the midpoint or moving average indicator}
+	\item{lower band}{ the lower band traditionally constructed to be symetrical and opposite the upper band, but potentially constructed via a different function or parameterized differently than the upper band function}
+    }
 }
 \section{Signals}{
     The classic Bollinger Bands strategy depends on crossover events (signals) for the upper and lower band and the midpoint.
@@ -51,4 +58,4 @@
     \url{http://trading-strategies.netfirms.com/trading/bollingerbandtactics.htm}
 }
 \keyword{datasets}
-\keyword{ ts } 
\ No newline at end of file
+\keyword{ ts } 



More information about the Blotter-commits mailing list