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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Sep 6 22:39:44 CEST 2014


Author: bodanker
Date: 2014-09-06 22:39:44 +0200 (Sat, 06 Sep 2014)
New Revision: 1630

Modified:
   pkg/quantstrat/R/paramsets.R
Log:
- Fix bug #5776; thanks to Doug Service for the report


Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R	2014-08-03 01:04:51 UTC (rev 1629)
+++ pkg/quantstrat/R/paramsets.R	2014-09-06 20:39:44 UTC (rev 1630)
@@ -145,19 +145,19 @@
 {
     nsamples <- min(nsamples, nrow(param.combos))
 
-    param.combos <- param.combos[sample(nrow(param.combos), size=nsamples),]
+    param.combos <- param.combos[sample(nrow(param.combos), size=nsamples),,drop=FALSE]
     
     if(NCOL(param.combos) == 1)
-        param.combos <- param.combos[order(param.combos)]
+        param.combos <- param.combos[order(param.combos),,drop=FALSE]
     else
         param.combos <- param.combos[with(param.combos,order(param.combos[,1],param.combos[,2])),]
 
-    data.frame(param.combos)
+    param.combos
 }
 
 install.param.combo <- function(strategy, param.combo, paramset.label)
 {
-    for(param.label in names(param.combo))
+    for(param.label in colnames(param.combo))
     {
         distribution <- strategy$paramsets[[paramset.label]]$distributions[[param.label]]
 
@@ -179,7 +179,7 @@
                 {
                     if(strategy[[components.type]][[index]]$label == component.label)
                     {
-                        strategy[[components.type]][[index]]$arguments[[variable.name]] <- param.combo[[param.label]]
+                        strategy[[components.type]][[index]]$arguments[[variable.name]] <- param.combo[,param.label]
 
                         found <- TRUE
                         break
@@ -394,6 +394,11 @@
     } else {
         param.combos <- paramsets
     }
+    # This is work-around for a buglet in iterators:::getIterVal.dataframeiter
+    # Convert param.combos to matrix if it's only one column, else the
+    # iterator will drop the data.frame dimensions, resulting in a vector
+    if(ncol(param.combos) == 1)
+        param.combos <- as.matrix(param.combos)
 
     env.functions <- c('clone.portfolio', 'clone.orderbook', 'install.param.combo')
     env.instrument <- as.list(FinancialInstrument:::.instrument)



More information about the Blotter-commits mailing list