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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Sep 18 23:04:56 CEST 2010


Author: braverock
Date: 2010-09-18 23:04:55 +0200 (Sat, 18 Sep 2010)
New Revision: 396

Modified:
   pkg/quantstrat/R/indicators.R
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/signals.R
   pkg/quantstrat/man/add.indicator.Rd
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/ruleSignal.Rd
   pkg/quantstrat/man/sigFormula.Rd
Log:
- update documentation

Modified: pkg/quantstrat/R/indicators.R
===================================================================
--- pkg/quantstrat/R/indicators.R	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/R/indicators.R	2010-09-18 21:04:55 UTC (rev 396)
@@ -9,7 +9,7 @@
 #' Indicators are applied before signals and rules, and the output of indicators 
 #' may be used as inputs to construct signals or fire rules.
 #'
-#' \code{arguments} and \code{parameters} are named lists that describe the arguments to be passed to nthe indicator function.
+#' \code{arguments} and \code{parameters} are named lists that describe the arguments to be passed to the indicator function.
 #' \code{arguments} is for defining any non-default arguments to be passed to the function named in the \code{name} of the indicator.  
 #' For example, the \code{x} argument to a moving average function may be defined as \code{x=quote(Cl(mktdata))}
 #' 

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/R/orders.R	2010-09-18 21:04:55 UTC (rev 396)
@@ -374,6 +374,7 @@
                     txnprice=NULL
                     txntime=as.character(index(ordersubset[ii,]))
                     txnfees=ordersubset[ii, ]$Txn.Fees
+					if(is.null(txnfees)) txnfees=0
                     switch(ordersubset[ii,]$Order.Type,
                         market = {
                                 txnprice=as.numeric(getPrice(mktdata[txntime], prefer='close'))
@@ -494,7 +495,7 @@
                                                  threshold=ordersubset[ii,]$Order.Threshold,
                                                  status="open",
                                                  replace=FALSE, return=TRUE,
-                                                 ,...=..., TxnFees=ordersubset[ii,]$TxnFees)
+                                                 ,...=..., TxnFees=ordersubset[ii,]$Txn.Fees)
 										if (is.null(neworders)) neworders=neworder else neworders = rbind(neworders,neworder)
                                         ordersubset[ii,]$Order.Status<-'replaced'
                                         ordersubset[ii,]$Order.StatusTime<-as.character(timestamp)

Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/R/signals.R	2010-09-18 21:04:55 UTC (rev 396)
@@ -157,17 +157,17 @@
         colNums <- match.names(columns,colnames(data))
 
 		opr <- switch( relationship,
-					 gt = , '>'='>', 
-					 lt =, '<'='<', 
-					 eq =, "=="=, "=" = "==",
-					 gte=, gteq=, ge=, ">=" = ">=",
-					 lte=, lteq=, le=, "<=" = "<="
-					)
+					   	gt = , '>' = '>', 
+					 	lt =, '<' = '<', 
+					 	eq =, "==" =, "=" = "==",
+					 	gte =, gteq =, ge =, ">=" = ">=",
+					 	lte =, lteq =, le =, "<=" = "<="
+					 )
 
 		ret_sig <- do.call( opr, list(data[,colNums[1]], data[,colNums[2]]))
 
     } else {
-        stop("comparison of more than two columns not supported yet, patches welcome")
+        stop("comparison of more than two columns not supported, see sigFormula")
     }
     colnames(ret_sig)<-label
     return(ret_sig)
@@ -257,6 +257,13 @@
 }
 
 #' generate a signal from a formula
+#' 
+#' This code takes advantage of some base R functionality that can treat an R object (in this case the internal mktdata object in quantstrat) as an enfironment or 'frame' using \code{\link{parent.frame}}.  
+#' This allows the columns of the data to be addressed without any major manipulation, simply by column name.  In most cases in quantstrat, this will be either the price/return columns, or columns added by indicators or prior signals.
+#' The formula will return TRUE/FALSE for each row comparison as a time series column which can then be used for rule execution.  The \code{formula} will be evaluated using \code{\link{eval}} as though in an if statement. 
+#' 
+#' This code is adapted from the approach used by Vijay Vaidyanthan in his PAST/AAII/SIPRO code to construct arbitrary, formulaic, comparisons.  Many thanks to Vijay for sharing his expertise.
+#'  
 #' @param label text label to apply to the output
 #' @param data data to apply formula to
 #' @param formula a logical expression like that used in an if statement, will typically reference column names in \code{mktdata}

Modified: pkg/quantstrat/man/add.indicator.Rd
===================================================================
--- pkg/quantstrat/man/add.indicator.Rd	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/man/add.indicator.Rd	2010-09-18 21:04:55 UTC (rev 396)
@@ -12,7 +12,7 @@
 Indicators are applied before signals and rules, and the output of indicators 
 may be used as inputs to construct signals or fire rules.
 
-\code{arguments} and \code{parameters} are named lists that describe the arguments to be passed to nthe indicator function.
+\code{arguments} and \code{parameters} are named lists that describe the arguments to be passed to the indicator function.
 \code{arguments} is for defining any non-default arguments to be passed to the function named in the \code{name} of the indicator.  
 For example, the \code{x} argument to a moving average function may be defined as \code{x=quote(Cl(mktdata))}
 

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/man/addOrder.Rd	2010-09-18 21:04:55 UTC (rev 396)
@@ -3,7 +3,7 @@
 \title{add an order to the order book...}
 \usage{addOrder(portfolio, symbol, timestamp, qty, price, ordertype, side,
     threshold, status="open", statustimestamp="", delay=1e-05,
-    tmult=FALSE, replace=TRUE, return=FALSE)}
+    tmult=FALSE, replace=TRUE, return=FALSE, ..., TxnFees=0)}
 \description{add an order to the order book}
 \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.
