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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 19 13:31:54 CET 2013


Author: braverock
Date: 2013-03-19 13:31:54 +0100 (Tue, 19 Mar 2013)
New Revision: 1409

Added:
   pkg/quantstrat/man/chart.forward.testing.Rd
   pkg/quantstrat/man/chart.forward.training.Rd
   pkg/quantstrat/man/put.orderbook.Rd
   pkg/quantstrat/man/put.strategy.Rd
   pkg/quantstrat/man/walk.forward.Rd
Modified:
   pkg/quantstrat/R/ruleOrderProc.R
   pkg/quantstrat/R/rules.R
   pkg/quantstrat/man/add.rule.Rd
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/initStrategy.Rd
   pkg/quantstrat/man/paramConstraint.Rd
Log:
- use order price for fill in low-frequency data, thanks to Peter Carl for investigating changes caused by newer xts Date index handling 
- multiple documentation updates, mostly to walk.forward
- props to Chinmay Patil for comments on chain rule descriptions
- bump version

Modified: pkg/quantstrat/R/ruleOrderProc.R
===================================================================
--- pkg/quantstrat/R/ruleOrderProc.R	2013-03-10 20:43:32 UTC (rev 1408)
+++ pkg/quantstrat/R/ruleOrderProc.R	2013-03-19 12:31:54 UTC (rev 1409)
@@ -109,6 +109,9 @@
             #if( NROW(mktdataTimestamp) > 1 ) mktdataTimestamp <- last(mktdataTimestamp)
 
             orderType <- ordersubset[ii,"Order.Type"]
+            
+            if(hasArg(allowMagicalThinking)) allowMagicalThinking=match.call(expand.dots=TRUE)$allowMagicalThinking
+            else allowMagicalThinking = FALSE
 
             freq = periodicity(mktdata)
             #switch on frequency
@@ -120,7 +123,18 @@
                                 monthly = {
                                     txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g. in the intraday cross, or leading into the end of month, quarter, etc.
                                     # txntime=as.character(timestamp) # use this if you wanted to transact on the close of the next bar
-                                    txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1])
+                                    # txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1])
+									txnprice = orderPrice
+                                },
+                                daily = {
+                                    if(isTRUE(allowMagicalThinking)){
+                                        txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g. in the intraday cross, or leading into the end of month, quarter, etc.
+                                        #txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1])
+										txnprice = orderPrice
+                                    } else {
+                                        txntime = timestamp
+                                        txnprice = as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1]) #filled at now-prevailing 'price'
+                                    }
                                 }, #end daily
                                 { 
                                     txntime = timestamp

Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2013-03-10 20:43:32 UTC (rev 1408)
+++ pkg/quantstrat/R/rules.R	2013-03-19 12:31:54 UTC (rev 1409)
@@ -15,7 +15,7 @@
 #'   \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}
-#'   \item{chain}{ rules executed upon fill of the corresponding order, identified by label }
+#'   \item{chain}{ rules executed upon fill of an order corresponding to the label of the parent rule identified by the \code{parent} arg. }
 #' } 
 #'  
 #' The rules will be executed by type, in the order listed above.  
@@ -65,7 +65,7 @@
 #' @param parameters vector of strings naming parameters to be saved for apply-time definition
 #' @param label arbitrary text label for rule output, NULL default will be converted to '<name>.rule'
 #' @param type one of "risk","order","rebalance","exit","enter","chain" see Details
-#' @param parent the parent rule for a chain rule
+#' @param parent the label of the parent rule for a chain rule
 #' @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[type] list to update
@@ -104,7 +104,7 @@
     tmp_rule$type<-type
     if(type == 'chain')
     {
-        if(is.null(parent)) stop("You must specify a parent if ruletype=='chain'")
+        if(is.null(parent)) stop("You must specify the label of the parent rule if ruletype=='chain'")
         tmp_rule$parent<-parent
     }
     tmp_rule$enabled<-enabled
@@ -541,8 +541,7 @@
                         cross<-sigThreshold(data=mkt_price_series, label='tmptrail',column=col,threshold=tmpprice,relationship=relationship)
                         # find first index that would cross after this index
                         if (any(cross[trailspan])){
-                            newidx <- curIndex + which(cross[trailspan])[1] - 1  #curIndex/firsttime was 1 in the subset, we need a -1 offset?
-                            newidx <- index(mktdata[index(which(cross[trailspan])[1]),which.i=TRUE])
+                            newidx <- curIndex + index(mktdata[index(which(cross[trailspan])[1]),which.i=TRUE])
                             # insert that into dindex
                             assign.dindex(c(get.dindex(),newidx))
                         } else {

Modified: pkg/quantstrat/man/add.rule.Rd
===================================================================
--- pkg/quantstrat/man/add.rule.Rd	2013-03-10 20:43:32 UTC (rev 1408)
+++ pkg/quantstrat/man/add.rule.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -29,7 +29,8 @@
   "risk","order","rebalance","exit","enter","chain" see
   Details}
 
-  \item{parent}{the parent rule for a chain rule}
+  \item{parent}{the label of the parent rule for a chain
+  rule}
 
   \item{...}{any other passthru parameters}
 
@@ -80,8 +81,9 @@
   univariate strategies} \item{exit}{ rules to determine
   whether to exit a position} \item{enter}{ rules to
   determine whether to enter or increase a position}
