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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 6 13:11:24 CET 2010


Author: braverock
Date: 2010-02-06 13:11:21 +0100 (Sat, 06 Feb 2010)
New Revision: 231

Added:
   pkg/quantstrat/man/add.rule.Rd
Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/R/indicators.R
   pkg/quantstrat/R/signals.R
   pkg/quantstrat/R/strategy.R
   pkg/quantstrat/R/traderules.R
   pkg/quantstrat/man/add.indicator.Rd
   pkg/quantstrat/man/add.signal.Rd
   pkg/quantstrat/man/sigCrossover.Rd
   pkg/quantstrat/man/sigPeak.Rd
   pkg/quantstrat/man/sigThreshold.Rd
Log:
- add.rule documentation
- multiple documentation updates
- updates to pass R CMD check
- bump version to 0.0.2

Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/DESCRIPTION	2010-02-06 12:11:21 UTC (rev 231)
@@ -1,13 +1,13 @@
 Package: quantstrat
 Type: Package
 Title: Quantitative Strategy Model Framework
-Version: 0.0.1
-Date: 2010-01-25
+Version: 0.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)
 Suggests: PerformanceAnalytics,PortfolioAnalytics
 Maintainer: Jeffrey A. Ryan <jeff.a.ryan at gmail.com>
-Description: Specify, build, and backtest quantitative financial trading strategies
+Description: Specify, build, and back-test quantitative financial trading and portfolio strategies
 LazyLoad: yes
 License: GPL-3
-Collate: 'indicators.R' 'match.names.R' 'signals.R' 'strategy.R'
+Collate: 'indicators.R' 'match.names.R' 'signals.R' 'strategy.R' 'traderules.R'

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/NAMESPACE	2010-02-06 12:11:21 UTC (rev 231)
@@ -11,3 +11,4 @@
 export(applyStrategy)
 export(is.strategy)
 export(getStrategy)
+export(add.rule)

Modified: pkg/quantstrat/R/indicators.R
===================================================================
--- pkg/quantstrat/R/indicators.R	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/R/indicators.R	2010-02-06 12:11:21 UTC (rev 231)
@@ -3,6 +3,7 @@
 #' @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
+#' @param label arbitrary text label for indicator output, NULL default will be converted to '<name>.ind'
 #' @param ... any other passthru parameters
 #' @param enabled TRUE/FALSE whether the indicator is enabled for use in applying the strategy, default TRUE
 #' @param indexnum if you are updating a specific indicator, the index number in the $indicators list to update
@@ -61,7 +62,7 @@
             }
         }
         
-        if(!is.true(indicator$enabled)) next()
+        if(!isTRUE(indicator$enabled)) next()
         
         # see 'S Programming p. 67 for this matching
         fun<-match.fun(indicator$name)

Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/R/signals.R	2010-02-06 12:11:21 UTC (rev 231)
@@ -1,5 +1,5 @@
 
-#' add an signal to a strategy
+#' add a signal to a strategy
 #' @param strategy an object of type 'strategy' to add the signal to
 #' @param name name of the signal, must correspond to an R function
 #' @param arguments default arguments to be passed to an signal function when executed
@@ -64,7 +64,7 @@
             }
         }
  
-        if(!is.true(signal$enabled)) next()
+        if(!isTRUE(signal$enabled)) next()
         
         # see 'S Programming p. 67 for this matching
         fun<-match.fun(signal$name)
@@ -144,7 +144,7 @@
 
 #' generate a crossover signal
 #' 
-#' This will generate a corssover signal, which is a dimension-reduced version 
+#' This will generate a crossover signal, which is a dimension-reduced version 
 #' of a comparison signal \code{\link{sigComparison}}.
 #' 
 #' It will return TRUE on the period in which there is a crossover in the 
@@ -164,6 +164,9 @@
 }
 
 #' signal function for peak/valley signals