@@ -79,4 +79,6 @@
 \item{delay}{what delay to add to timestamp when inserting the order into the order book, in seconds}
 \item{tmult}{if TRUE, threshold is a percent multiplier for \code{price}, not a scalar to be added/subtracted from price.  threshold will be dynamically converted to a scalar at time of order entry}
 \item{replace}{TRUE/FALSE, whether to replace any other open order(s) on this portfolio symbol, default TRUE}
-\item{return}{if TRUE, return the row that makes up the order, default FALSE (will assign into the environment)}}
+\item{return}{if TRUE, return the row that makes up the order, default FALSE (will assign into the environment)}
+\item{dots}{any other passthru parameters}
+\item{TxnFees}{numeric fees (usually negative) or function name for calculating TxnFees (processing happens later, not in this function)}}

Modified: pkg/quantstrat/man/ruleSignal.Rd
===================================================================
--- pkg/quantstrat/man/ruleSignal.Rd	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/man/ruleSignal.Rd	2010-09-18 21:04:55 UTC (rev 396)
@@ -3,18 +3,22 @@
 \title{default rule to generate a trade order on a signal...}
 \usage{ruleSignal(data=mktdata, timestamp, sigcol, sigval, orderqty=0,
     ordertype, orderside, threshold, replace=TRUE, delay=1e-04,
-    osFUN="osNoOp", pricemethod=c("market", "opside"), portfolio,
-    symbol, ..., ruletype)}
+    osFUN="osNoOp", pricemethod=c("market", "opside", "maker"),
+    portfolio, symbol, ..., ruletype, TxnFees=0)}
 \description{default rule to generate a trade order on a signal}
-\details{\code{pricemethod} may be one of 'market' or 'opside' 
+\details{\code{pricemethod} may be one of 'market', 'opside', or 'maker' 
 which will either try to get the price of the 'market' at \code{timestamp} and use this as the order price
-or 'opside' which will use the 'ask' price if you're buying and the 'bid' price if you're selling
+or 'opside' which will use the 'ask' price if you're buying and the 'bid' price if you're selling, crossing 
+the market at the time of order entry to attempt to set an aggressive price to get the trade.  
+The 'maker' \code{pricemethod} will create a pair of orders for both bid and offer, modeling market making 
+activities by having orders on both sides.  This will then create an Order.Set, and use the threshold to
+set the prices for these orders.
 
 If \code{threshold} is not numeric or \code{NULL} it should be the character string describing a function that can calculate a threshold.  
 Ideally this will be a column lookup on a non-path-dependent indicator calculated in advance.
 
 If \code{orderside} is NULL, the function will attempt to calculate the side from the current position 
-(if any) and the order quantity.}
+(if any), the order quantity, and the order type.}
 \seealso{\code{\link{osNoOp}} , \code{\link{add.rule}}}
 \arguments{\item{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}
 \item{timestamp}{timestamp coercible to POSIXct that will be the time the order will be inserted on}
@@ -27,7 +31,7 @@
 \item{replace}{TRUE/FALSE, whether to replace any other open order(s) on this portfolio symbol, default TRUE}
 \item{delay}{what delay to add to timestamp when inserting the order into the order book, in seconds}
 \item{osFUN}{function or text descriptor of function to use for order sizing, default \code{\link{osNoOp}}}
-\item{pricemethod}{one of 'market' or 'opside', see Details}
+\item{pricemethod}{one of 'market', 'opside', or 'maker', see Details}
 \item{portfolio}{text name of the portfolio to place orders in}
 \item{symbol}{identifier of the instrument to place orders for.  The name of any associated price objects (xts prices, usually OHLC) should match these}
 \item{...}{any other passthru parameters}

Modified: pkg/quantstrat/man/sigFormula.Rd
===================================================================
--- pkg/quantstrat/man/sigFormula.Rd	2010-09-18 20:11:22 UTC (rev 395)
+++ pkg/quantstrat/man/sigFormula.Rd	2010-09-18 21:04:55 UTC (rev 396)
@@ -3,6 +3,11 @@
 \title{generate a signal from a formula...}
 \usage{sigFormula(label, data=mktdata, formula, cross=FALSE)}
 \description{generate a signal from a formula}
+\details{This code takes advantage of some base R functionality that can treat an R object (in this case the internal mktdata object in quantstrat) as an enfironment or 'frame' using \code{\link{parent.frame}}.  
+This allows the columns of the data to be addressed without any major manipulation, simply by column name.  In most cases in quantstrat, this will be either the price/return columns, or columns added by indicators or prior signals.
+The formula will return TRUE/FALSE for each row comparison as a time series column which can then be used for rule execution.  The \code{formula} will be evaluated using \code{\link{eval}} as though in an if statement. 
+
+This code is adapted from the approach used by Vijay Vaidyanthan in his PAST/AAII/SIPRO code to construct arbitrary, formulaic, comparisons.  Many thanks to Vijay for sharing his expertise.}
 \arguments{\item{label}{text label to apply to the output}
 \item{data}{data to apply formula to}
 \item{formula}{a logical expression like that used in an if statement, will typically reference column names in \code{mktdata}}



More information about the Blotter-commits mailing list