[Blotter-commits] r774 - in pkg/quantstrat: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 12 19:08:41 CEST 2011
Author: gsee
Date: 2011-09-12 19:08:40 +0200 (Mon, 12 Sep 2011)
New Revision: 774
Modified:
pkg/quantstrat/DESCRIPTION
pkg/quantstrat/R/indicators.R
pkg/quantstrat/R/rules.R
pkg/quantstrat/R/signals.R
pkg/quantstrat/man/add.indicator.Rd
pkg/quantstrat/man/add.rule.Rd
pkg/quantstrat/man/add.signal.Rd
pkg/quantstrat/man/getParameterTable.Rd
Log:
- if add.signal, add.rule, add.indicator is given the name of a strategy,
it will getStrategy, update and store it and return the name.
If given a strategy, it will still return the updated strategy object.
- roxygenize all except applyParameters.Rd
Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/DESCRIPTION 2011-09-12 17:08:40 UTC (rev 774)
@@ -1,7 +1,7 @@
Package: quantstrat
Type: Package
Title: Quantitative Strategy Model Framework
-Version: 0.5.3
+Version: 0.5.4
Date: $Date$
Author: Peter Carl, Dirk Eddelbuettel, Brian G. Peterson,
Jeffrey A. Ryan, Joshua Ulrich, Garrett See, Yu Chen
Modified: pkg/quantstrat/R/indicators.R
===================================================================
--- pkg/quantstrat/R/indicators.R 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/R/indicators.R 2011-09-12 17:08:40 UTC (rev 774)
@@ -37,7 +37,7 @@
#' \code{\link{paste}}'d to either the returned column names or the
#' respective column number.
#'
-#' @param strategy an object of type 'strategy' to add the indicator to
+#' @param strategy an object (or the name of an object) 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 parameters vector of strings naming parameters to be saved for apply-time definition,default NULL, only needed if you need special names to avoid argument collision
@@ -46,6 +46,7 @@
#' @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
#' @param store TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE
+#' @return if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy.
#' @seealso
#' \code{\link{quote}}
#' \code{\link{applyIndicators}}
@@ -54,7 +55,12 @@
#'
#' @export
add.indicator <- function(strategy, name, arguments, parameters=NULL, label=NULL, ..., enabled=TRUE, indexnum=NULL, store=FALSE) {
- if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
+ if (!is.strategy(strategy)) {
+ strategy<-try(getStrategy(strategy))
+ if(inherits(strategy,"try-error"))
+ stop ("You must supply an object or the name of an object of type 'strategy'.")
+ store=TRUE
+ }
tmp_indicator<-list()
tmp_indicator$name<-name
if(is.null(label)) label = paste(name,"ind",sep='.')
@@ -73,6 +79,7 @@
if (store) assign(strategy$name,strategy,envir=as.environment(.strategy))
else return(strategy)
+ strategy$name
}
#' apply the indicators in the strategy to arbitrary market data
Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/R/rules.R 2011-09-12 17:08:40 UTC (rev 774)
@@ -68,9 +68,15 @@
#' @param path.dep TRUE/FALSE whether rule is path dependent, default TRUE, see Details
#' @param timespan an xts/ISO-8601 style \emph{time} subset, like "T08:00/T15:00", see Details
#' @param store TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE
+#' @return if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy.
#' @export
add.rule <- function(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) {
- if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
+ if (!is.strategy(strategy)) {
+ strategy<-try(getStrategy(strategy))
+ if(inherits(strategy,"try-error"))
+ stop ("You must supply an object or the name of an object of type 'strategy'.")
+ store=TRUE
+ }
type=type[1]
if(is.null(type)) stop("You must specify a type")
if(is.na(charmatch(type,c("risk","order","rebalance","exit","enter","pre","post")))) stop(paste("type:",type,' must be one of "risk", "order", "rebalance", "exit", "enter", "pre", or "post"'))
@@ -108,6 +114,7 @@
if (store) assign(strategy$name,strategy,envir=as.environment(.strategy))
else return(strategy)
+ strategy$name
}
#' apply the rules in the strategy to arbitrary market data
Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/R/signals.R 2011-09-12 17:08:40 UTC (rev 774)
@@ -14,7 +14,7 @@
#' \code{\link{paste}}'d to either the returned column names or the
#' respective column number.
#'
-#' @param strategy an object of type 'strategy' to add the signal to
+#' @param strategy an object (or the name of an object) of type 'strategy' to add the signal to
#' @param name name of the signal, must correspond to an R function
#' @param arguments named list of default arguments to be passed to an signal function when executed
#' @param parameters vector of strings naming parameters to be saved for apply-time definition,default NULL, only needed if you need special names to avoid argument collision
@@ -23,6 +23,7 @@
#' @param enabled TRUE/FALSE whether the signal is enabled for use in applying the strategy, default TRUE
#' @param indexnum if you are updating a specific signal, the index number in the $signals list to update
#' @param store TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE
+#' @return if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy.
#' @seealso
#' \code{\link{applySignals}}
#' \code{\link{add.indicator}}
@@ -35,7 +36,12 @@
#'
#' @export
add.signal <- function(strategy, name, arguments, parameters=NULL, label=NULL, ..., enabled=TRUE, indexnum=NULL, store=FALSE) {
- if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
+ if (!is.strategy(strategy)) {
+ strategy<-try(getStrategy(strategy))
+ if(inherits(strategy,"try-error"))
+ stop ("You must supply an object or the name of an object of type 'strategy'.")
+ store=TRUE
+ }
tmp_signal<-list()
tmp_signal$name<-name
if(is.null(label)) label = paste(name,"sig",sep='.')
@@ -54,6 +60,7 @@
if (store) assign(strategy$name,strategy,envir=as.environment(.strategy))
else return(strategy)
+ strategy$name
}
#' apply the signals in the strategy to arbitrary market data
Modified: pkg/quantstrat/man/add.indicator.Rd
===================================================================
--- pkg/quantstrat/man/add.indicator.Rd 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/man/add.indicator.Rd 2011-09-12 17:08:40 UTC (rev 774)
@@ -7,8 +7,8 @@
store = FALSE)
}
\arguments{
- \item{strategy}{an object of type 'strategy' to add the
- indicator to}
+ \item{strategy}{an object (or the name of an object) type
+ 'strategy' to add the indicator to}
\item{name}{name of the indicator, must correspond to an
R function}
@@ -35,6 +35,10 @@
\item{store}{TRUE/FALSE whether to store the strategy in
the .strategy environment, or return it. default FALSE}
}
+\value{
+ if \code{strategy} was the name of a strategy, the name.
+ It it was a strategy, the updated strategy.
+}
\description{
Indicators are typically standard technical or
statistical analysis outputs, such as moving averages,
Modified: pkg/quantstrat/man/add.rule.Rd
===================================================================
--- pkg/quantstrat/man/add.rule.Rd 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/man/add.rule.Rd 2011-09-12 17:08:40 UTC (rev 774)
@@ -44,6 +44,10 @@
\item{store}{TRUE/FALSE whether to store the strategy in
the .strategy environment, or return it. default FALSE}
}
+\value{
+ if \code{strategy} was the name of a strategy, the name.
+ It it was a strategy, the updated strategy.
+}
\description{
Rules will be processed in a very particular manner, so
it bears going over.
Modified: pkg/quantstrat/man/add.signal.Rd
===================================================================
--- pkg/quantstrat/man/add.signal.Rd 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/man/add.signal.Rd 2011-09-12 17:08:40 UTC (rev 774)
@@ -7,8 +7,8 @@
= FALSE)
}
\arguments{
- \item{strategy}{an object of type 'strategy' to add the
- signal to}
+ \item{strategy}{an object (or the name of an object) of
+ type 'strategy' to add the signal to}
\item{name}{name of the signal, must correspond to an R
function}
@@ -35,6 +35,10 @@
\item{store}{TRUE/FALSE whether to store the strategy in
the .strategy environment, or return it. default FALSE}
}
+\value{
+ if \code{strategy} was the name of a strategy, the name.
+ It it was a strategy, the updated strategy.
+}
\description{
This adds a signal definition to a strategy object.
}
Modified: pkg/quantstrat/man/getParameterTable.Rd
===================================================================
--- pkg/quantstrat/man/getParameterTable.Rd 2011-09-12 16:53:03 UTC (rev 773)
+++ pkg/quantstrat/man/getParameterTable.Rd 2011-09-12 17:08:40 UTC (rev 774)
@@ -9,7 +9,7 @@
}
\value{
A list of objects that contains the parameter structure
- information" \describe{ \item{paramNameList}{the list of
+ information \describe{ \item{paramNameList}{the list of
parameters used in the strategy, for printing or viewing
as a table.} \item{strategyName}{ string name of the
strategy} \item{structure}{the detailed paramter
@@ -19,14 +19,14 @@
}
\description{
Users can use this function to extract the parameters
- used in a strategy, and as a reminder/ cheatsheet when
- they create the parameter distribution. But it's not
- required to be used to specify the distribution of
- parameters.
+ used in a strategy, and use the output as a reminder/
+ cheatsheet when they create the parameter distribution or
+ parameter constraints. But it's not required to run to
+ specify the distribution or constraints of parameters.
}
\examples{
-# When strategy object stratMACD has already been created by macd.R demo:
-# bfollowing line will return the parameter information to object paramStructure:
+# When strategy object stratMACD has already been created by demo macd.R:
+# following line will return object x that contains the parameter information.
\dontrun{
x<-getParameterTable(stratMACD)
}
More information about the Blotter-commits
mailing list