[Blotter-commits] r1344 - in pkg/quantstrat: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jan 5 00:44:55 CET 2013
Author: opentrades
Date: 2013-01-05 00:44:54 +0100 (Sat, 05 Jan 2013)
New Revision: 1344
Modified:
pkg/quantstrat/R/paramsets.R
pkg/quantstrat/R/walk.forward.R
pkg/quantstrat/man/apply.paramset.Rd
Log:
- renamed user.func and args.list parameters in apply.paramset() to user.func and user.args resp
- removed user.func and args.list parameters from walk.forward() and introduced ... instead, so user.func
and user.args can be optionally passed to apply.paramset() if applicable
- updated documentation for apply.paramset()
Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R 2013-01-04 18:38:44 UTC (rev 1343)
+++ pkg/quantstrat/R/paramsets.R 2013-01-04 23:44:54 UTC (rev 1344)
@@ -335,6 +335,8 @@
#' @param paramset.label a label uniquely identifying the paramset within the strategy
#' @param portfolio.st a string variable
#' @param nsamples if > 0 then take a sample of only size nsamples from the paramset
+#' @param user.func an optional user-supplied function to be run for each param.combo at the end, either on the slave or on the master (see calc)
+#' @param user.args user-supplied list of arguments for user.func
#' @param calc 'slave' to run updatePortfolio() and tradesStats() on the slave and return all portfolios and orderbooks as a list: higher parallelization but more data transfer between master and slave; 'master' to have updatePortf() and tradeStats() run at the master and return all portfolios and orderbooks in the .blotter and .strategy environments resp: less parallelization but also less data transfer between slave and master; default is 'master'
#' @param verbose return full information, in particular the .blotter environment, default FALSE
#'
@@ -342,7 +344,7 @@
#' @export
#' @seealso \code{\link{add.constraint}}, \code{\link{add.constraint}}, \code{\link{delete.paramset}}
-apply.paramset <- function(strategy.st, paramset.label, portfolio.st, account.st, mktdata, nsamples=0, user.func=NULL, args.list=NULL, calc='master', verbose=FALSE)
+apply.paramset <- function(strategy.st, paramset.label, portfolio.st, account.st, mktdata, nsamples=0, user.func=NULL, user.args=NULL, calc='master', verbose=FALSE)
{
require(foreach, quietly=TRUE)
require(iterators, quietly=TRUE)
@@ -399,8 +401,8 @@
updatePortf(r$portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''))
r$tradeStats <- tradeStats(r$portfolio.st)
- if(!is.null(user.func) && !is.null(args.list))
- r$user.func <- do.call(user.func, args.list)
+ if(!is.null(user.func) && !is.null(user.args))
+ r$user.func <- do.call(user.func, user.args)
}
results[[r$portfolio.st]] <- r
@@ -465,8 +467,8 @@
updatePortf(result$portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''))
result$tradeStats <- tradeStats(result$portfolio.st)
- if(!is.null(user.func) && !is.null(args.list))
- result$user.func <- do.call(user.func, args.list)
+ if(!is.null(user.func) && !is.null(user.args))
+ result$user.func <- do.call(user.func, user.args)
}
result$portfolio <- getPortfolio(result$portfolio.st)
result$order_book <- getOrderBook(result$portfolio.st)
Modified: pkg/quantstrat/R/walk.forward.R
===================================================================
--- pkg/quantstrat/R/walk.forward.R 2013-01-04 18:38:44 UTC (rev 1343)
+++ pkg/quantstrat/R/walk.forward.R 2013-01-04 23:44:54 UTC (rev 1344)
@@ -35,8 +35,8 @@
#' @param k.training the number of periods to use for training, eg. '3' months
#' @param nsamples the number of sample param.combos to draw from the paramset for training; 0 means all samples (see also apply.paramset)
#' @param k.testing the number of periods to use for testing, eg. '1 month'
-#' @param objective_func a user provided function returning the best param.combo from the paramset, based on training results; defaults to 'max'
-#' @param objective_arg a user provided argument to objective_func, defaults to quote(tradeStats.list$Net.Trading.PL)
+#' @param objective.func a user provided function returning the best param.combo from the paramset, based on training results; defaults to 'max'
+#' @param objective.arg a user provided argument to objective.func, defaults to quote(tradeStats.list$Net.Trading.PL)
#' @param verbose dumps a lot of info during the run if set to TRUE, defaults to FALSE
#'
#' @return 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
@@ -51,8 +51,8 @@
#' @export
walk.forward <- function(strategy.st, paramset.label, portfolio.st, account.st, period, k.training, nsamples=0, k.testing,
- objective_func=function(x){which(x==max(x))}, objective_args=list(x=quote(tradeStats.list$Net.Trading.PL)),
- user.func=NULL, args.list=NULL, verbose=FALSE)
+ objective.func=function(x){which(x==max(x))}, objective.args=list(x=quote(tradeStats.list$Net.Trading.PL)),
+ ..., verbose=FALSE)
{
must.have.args(match.call(), c('portfolio.st', 'strategy.st', 'paramset.label', 'k.training'))
@@ -103,7 +103,8 @@
# run backtests on training window
result$apply.paramset <- apply.paramset(strategy.st=strategy.st, paramset.label=paramset.label,
portfolio.st=portfolio.st, account.st=account.st, mktdata=symbol[training.timespan], nsamples=nsamples,
- calc='slave', user.func=user.func, args.list=args.list, verbose=verbose)
+ calc='slave', ...=..., verbose=verbose)
+ #calc='slave', user.func=user.func, args.list=args.list, verbose=verbose)
#calc='master', user.func=user.func, args.list=args.list, verbose=verbose)
#portfolio.st=portfolio.st, mktdata=symbol[training.timespan], nsamples=nsamples, calc='slave', verbose=verbose)
@@ -111,11 +112,11 @@
if(!missing(k.testing) && k.testing>0)
{
- if(!is.function(objective_func))
- stop(paste(objective_func, 'unknown objective function', sep=': '))
+ if(!is.function(objective.func))
+ stop(paste(objective.func, 'unknown objective function', sep=': '))
# select best param.combo
- param.combo.nr <- do.call(objective_func, objective_args)
+ param.combo.nr <- do.call(objective.func, objective.args)
param.combo <- tradeStats.list[param.combo.nr, 1:grep('Portfolio', names(tradeStats.list)) - 1]
# configure strategy to use selected param.combo
Modified: pkg/quantstrat/man/apply.paramset.Rd
===================================================================
--- pkg/quantstrat/man/apply.paramset.Rd 2013-01-04 18:38:44 UTC (rev 1343)
+++ pkg/quantstrat/man/apply.paramset.Rd 2013-01-04 23:44:54 UTC (rev 1344)
@@ -3,8 +3,8 @@
\title{Apply a paramset to the strategy}
\usage{
apply.paramset(strategy.st, paramset.label, portfolio.st,
- mktdata, nsamples = 0, calc = "master",
- verbose = FALSE)
+ account.st, mktdata, nsamples = 0, user.func = NULL,
+ user.args = NULL, calc = "master", verbose = FALSE)
}
\arguments{
\item{strategy}{the name of the strategy object}
@@ -17,6 +17,13 @@
\item{nsamples}{if > 0 then take a sample of only size
nsamples from the paramset}
+ \item{user.func}{an optional user-supplied function to be
+ run for each param.combo at the end, either on the slave
+ or on the master (see calc)}
+
+ \item{user.args}{user-supplied list of arguments for
+ user.func}
+
\item{calc}{'slave' to run updatePortfolio() and
tradesStats() on the slave and return all portfolios and
orderbooks as a list: higher parallelization but more
More information about the Blotter-commits
mailing list