[Blotter-commits] r1371 - in pkg/quantstrat: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jan 20 22:59:33 CET 2013
Author: opentrades
Date: 2013-01-20 22:59:33 +0100 (Sun, 20 Jan 2013)
New Revision: 1371
Modified:
pkg/quantstrat/R/paramsets.R
pkg/quantstrat/R/utils.R
pkg/quantstrat/R/walk.forward.R
pkg/quantstrat/man/apply.paramset.Rd
Log:
- add must.be.environment() function
- modified apply.paramset() audit parameter, must now be NULL or specify an env to store info
- moved saving of env in a file from apply.paramset() to walk.forward()
Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R 2013-01-17 20:58:10 UTC (rev 1370)
+++ pkg/quantstrat/R/paramsets.R 2013-01-20 21:59:33 UTC (rev 1371)
@@ -349,20 +349,22 @@
#' @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 'slave'
-#' @param audit.st optional filename for storage of audit data
+#' @param audit a user-specified environment to store a copy of all portfolios, orderbooks and other data from the tests, or NULL to trash this information
#' @param verbose return full information, in particular the .blotter environment, default FALSE
#'
#' @author Jan Humme
#' @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, user.args=NULL, calc='slave', audit.st=NULL, verbose=FALSE)
+apply.paramset <- function(strategy.st, paramset.label, portfolio.st, account.st, mktdata, nsamples=0, user.func=NULL, user.args=NULL, calc='slave', audit=NULL, verbose=FALSE)
{
must.have.args(match.call(), c('strategy.st', 'paramset.label', 'portfolio.st'))
strategy <- must.be.strategy(strategy.st)
must.be.paramset(strategy, paramset.label)
+ if(!is.null(audit)) must.be.environment(audit)
+
portfolio <- getPortfolio(portfolio.st)
account <- getAccount(account.st)
orderbook <- getOrderBook(portfolio.st)
@@ -378,7 +380,10 @@
env.functions <- c('clone.portfolio', 'clone.orderbook', 'install.param.combo')
env.instrument <- as.list(FinancialInstrument:::.instrument)
- .audit <- new.env()
+ if(is.null(audit))
+ .audit <- new.env()
+ else
+ .audit <- audit
combine <- function(...)
{
@@ -474,8 +479,8 @@
results$distributions <- distributions
results$constraints <- constraints
- if(!is.null(audit.st))
- save(.audit, file=paste(audit.st, 'RData', sep='.'))
+ if(is.null(audit))
+ .audit <- NULL
return(results)
}
Modified: pkg/quantstrat/R/utils.R
===================================================================
--- pkg/quantstrat/R/utils.R 2013-01-17 20:58:10 UTC (rev 1370)
+++ pkg/quantstrat/R/utils.R 2013-01-20 21:59:33 UTC (rev 1371)
@@ -23,6 +23,12 @@
}
}
+must.be.environment <- function(e)
+{
+ if(!is.environment(e))
+ stop(paste(e, ': not an environment', sep=''))
+}
+
must.be.strategy <- function(strategy)
{
if(!is.strategy(strategy))
Modified: pkg/quantstrat/R/walk.forward.R
===================================================================
--- pkg/quantstrat/R/walk.forward.R 2013-01-17 20:58:10 UTC (rev 1370)
+++ pkg/quantstrat/R/walk.forward.R 2013-01-20 21:59:33 UTC (rev 1371)
@@ -101,15 +101,23 @@
print(paste('=== training', paramset.label, 'on', training.timespan))
+ audit.env <- NULL
if(!is.null(audit.prefix))
- audit.st <- paste(audit.prefix, index(symbol[training.start]), index(symbol[training.end]), sep='.')
+ audit.env <- new.env()
# 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', audit.st=audit.st, verbose=verbose, ...=...)
+ calc='slave', audit=audit.env, verbose=verbose, ...=...)
+ if(!is.null(audit.prefix))
+ {
+ save(audit.env, file=paste(audit.prefix, index(symbol[training.start]), index(symbol[training.end]), 'RData', sep='.'))
+
+ audit.env <- NULL
+ }
+
tradeStats.list <- result$apply.paramset$tradeStats
if(!missing(k.testing) && k.testing>0)
Modified: pkg/quantstrat/man/apply.paramset.Rd
===================================================================
--- pkg/quantstrat/man/apply.paramset.Rd 2013-01-17 20:58:10 UTC (rev 1370)
+++ pkg/quantstrat/man/apply.paramset.Rd 2013-01-20 21:59:33 UTC (rev 1371)
@@ -4,7 +4,7 @@
\usage{
apply.paramset(strategy.st, paramset.label, portfolio.st,
account.st, mktdata, nsamples = 0, user.func = NULL,
- user.args = NULL, calc = "slave", audit.st = NULL,
+ user.args = NULL, calc = "slave", audit = NULL,
verbose = FALSE)
}
\arguments{
@@ -40,8 +40,9 @@
also less data transfer between slave and master; default
is 'slave'}
- \item{audit.st}{optional filename for storage of audit
- data}
+ \item{audit}{a user-specified environment to store a copy
+ of all portfolios, orderbooks and other data from the
+ tests, or NULL to trash this information}
\item{verbose}{return full information, in particular the
.blotter environment, default FALSE}
More information about the Blotter-commits
mailing list