[Blotter-commits] r1322 - in pkg/quantstrat: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Dec 27 02:19:22 CET 2012
Author: opentrades
Date: 2012-12-27 02:19:22 +0100 (Thu, 27 Dec 2012)
New Revision: 1322
Modified:
pkg/quantstrat/R/paramsets.R
pkg/quantstrat/R/walk.forward.R
pkg/quantstrat/man/apply.paramset.Rd
Log:
- changed name of 'mode' parameter in apply.paramset to 'calc' in order to avoid conflict with R mode func
- split objective in objective.func and objective.arg, with defaults 'max' and
'quote(tradeStats.list$Net.Trading.PL)' resp
- adjusted docs
Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R 2012-12-26 22:41:47 UTC (rev 1321)
+++ pkg/quantstrat/R/paramsets.R 2012-12-27 01:19:22 UTC (rev 1322)
@@ -335,14 +335,14 @@
#' @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 mode '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 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
#'
#' @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, mktdata, nsamples=0, mode='master', verbose=FALSE)
+apply.paramset <- function(strategy.st, paramset.label, portfolio.st, mktdata, nsamples=0, calc='master', verbose=FALSE)
{
require(foreach, quietly=TRUE)
require(iterators, quietly=TRUE)
@@ -381,7 +381,7 @@
{
r <- args[[i]]
- switch(mode,
+ switch(calc,
slave = {
# compute results on slave and return as list
@@ -457,7 +457,7 @@
strategy <- install.param.combo(strategy, param.combo, paramset.label)
applyStrategy(strategy, portfolios=result$portfolio.st, mktdata=mktdata, verbose=verbose)
- if(mode == 'slave')
+ if(calc == 'slave')
{
updatePortf(result$portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''))
result$tradeStats <- tradeStats(result$portfolio.st)
Modified: pkg/quantstrat/R/walk.forward.R
===================================================================
--- pkg/quantstrat/R/walk.forward.R 2012-12-26 22:41:47 UTC (rev 1321)
+++ pkg/quantstrat/R/walk.forward.R 2012-12-27 01:19:22 UTC (rev 1322)
@@ -15,13 +15,6 @@
#
###############################################################################
-max.Net.Trading.PL <- function(tradeStats.list)
-{
- which(max(tradeStats.list$Net.Trading.PL) == tradeStats.list$Net.Trading.PL)
-}
-
-### exported functions ############################################################
-
#' Rolling Walk Forward Analysis
#'
#' A wrapper for apply.paramset() and applyStrategy(), implementing a Rolling Walk Forward Analysis (WFA).
@@ -42,7 +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 a user provided function returning the best param.combo from the paramset, based on training results; a default function is provided that returns the number of the param.combo that brings the highest 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
@@ -56,7 +50,7 @@
#'
#' @export
-walk.forward <- function(portfolio.st, strategy.st, paramset.label, period, k.training, nsamples=0, k.testing, objective=max.Net.Trading.PL, verbose=FALSE)
+walk.forward <- function(portfolio.st, strategy.st, paramset.label, period, k.training, nsamples=0, k.testing, objective_func=max, objective_arg=quote(tradeStats.list$Net.Trading.PL), verbose=FALSE)
{
warning('walk.forward() is still under development! expect changes in arguments and results at any time JH')
@@ -108,17 +102,18 @@
# run backtests on training window
result$apply.paramset <- apply.paramset(strategy.st=strategy.st, paramset.label=paramset.label,
- portfolio.st=portfolio.st, mktdata=symbol[training.timespan], nsamples=nsamples, mode='slave', verbose=verbose)
+ portfolio.st=portfolio.st, mktdata=symbol[training.timespan], nsamples=nsamples, calc='slave', verbose=verbose)
tradeStats.list <- result$apply.paramset$tradeStats
if(!missing(k.testing) && k.testing>0)
{
- if(!is.function(objective))
- stop(paste(objective, '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, list('tradeStats.list'=tradeStats.list))
+ #param.combo.nr <- do.call(objective, list('tradeStats.list'=tradeStats.list))
+ param.combo.nr <- which(do.call(objective_func, list(objective_arg)) == eval(objective_arg))
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 2012-12-26 22:41:47 UTC (rev 1321)
+++ pkg/quantstrat/man/apply.paramset.Rd 2012-12-27 01:19:22 UTC (rev 1322)
@@ -3,7 +3,7 @@
\title{Apply a paramset to the strategy}
\usage{
apply.paramset(strategy.st, paramset.label, portfolio.st,
- mktdata, nsamples = 0, mode = "master",
+ mktdata, nsamples = 0, calc = "master",
verbose = FALSE)
}
\arguments{
@@ -17,7 +17,7 @@
\item{nsamples}{if > 0 then take a sample of only size
nsamples from the paramset}
- \item{mode}{'slave' to run updatePortfolio() and
+ \item{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
More information about the Blotter-commits
mailing list