-  \item{chain}{ rules executed upon fill of the
-  corresponding order, identified by label } }
+  \item{chain}{ rules executed upon fill of an order
+  corresponding to the label of the parent rule identified
+  by the \code{parent} arg. } }
 
   The rules will be executed by type, in the order listed
   above. Multiple rules of each type may be defined, as

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2013-03-10 20:43:32 UTC (rev 1408)
+++ pkg/quantstrat/man/addOrder.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -5,7 +5,7 @@
   addOrder(portfolio, symbol, timestamp, qty, price,
     ordertype, side, threshold = NULL, orderset = "",
     status = "open", statustimestamp = "", prefer = NULL,
-    delay = 0.00001, tmult = FALSE, replace = TRUE,
+    delay = 1e-05, tmult = FALSE, replace = TRUE,
     return = FALSE, ..., TxnFees = 0, label = "")
 }
 \arguments{

Added: pkg/quantstrat/man/chart.forward.testing.Rd
===================================================================
--- pkg/quantstrat/man/chart.forward.testing.Rd	                        (rev 0)
+++ pkg/quantstrat/man/chart.forward.testing.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -0,0 +1,14 @@
+\name{chart.forward.testing}
+\alias{chart.forward.testing}
+\title{Chart to analyse walk.forward() objective function}
+\usage{
+  chart.forward.testing(audit.filename)
+}
+\arguments{
+  \item{audit.filename}{name of .audit environment file as
+  produced by walk.forward()}
+}
+\description{
+  Chart to analyse walk.forward() objective function
+}
+


Property changes on: pkg/quantstrat/man/chart.forward.testing.Rd
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: pkg/quantstrat/man/chart.forward.training.Rd
===================================================================
--- pkg/quantstrat/man/chart.forward.training.Rd	                        (rev 0)
+++ pkg/quantstrat/man/chart.forward.training.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -0,0 +1,14 @@
+\name{chart.forward.training}
+\alias{chart.forward.training}
+\title{Chart to analyse walk.forward() objective function}
+\usage{
+  chart.forward.training(audit.filename)
+}
+\arguments{
+  \item{audit.filename}{name of .audit environment file as
+  produced by walk.forward()}
+}
+\description{
+  Chart to analyse walk.forward() objective function
+}
+


Property changes on: pkg/quantstrat/man/chart.forward.training.Rd
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: pkg/quantstrat/man/initStrategy.Rd
===================================================================
--- pkg/quantstrat/man/initStrategy.Rd	2013-03-10 20:43:32 UTC (rev 1408)
+++ pkg/quantstrat/man/initStrategy.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -42,8 +42,8 @@
   \item{init.Portf}{if TRUE, will call
   \code{\link[blotter]{initPortf}} to initialize the
   portfolio object} \item{init.Acct}{if TRUE, will call
-  \code{\link[blotter]{initAccount}} to initialize the
-  account object} \item{init.Orders}{if TRUE, will call
+  \code{\link[blotter]{initAcct}} to initialize the account
+  object} \item{init.Orders}{if TRUE, will call
   \code{\link{initOrders}} to initialize the order book for
   this test} \item{unique}{not yet implemented, will force
   a unique portfolio and account name if the portfolio,

Modified: pkg/quantstrat/man/paramConstraint.Rd
===================================================================
--- pkg/quantstrat/man/paramConstraint.Rd	2013-03-10 20:43:32 UTC (rev 1408)
+++ pkg/quantstrat/man/paramConstraint.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -1,6 +1,6 @@
 \name{paramConstraint}
 \alias{paramConstraint}
-\title{Internal function used in applyParameter function for process constraints on relationship between two parameter values. Basicly is the same as sigComparison function in signal.R written by Brian, with miner change.}
+\title{Internal function used in applyParameter function for process constraints on relationship between two parameter values. Basicly is the same as sigComparison function in signal.R written by Brian, with minor change.}
 \usage{
   paramConstraint(label, data = mktdata, columns,
     relationship = c("gt", "lt", "eq", "gte", "lte", "op"))

Added: pkg/quantstrat/man/put.orderbook.Rd
===================================================================
--- pkg/quantstrat/man/put.orderbook.Rd	                        (rev 0)
+++ pkg/quantstrat/man/put.orderbook.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -0,0 +1,24 @@
+\name{put.orderbook}
+\alias{put.orderbook}
+\title{put an orderbook object in .strategy env}
+\usage{
+  put.orderbook(portfolio.st, orderbook, envir = .strategy)
+}
+\arguments{
+  \item{portfolio.st}{string identifying portfolio}
+
+  \item{orderbook}{orderbook object}
+
+  \item{envir}{the environment to store the orderbook
+  object in, defaults to .strategy}
+}
+\description{
+  put an orderbook object in .strategy env
+}
+\seealso{
+  getOrderBook
+}
+\concept{
+  order book
+}
+


Property changes on: pkg/quantstrat/man/put.orderbook.Rd
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: pkg/quantstrat/man/put.strategy.Rd
===================================================================
--- pkg/quantstrat/man/put.strategy.Rd	                        (rev 0)
+++ pkg/quantstrat/man/put.strategy.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -0,0 +1,20 @@
+\name{put.strategy}
+\alias{put.strategy}
+\title{put a strategy object in .strategy env}
+\usage{
+  put.strategy(strategy, envir = .strategy)
+}
+\arguments{
+  \item{strategy}{object; name will be extracted as
+  strategy$name}
+
+  \item{envir}{the environment to store the strategy in,
+  defaults to .strategy}
+}
+\description{
+  put a strategy object in .strategy env
+}
+\seealso{
+  getStrategy
+}
+


Property changes on: pkg/quantstrat/man/put.strategy.Rd
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: pkg/quantstrat/man/walk.forward.Rd
===================================================================
--- pkg/quantstrat/man/walk.forward.Rd	                        (rev 0)
+++ pkg/quantstrat/man/walk.forward.Rd	2013-03-19 12:31:54 UTC (rev 1409)
@@ -0,0 +1,98 @@
+\name{walk.forward}
+\alias{walk.forward}
+\title{Rolling Walk Forward Analysis}
+\usage{
+  walk.forward(strategy.st, paramset.label, portfolio.st,
+    account.st, period, k.training, nsamples = 0,
+    audit.prefix = NULL, k.testing,
+    obj.func = function(x) {     which(x == max(x)) },
+    obj.args = list(x = quote(tradeStats.list$Net.Trading.PL)),
+    include.insamples = TRUE, ..., verbose = FALSE)
+}
+\arguments{
+  \item{portfolio.st}{the name of the portfolio object}
+
+  \item{account.st}{the name of the account object}
+
+  \item{strategy.st}{the name of the strategy object}
+
+  \item{paramset.label}{a label uniquely identifying within
+  the strategy the paramset to be tested}
+
+  \item{period}{the period unit, as a character string, eg.
+  'days' or 'months'}
+
+  \item{k.training}{the number of periods to use for
+  training, eg. '3' months}
+
+  \item{nsamples}{the number of sample param.combos to draw
+  from the paramset for training; 0 means all samples (see
+  also apply.paramset)}
+
+  \item{audit.prefix}{prefix to generate filenames for
+  storage of audit data. For each training set, a separate
+  file is created, containing an enviroment called .audit,
+  with all in-sample portfolios and orderbooks as well as
+  information as to which param.combos were evaluated, and
+  the result of the objective function. In addition, a
+  special file is generated that contains portfolio and
+  orderbook for the concatenated testing param.combos as
+  selected by the objective function, plus (optionally)
+  complete in-sample portfolios and orderbooks for
+  reference (see include.insamples)}
+
+  \item{k.testing}{the number of periods to use for
+  testing, eg. '1 month'}
+
+  \item{obj.func}{a user provided function returning the
+  best param.combo from the paramset, based on training
+  results; defaults to 'max'}
+
+  \item{obj.args}{a user provided argument to obj.func,
+  defaults to quote(tradeStats.list$Net.Trading.PL)}
+
+  \item{include.insamples}{will optionally run a full
+  backtest for each param.combo in the paramset, and add
+  the resulting in-sample portfolios and orderbooks to the
+  file '<prefix>.results.RData'; default TRUE}
+
+  \item{...}{optional parameters to pass to
+  apply.paramset()}
+
+  \item{verbose}{dumps a lot of info during the run if set
+  to TRUE, defaults to FALSE}
+}
+\value{
+  a list consisting of a slot containing detailed results
+  for each training + testing period, as well as the
+  portfolio and the tradeStats() for the portfolio
+}
+\description{
+  A wrapper for apply.paramset() and applyStrategy(),
+  implementing a Rolling Walk Forward Analysis (WFA).
+}
+\details{
+  walk.forward executes a strategy on a portfolio, while
+  rolling a re-optimization of one of the strategies
+  parameter sets during a specified time period (training
+  window), then selecting an optimal parameter combination
+  from the parameter set using an obj function, then
+  applying the selected parameter combo to the next
+  out-of-sample time period immediately following the
+  training window (testing window). Once completed, the
+  training window is shifted forward by a time period equal
+  to the testing window size, and the process is repeated.
+  WFA stops when there are insufficient data left for a
+  full testing window.
+
+  For a complete description, see Jaekle&Tomasini chapter
+  6.
+}
+\author{
+  Jan Humme
+}
+\seealso{
+  \code{\link{applyStrategy}} \code{\link{apply.paramset}}
+  \code{\link{endpoints}} \code{\link{tradeStats}}
+}
+


Property changes on: pkg/quantstrat/man/walk.forward.Rd
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the Blotter-commits mailing list