[Blotter-commits] r1164 - in pkg/quantstrat: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Sep 6 22:21:09 CEST 2012
Author: opentrades
Date: 2012-09-06 22:21:08 +0200 (Thu, 06 Sep 2012)
New Revision: 1164
Modified:
pkg/quantstrat/R/orders.R
pkg/quantstrat/man/add.rule.Rd
pkg/quantstrat/man/addOrder.Rd
pkg/quantstrat/man/applyParameter.Rd
pkg/quantstrat/man/initStrategy.Rd
pkg/quantstrat/man/setParameterConstraint.Rd
pkg/quantstrat/man/setParameterDistribution.Rd
pkg/quantstrat/man/sigFormula.Rd
pkg/quantstrat/man/updateStrategy.Rd
Log:
update documentation on thresholds
Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/R/orders.R 2012-09-06 20:21:08 UTC (rev 1164)
@@ -139,25 +139,24 @@
#' or exit a position at a specific price.
#' Threshold multipliers have also been added for stoplimit. These allow a threshold to be set as a multiplier
#' of the current price. For example, to set a stoplimit order at the current price
-#' plus ten percent, you would set the threshold multiplier to 1.10. The threshold multiplier (or scalar) on a
-#' stoplimit order will be converted to a price at order entry.
-#' There is no functional different between a regular 'limit'
-#' order and a 'stoplimit' order once entered into the order book, but the distinction will likely
-#' be useful for reporting on when stops have been triggered.
+#' minus ten percent, you would set the threshold multiplier to -0.10. The threshold multiplier on a
+#' stoplimit order will be multiplied with the price and added to the prefered price upon order entry.
+#' There is no functional difference between a regular 'limit' order and a 'stoplimit' order once entered into
+#' the order book, but the distinction will likely be useful for reporting on when stops have been triggered.
#'
-#' We have also modeled a 'stoptrailing' order, which may be used to model dynamic limit-based entry or exit.
-#' If you set \code{tmult=TRUE} on a stoptrailing order, the size of the threshold will be set as a
-#' difference between the multiplier times the price and the current price at order entry. in this way, a 10%
-#' trailing entry (exit) will not change in size from the current price as the price changes. It is effectively
-#' converted to a scalar at order entry. While this functionality could change in the future,
-#' we believe this is more conservative than growing or shrinking the threshold distance from the current market price
-#' in relation to the threshold, and will result in fewer unintended consequences and more understandable behavior. Comments Welcome.
+#' We have also modeled a 'stoptrailing' order, which may be used to model dynamic limit-based exit.
+#' If you set \code{tmult=TRUE} on a stoptrailing order, the size of the threshold will be calculated upon
+#' order entry in the same way as for stoplimit orders; the resulting scalar will remain fixed for the life
+#' span of the order. In this way, a 10 pct trailing exit will not change in size from the current price as
+#' the price changes. While this functionality could change in the future, we believe this is more conservative
+#' than growing or shrinking the threshold distance from the current market price in relation to the threshold,
+#' and will result in fewer unintended consequences and more understandable behavior.
#'
-#' The 'stop*' or 'iceberg' order types are the only order type that makes use of the order \code{threshold}.
-#' Scalar thresholds \code{tmult=FALSE} on stoplimit or stoptrailing
-#' orders will be added to the current market price to set the limit price. In other worlds, a
-#' scalar threshold is the difference either positive or negative from the current price when
-#' the order is entered. With a stoptrailing order, the order may be moved (via cancel/replace) frequently.
+#' The 'limit', 'stoplimit', 'stoptrailing' and 'iceberg' order types are the only order types that make use
+#' of the order \code{threshold}. Scalar thresholds \code{tmult=FALSE} on stoplimit or stoptrailing orders
+#' will be added to the current market price to set the limit price. In other worlds, a scalar threshold
+#' is the difference either positive or negative from the current price when the order is entered. With a
+#' stoptrailing order, the order may be moved ("replaced") frequently.
#'
#' 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.
@@ -198,12 +197,12 @@
#' @param price numeric price at which the order is to be inserted
#' @param ordertype one of "market","limit","stoplimit", "stoptrailing",or "iceberg"
#' @param side one of either "long" or "short"
-#' @param threshold numeric threshold to apply to trailing stop orders and limit orders, default NULL
+#' @param threshold numeric threshold to apply to limit, stoplimit, stoptrailing and iceberg orders, default NULL
#' @param orderset set a tag identifying the orderset
#' @param status one of "open", "closed", "canceled", or "replaced", default "open"
#' @param statustimestamp timestamp of a status update, will be blank when order is initiated
#' @param delay what delay to add to timestamp when inserting the order into the order book, in seconds
-#' @param 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
+#' @param tmult if TRUE, threshold is a percent multiplier for \code{price}, not a scalar. Threshold is converted to a scalar by multiplying it with the price, then added to the price just like a scalar threshold.
#' @param replace TRUE/FALSE, whether to replace any other open order(s) on this symbol with the same properties as this order, default TRUE, see Details
#' @param return if TRUE, return the row that makes up the order, default FALSE (will assign into the environment)
#' @param \dots any other passthru parameters
Modified: pkg/quantstrat/man/add.rule.Rd
===================================================================
--- pkg/quantstrat/man/add.rule.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/add.rule.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -4,9 +4,10 @@
\usage{
add.rule(strategy, name, arguments, parameters = NULL,
label = NULL,
- type = c(NULL, "risk", "order", "rebalance", "exit", "enter"),
- ..., enabled = TRUE, indexnum = NULL, path.dep = TRUE,
- timespan = NULL, store = FALSE, storefun = TRUE)
+ type = c(NULL, "risk", "order", "rebalance", "exit", "enter", "chain"),
+ parent = NULL, ..., enabled = TRUE, indexnum = NULL,
+ path.dep = TRUE, timespan = NULL, store = FALSE,
+ storefun = TRUE)
}
\arguments{
\item{strategy}{an object of type 'strategy' to add the
@@ -25,7 +26,8 @@
default will be converted to '<name>.rule'}
\item{type}{one of
- "risk","order","rebalance","exit","enter", see Details}
+ "risk","order","rebalance","exit","enter","chain" see
+ Details}
\item{...}{any other passthru parameters}
@@ -75,12 +77,13 @@
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.
+ determine whether to enter or increase a position}
+ \item{chain}{ rules executed upon fill of the
+ corresponding order, identified by label } 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
Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/addOrder.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -29,8 +29,8 @@
\item{side}{one of either "long" or "short"}
- \item{threshold}{numeric threshold to apply to trailing
- stop orders and limit orders, default NULL}
+ \item{threshold}{numeric threshold to apply to limit,
+ stoplimit, stoptrailing and iceberg orders, default NULL}
\item{orderset}{set a tag identifying the orderset}
@@ -44,9 +44,9 @@
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}
+ for \code{price}, not a scalar. Threshold is converted to
+ a scalar by multiplying it with the price, then added to
+ the price just like a scalar threshold.}
\item{replace}{TRUE/FALSE, whether to replace any other
open order(s) on this symbol with the same properties as
@@ -98,38 +98,38 @@
also been added for stoplimit. These allow a threshold
to be set as a multiplier of the current price. For
example, to set a stoplimit order at the current price
- plus ten percent, you would set the threshold multiplier
- to 1.10. The threshold multiplier (or scalar) on a
- stoplimit order will be converted to a price at order
- entry. There is no functional different between a regular
- 'limit' order and a 'stoplimit' order once entered into
- the order book, but the distinction will likely be useful
- for reporting on when stops have been triggered.
+ minus ten percent, you would set the threshold multiplier
+ to -0.10. The threshold multiplier on a stoplimit order
+ will be multiplied with the price and added to the
+ prefered price upon order entry. There is no functional
+ difference between a regular 'limit' order and a
+ 'stoplimit' order once entered into the order book, but
+ the distinction will likely be useful for reporting on
+ when stops have been triggered.
We have also modeled a 'stoptrailing' order, which may be
- used to model dynamic limit-based entry or exit. If you
- set \code{tmult=TRUE} on a stoptrailing order, the size
- of the threshold will be set as a difference between the
- multiplier times the price and the current price at order
- entry. in this way, a 10% trailing entry (exit) will not
- change in size from the current price as the price
- changes. It is effectively converted to a scalar at
- order entry. While this functionality could change in
- the future, we believe this is more conservative than
- growing or shrinking the threshold distance from the
- current market price in relation to the threshold, and
- will result in fewer unintended consequences and more
- understandable behavior. Comments Welcome.
+ used to model dynamic limit-based exit. If you set
+ \code{tmult=TRUE} on a stoptrailing order, the size of
+ the threshold will be calculated upon order entry in the
+ same way as for stoplimit orders; the resulting scalar
+ will remain fixed for the life span of the order. In
+ this way, a 10 pct trailing exit will not change in size
+ from the current price as the price changes. While this
+ functionality could change in the future, we believe this
+ is more conservative than growing or shrinking the
+ threshold distance from the current market price in
+ relation to the threshold, and will result in fewer
+ unintended consequences and more understandable behavior.
- The 'stop*' or 'iceberg' order types are the only order
- type that makes use of the order \code{threshold}. Scalar
- thresholds \code{tmult=FALSE} on stoplimit or
- stoptrailing orders will be added to the current market
- price to set the limit price. In other worlds, a scalar
- threshold is the difference either positive or negative
- from the current price when the order is entered. With a
- stoptrailing order, the order may be moved (via
- cancel/replace) frequently.
+ The 'limit', 'stoplimit', 'stoptrailing' and 'iceberg'
+ order types are the only order types that make use of the
+ order \code{threshold}. Scalar thresholds
+ \code{tmult=FALSE} on stoplimit or stoptrailing orders
+ will be added to the current market price to set the
+ limit price. In other worlds, a scalar threshold is the
+ difference either positive or negative from the current
+ price when the order is entered. With a stoptrailing
+ order, the order may be moved ("replaced") frequently.
Some markets and brokers recognize a stop that triggers a
market order, when the stop is triggered, a market order
Modified: pkg/quantstrat/man/applyParameter.Rd
===================================================================
--- pkg/quantstrat/man/applyParameter.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/applyParameter.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -88,11 +88,11 @@
registerDoSMP(workers)
#PUT ALL CODE RELATED TO QUANTSTRAT HERE
- #Example to call the function: (For complete demo see parameterTestMACD.R)
- x<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,
+ #Example to call the function: (For complete demo see parameterTestMACD.R)
+ x<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,
method='random',sampleSize=20,parameterConstraints=pConstraint2)
- #or
- x<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,
+ #or
+ x<-applyParameter(strategy=stratMACD,portfolios=portfolio.st,parameterPool=tPD2,
method='expand',parameterConstraints=pConstraint2)
stopWorkers(workers)
Modified: pkg/quantstrat/man/initStrategy.Rd
===================================================================
--- pkg/quantstrat/man/initStrategy.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/initStrategy.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -3,9 +3,9 @@
\title{run standard and custom strategy initialization functions}
\usage{
initStrategy(strategy, portfolio, symbols,
- get.Symbols = TRUE, init.Portf = TRUE,
- init.Acct = TRUE, init.Orders = TRUE, unique = TRUE,
- ...)
+ parameters = NULL, get.Symbols = TRUE,
+ init.Portf = TRUE, init.Acct = TRUE,
+ init.Orders = TRUE, unique = TRUE, ...)
}
\arguments{
\item{strategy}{object of type \code{strategy} to
@@ -15,22 +15,44 @@
\item{symbols}{symbols}
- \item{get.Symbols}{TRUE/FALSE, default TRUE:}
+ \item{parameters}{named list of parameters to be applied
+ during evaluation of the strategy, default NULL}
- \item{init.Portf}{TRUE/FALSE, default TRUE:}
+ \item{get.Symbols}{TRUE/FALSE, default TRUE}
- \item{init.Acct}{TRUE/FALSE, default TRUE:}
+ \item{init.Portf}{TRUE/FALSE, default TRUE}
- \item{init.Orders}{TRUE/FALSE, default TRUE:}
+ \item{init.Acct}{TRUE/FALSE, default TRUE}
- \item{unique}{TRUE/FALSE, default TRUE:}
+ \item{init.Orders}{TRUE/FALSE, default TRUE}
- \item{\dots}{any other passtrhrough parameters}
+ \item{unique}{TRUE/FALSE, default TRUE}
+
+ \item{\dots}{any other passthrough parameters}
}
\description{
- run standard and custom strategy initialization functions
+ \code{initStrategy} will run a series of common
+ initialization functions at the beginning of an
+ \code{\link{applyStrategy}} call.
}
+\details{
+ \describe{ \item{get.Symbols}{if TRUE, will call
+ \code{\link[quantmod]{getSymbols}} on all symbols
+ included in the \code{symbols} vector}
+ \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{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,
+ account, or order book already exist} }
+}
\author{
Garrett See, Brian Peterson
}
+\seealso{
+ \code{\link{applyStrategy}}, \code{\link{add.init}},
+}
Modified: pkg/quantstrat/man/setParameterConstraint.Rd
===================================================================
--- pkg/quantstrat/man/setParameterConstraint.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/setParameterConstraint.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -41,7 +41,7 @@
#than slow macd signal:
\dontrun{
x<-setParameterConstraint(constraintLabel='macdPC',
- paramList=c('nFast','nSlow'),relationship='lt')
+ paramList=c('nFast','nSlow'),relationship='lt')
}
#The object x then can be used as one of the inputs to applyParameter function to specify the
#constraints between parameters.
Modified: pkg/quantstrat/man/setParameterDistribution.Rd
===================================================================
--- pkg/quantstrat/man/setParameterDistribution.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/setParameterDistribution.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -70,11 +70,11 @@
\dontrun{
#(For complete demo see parameterTestMACD.R)
tPD2<-setParameterDistribution(tPD2,'indicator',indexnum=1,
- distribution=list(nFast=(10:30)),label='nFast')
+ distribution=list(nFast=(10:30)),label='nFast')
tPD2<-setParameterDistribution(tPD2,'indicator',indexnum=1,
- distribution=list(nSlow=(20:40)),label='nSlow')
+ distribution=list(nSlow=(20:40)),label='nSlow')
tPD2<-setParameterDistribution(tPD2,'signal',indexnum=1,
- distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
+ distribution=list(relationship=c('gt','gte')),label='sig1.gtgte')
}
}
\author{
Modified: pkg/quantstrat/man/sigFormula.Rd
===================================================================
--- pkg/quantstrat/man/sigFormula.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/sigFormula.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -19,7 +19,7 @@
\description{
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
+ mktdata object in quantstrat) as an environment 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
Modified: pkg/quantstrat/man/updateStrategy.Rd
===================================================================
--- pkg/quantstrat/man/updateStrategy.Rd 2012-09-06 19:51:23 UTC (rev 1163)
+++ pkg/quantstrat/man/updateStrategy.Rd 2012-09-06 20:21:08 UTC (rev 1164)
@@ -2,12 +2,16 @@
\alias{updateStrategy}
\title{run standard and custom strategy wrapup functions such as updating portfolio, account, and ending equity}
\usage{
- updateStrategy(portfolio = "default",
- account = portfolio, Symbols = NULL, Dates = NULL,
- Prices = NULL, update.Portf = TRUE, update.Acct = TRUE,
- update.EndEq = TRUE, showEq = TRUE, chart = TRUE, ...)
+ updateStrategy(strategy, portfolio = "default",
+ account = portfolio, Symbols = NULL, parameters = NULL,
+ Dates = NULL, Prices = NULL, update.Portf = TRUE,
+ update.Acct = TRUE, update.EndEq = TRUE, showEq = TRUE,
+ chart = TRUE, ...)
}
\arguments{
+ \item{strategy}{object of type \code{strategy} to
+ initialize data/containers for}
+
\item{portfolio}{string identifying a portfolio}
\item{account}{string identifying an account. Same as
@@ -16,6 +20,9 @@
\item{Symbols}{character vector of names of symbols whose
portfolios will be updated}
+ \item{parameters}{named list of parameters to be applied
+ during evaluation of the strategy, default NULL}
+
\item{Dates}{optional xts-style ISO-8601 time range to
run updatePortf over, default NULL (will use times from
Prices)}
@@ -60,6 +67,16 @@
than tick. A custom wrapup function could take your high
frequency data and transform it to lower frequency data
before the call to \code{\link{updatePortf}}.
+
+ The 'standard wrapup functions included are: \describe{
+ \item{update.Portf}{ if TRUE, will call
+ \code{\link[blotter]{updatePortf}} to mark the book in
+ the portfolio. } \item{update.Acct}{ if TRUE, will call
+ \code{\link[blotter]{updateAcct}} to mark the blotter
+ account for this test. } \item{update.EndEq}{ if TRUE,
+ will call \code{\link[blotter]{updateEndEq}} to update
+ the account equity after all other accounting has been
+ completed. } }
}
\author{
Garrett See, Brian Peterson
More information about the Blotter-commits
mailing list