[Blotter-commits] r1338 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 3 20:54:03 CET 2013


Author: opentrades
Date: 2013-01-03 20:54:03 +0100 (Thu, 03 Jan 2013)
New Revision: 1338

Modified:
   pkg/quantstrat/R/paramsets.R
   pkg/quantstrat/R/walk.forward.R
Log:
modified walk.forward() to use parameter list for objective_args instead of just one parameter



Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R	2013-01-03 16:46:35 UTC (rev 1337)
+++ pkg/quantstrat/R/paramsets.R	2013-01-03 19:54:03 UTC (rev 1338)
@@ -86,7 +86,7 @@
 must.be.paramset <- function(strategy, paramset)
 {
     if(!(paramset %in% names(strategy$paramsets)))
-        stop(paste(paramset, ': not a paramset in strategy', strategy$name))
+        stop(paste(paramset, ': no such paramset in strategy', strategy$name))
 }
 
 create.paramset <- function(strategy, paramset.label)

Modified: pkg/quantstrat/R/walk.forward.R
===================================================================
--- pkg/quantstrat/R/walk.forward.R	2013-01-03 16:46:35 UTC (rev 1337)
+++ pkg/quantstrat/R/walk.forward.R	2013-01-03 19:54:03 UTC (rev 1338)
@@ -50,7 +50,7 @@
 #'
 #' @export
 
-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)
+walk.forward <- function(portfolio.st, strategy.st, paramset.label, 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)), verbose=FALSE)
 {
     must.have.args(match.call(), c('portfolio.st', 'strategy.st', 'paramset.label', 'k.training'))
 
@@ -100,7 +100,8 @@
 
             # 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, calc='slave', verbose=verbose)
+            #portfolio.st=portfolio.st, mktdata=symbol[training.timespan], nsamples=nsamples, calc='slave', verbose=verbose)
+            portfolio.st=portfolio.st, mktdata=symbol[training.timespan], nsamples=nsamples, calc='master', verbose=verbose)
 
             tradeStats.list <- result$apply.paramset$tradeStats
 
@@ -110,8 +111,7 @@
                     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 <- which(do.call(objective_func, list(objective_arg)) == eval(objective_arg))
+                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



More information about the Blotter-commits mailing list