+#' 
+#' This function tests to see if the mktdata or indicator \code{column} observations 
+#' on either side are lower(higher) creating a local peak(bottom).
 #' @param label text label to apply to the output
 #' @param data data to apply comparison to
 #' @param column named column to apply comparison to
@@ -191,6 +194,7 @@
 #' @param label text label to apply to the output
 #' @param data data to apply comparison to
 #' @param column named column to apply comparison to
+#' @param threshold numeric threhold to test for
 #' @param relationship one of c("gt","lt","eq","gte","lte") or reasonable alternatives
 #' @export
 sigThreshold <- function(label, data, column, threshold=0, relationship=c("gt","lt","eq","gte","lte")) {

Modified: pkg/quantstrat/R/strategy.R
===================================================================
--- pkg/quantstrat/R/strategy.R	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/R/strategy.R	2010-02-06 12:11:21 UTC (rev 231)
@@ -79,7 +79,7 @@
     ret$indicators <- applyIndicators(strategy , mktdata , ... )
      
     #loop over signal generators
-    ret$signals <- applySignals(strategy, mktdata, indicators, ... )
+    ret$signals <- applySignals(strategy, mktdata, ret$indicators, ... )
 
     #loop over rules 
     

Modified: pkg/quantstrat/R/traderules.R
===================================================================
--- pkg/quantstrat/R/traderules.R	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/R/traderules.R	2010-02-06 12:11:21 UTC (rev 231)
@@ -2,25 +2,33 @@
 #' 
 #' Rules will be processed in a very particular manner, so it bears going over.
 #' 
-#' First, rules are either path dependent or non-path-dependent.  path dependent rules 
+#' First, rules are either path dependent or non-path-dependent.  Path dependent rules 
 #' will be processed in every time increment for the \code{mktdata} passed into
 #' \code{\link{applyStrategy}}.  Non path dependent rules will likely be quite rare in real life, 
 #' and will be applied after indicators and signals, and before path-dependent rules are processed.
 #' 
 #' All rules have a \code{type}.  These may be any of:
 #' \itemize{
-#'   \item{risk }{rules that check and react to risk of positions, may stop all other rule execution temporarily or permanently}
-#'   \item{order }{order processing of any open orders at time t, always path-dependent}
-#'   \item{rebalance }{rules executed specifically in a portfolio context, unnecessary in univariate strategies}
-#'   \item{exit}{rules to determine whether to exit a position}
-#'   \item{enter}{rules to determine whether to enter a position}
+#'   \item{risk}{ rules that check and react to risk of positions, may stop all other rule execution temporarily or permanently}
+#'   \item{order}{ rules for order processing of any open orders at time t, always path-dependent}
+#'   \item{rebalance}{ rules executed specifically in a portfolio context, unnecessary in univariate strategies}
+#'   \item{exit}{ rules to determine whether to exit a position}
+#'   \item{enter}{ rules to determine whether to enter or increase a position}
 #' }  
 #' The rules will be executed by type, in the order listed above.  
 #' Multiple rules of each type may be defined, as with signals and indicators, 
 #' they will be executed in order by index number with any other rules sharing the same 
 #' type.
 #' 
-#' We anticipate that rules will be the part of a strategy most likely to 
+#' The rule execution order was constructed because path-dependent rules may modify   
+#' the ability of rules that have not fired yet to be evaluated.  For example, a 
+#' risk rule may flatten (close out) an entire position and put new orders 
+#' on hold, effectively stopping all further execution of the strategy.  
+#' Another example would be a rebalancing rule function that would enter 
+#' orders to rebalance the portfolio, and would hold other strategy processing 
+#' until the rebalancing period was over.
+#' 
+#' We anticipate that rules will be the portion of a strategy most likely to 
 #' not have suitable template code included with this package, as every strategy 
 #' and environment are different, especially in this respect.  
 #' We will attempt to provide enough examples and generic rules to give strategy
@@ -29,10 +37,12 @@
 #' @param strategy an object of type 'strategy' to add the rule to
 #' @param name name of the rule, must correspond to an R function
 #' @param arguments default arguments to be passed to an rule function when executed
-#' @param type 
+#' @param label arbitrary text label for signal output, NULL default will be converted to '<name>.sig'
+#' @param type one of "risk","order","rebalance","exit","entry", see Details
 #' @param ... any other passthru parameters
 #' @param enabled TRUE/FALSE whether the rule is enabled for use in applying the strategy, default TRUE
-#' @param indexnum if you are updating a specific rule, the index number in the $rules list to update
+#' @param indexnum if you are updating a specific rule, the index number in the $rules[type] list to update
+#' @param path.dep TRUE/FALSE whether rule is path dependent, default TRUE, see Details 
 #' @param store TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE
 #' @export
 add.rule <- function(strategy, name, arguments, label=NULL, type=c(NULL,"risk","order","rebalance","exit","entry"), ..., enabled=TRUE, indexnum=NULL, path.dep=TRUE, store=FALSE) {

Modified: pkg/quantstrat/man/add.indicator.Rd
===================================================================
--- pkg/quantstrat/man/add.indicator.Rd	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/man/add.indicator.Rd	2010-02-06 12:11:21 UTC (rev 231)
@@ -6,6 +6,7 @@
 \arguments{\item{strategy}{an object of type 'strategy' to add the indicator to}
 \item{name}{name of the indicator, must correspond to an R function}
 \item{arguments}{default arguments to be passed to an indicator function when executed}
+\item{label}{arbitrary text label for indicator output, NULL default will be converted to '<name>.ind'}
 \item{...}{any other passthru parameters}
 \item{enabled}{TRUE/FALSE whether the indicator is enabled for use in applying the strategy, default TRUE}
 \item{indexnum}{if you are updating a specific indicator, the index number in the $indicators list to update}

Added: pkg/quantstrat/man/add.rule.Rd
===================================================================
--- pkg/quantstrat/man/add.rule.Rd	                        (rev 0)
+++ pkg/quantstrat/man/add.rule.Rd	2010-02-06 12:11:21 UTC (rev 231)
@@ -0,0 +1,49 @@
+\name{add.rule}
+\alias{add.rule}
+\title{add a rule to a strategy...}
+\usage{add.rule(strategy, name, arguments, label, type=c(NULL, "risk", "order", "rebalance", "exit", "entry"), ..., enabled=TRUE, indexnum,
+    path.dep=TRUE, store=FALSE)}
+\description{add a rule to a strategy}
+\details{Rules will be processed in a very particular manner, so it bears going over.
+
+First, rules are either path dependent or non-path-dependent.  Path dependent rules 
+will be processed in every time increment for the \code{mktdata} passed into
+\code{\link{applyStrategy}}.  Non path dependent rules will likely be quite rare in real life, 
+and will be applied after indicators and signals, and before path-dependent rules are processed.
+
+All rules have a \code{type}.  These may be any of:
+\itemize{
+\item{risk}{ rules that check and react to risk of positions, may stop all other rule execution temporarily or permanently}
+\item{order}{ rules for order processing of any open orders at time t, always path-dependent}
+\item{rebalance}{ rules executed specifically in a portfolio context, unnecessary in univariate strategies}
+\item{exit}{ rules to determine whether to exit a position}
+\item{enter}{ rules to determine whether to enter or increase a position}
+}  
+The rules will be executed by type, in the order listed above.  
+Multiple rules of each type may be defined, as with signals and indicators, 
+they will be executed in order by index number with any other rules sharing the same 
+type.
+
+The rule execution order was constructed because path-dependent rules may modify   
+the ability of rules that have not fired yet to be evaluated.  For example, a 
+risk rule may flatten (close out) an entire position and put new orders 
+on hold, effectively stopping all further execution of the strategy.  
+Another example would be a rebalancing rule function that would enter 
+orders to rebalance the portfolio, and would hold other strategy processing 
+until the rebalancing period was over.
+
+We anticipate that rules will be the portion of a strategy most likely to 
+not have suitable template code included with this package, as every strategy 
+and environment are different, especially in this respect.  
+We will attempt to provide enough examples and generic rules to give strategy
+authors a place to start.}
+\arguments{\item{strategy}{an object of type 'strategy' to add the rule to}
+\item{name}{name of the rule, must correspond to an R function}
+\item{arguments}{default arguments to be passed to an rule function when executed}
+\item{label}{arbitrary text label for signal output, NULL default will be converted to '<name>.sig'}
+\item{type}{one of "risk","order","rebalance","exit","entry", see Details}
+\item{...}{any other passthru parameters}
+\item{enabled}{TRUE/FALSE whether the rule is enabled for use in applying the strategy, default TRUE}
+\item{indexnum}{if you are updating a specific rule, the index number in the $rules[type] list to update}
+\item{path.dep}{TRUE/FALSE whether rule is path dependent, default TRUE, see Details}
+\item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE}}


Property changes on: pkg/quantstrat/man/add.rule.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/quantstrat/man/add.signal.Rd
===================================================================
--- pkg/quantstrat/man/add.signal.Rd	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/man/add.signal.Rd	2010-02-06 12:11:21 UTC (rev 231)
@@ -1,8 +1,8 @@
 \name{add.signal}
 \alias{add.signal}
-\title{add an signal to a strategy...}
+\title{add a signal to a strategy...}
 \usage{add.signal(strategy, name, arguments, label, ..., enabled=TRUE, indexnum, store=FALSE)}
-\description{add an signal to a strategy}
+\description{add a signal to a strategy}
 \arguments{\item{strategy}{an object of type 'strategy' to add the signal to}
 \item{name}{name of the signal, must correspond to an R function}
 \item{arguments}{default arguments to be passed to an signal function when executed}

Modified: pkg/quantstrat/man/sigCrossover.Rd
===================================================================
--- pkg/quantstrat/man/sigCrossover.Rd	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/man/sigCrossover.Rd	2010-02-06 12:11:21 UTC (rev 231)
@@ -3,7 +3,7 @@
 \title{generate a crossover signal...}
 \usage{sigCrossover(label, data, columns, relationship=c("gt", "lt", "eq", "gte", "lte"))}
 \description{generate a crossover signal}
-\details{This will generate a corssover signal, which is a dimension-reduced version 
+\details{This will generate a crossover signal, which is a dimension-reduced version 
 of a comparison signal \code{\link{sigComparison}}.
 
 It will return TRUE on the period in which there is a crossover in the 

Modified: pkg/quantstrat/man/sigPeak.Rd
===================================================================
--- pkg/quantstrat/man/sigPeak.Rd	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/man/sigPeak.Rd	2010-02-06 12:11:21 UTC (rev 231)
@@ -3,6 +3,8 @@
 \title{signal function for peak/valley signals...}
 \usage{sigPeak(label, data, column, direction=c("peak", "bottom"))}
 \description{signal function for peak/valley signals}
+\details{This function tests to see if the mktdata or indicator \code{column} observations 
+on either side are lower(higher) creating a local peak(bottom).}
 \arguments{\item{label}{text label to apply to the output}
 \item{data}{data to apply comparison to}
 \item{column}{named column to apply comparison to}

Modified: pkg/quantstrat/man/sigThreshold.Rd
===================================================================
--- pkg/quantstrat/man/sigThreshold.Rd	2010-02-06 11:04:13 UTC (rev 230)
+++ pkg/quantstrat/man/sigThreshold.Rd	2010-02-06 12:11:21 UTC (rev 231)
@@ -9,4 +9,5 @@
 \arguments{\item{label}{text label to apply to the output}
 \item{data}{data to apply comparison to}
 \item{column}{named column to apply comparison to}
+\item{threshold}{numeric threhold to test for}
 \item{relationship}{one of c("gt","lt","eq","gte","lte") or reasonable alternatives}}



More information about the Blotter-commits mailing list