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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 22 01:42:17 CET 2013


Author: opentrades
Date: 2013-01-22 01:42:17 +0100 (Tue, 22 Jan 2013)
New Revision: 1378

Modified:
   pkg/quantstrat/R/paramsets.R
   pkg/quantstrat/R/walk.forward.R
Log:
- some improvements in storing selected param.combo in .audit environment



Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R	2013-01-22 00:17:25 UTC (rev 1377)
+++ pkg/quantstrat/R/paramsets.R	2013-01-22 00:42:17 UTC (rev 1378)
@@ -487,7 +487,6 @@
         assign('constraints', constraints, envir=.audit)
         assign('paramset.label', paramset.label, envir=.audit)
         assign('param.combos', param.combos, envir=.audit)
-        assign('param.combos', param.combos, envir=.audit)
         assign('tradeStats', results$tradeStats, envir=.audit)
         assign('user.func', results$user.func, envir=.audit)
     }

Modified: pkg/quantstrat/R/walk.forward.R
===================================================================
--- pkg/quantstrat/R/walk.forward.R	2013-01-22 00:17:25 UTC (rev 1377)
+++ pkg/quantstrat/R/walk.forward.R	2013-01-22 00:42:17 UTC (rev 1378)
@@ -120,20 +120,28 @@
                     stop(paste(obj.func, 'unknown obj function', sep=': '))
 
                 # select best param.combo
-                param.combo.nr <- do.call(obj.func, obj.args)
-                param.combo <- tradeStats.list[param.combo.nr, 1:grep('Portfolio', names(tradeStats.list)) - 1]
+                param.combo.idx <- do.call(obj.func, obj.args)
+                if(length(param.combo.idx) == 0)
+                    stop('obj.func() returned empty result')
 
-                assign('obj.func', obj.func, envir=.audit)
-                assign('param.combo.nr', param.combo.nr, envir=.audit)
-                assign('param.combo', param.combo, envir=.audit)
+                param.combo <- tradeStats.list[param.combo.idx, 1:grep('Portfolio', names(tradeStats.list)) - 1]
+                param.combo.nr <- row.names(tradeStats.list)[param.combo.idx]
 
+                if(!is.null(.audit))
+                {
+                    assign('obj.func', obj.func, envir=.audit)
+                    assign('param.combo.idx', param.combo.idx, envir=.audit)
+                    assign('param.combo.nr', param.combo.nr, envir=.audit)
+                    assign('param.combo', param.combo, envir=.audit)
+                }
+
                 # configure strategy to use selected param.combo
                 strategy <- quantstrat:::install.param.combo(strategy, param.combo, paramset.label)
 
                 result$testing.timespan <- testing.timespan
-                result$param.combo.nr <- param.combo.nr
-                result$param.combo <- param.combo
-                result$strategy <- strategy
+#                result$param.combo.idx <- param.combo.idx
+#                result$param.combo <- param.combo
+#                result$strategy <- strategy
 
                 print(paste('=== testing param.combo', param.combo.nr, 'on', testing.timespan))
                 print(param.combo)
@@ -149,7 +157,7 @@
                 k <- k + 1
             }
 
-            if(!is.null(audit.prefix))
+            if(!is.null(.audit))
             {
                 save(.audit, file=paste(audit.prefix, index(symbol[training.start]), index(symbol[training.end]), 'RData', sep='.'))
 



More information about the Blotter-commits mailing list