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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 13 21:49:59 CET 2012


Author: opentrades
Date: 2012-11-13 21:49:59 +0100 (Tue, 13 Nov 2012)
New Revision: 1249

Modified:
   pkg/quantstrat/R/paramsets.R
Log:
- combine function now assigns slave portfolio objects to master .blotter enviroment
- moved updatePortf() and tradeStats() into combine function



Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R	2012-11-13 19:44:14 UTC (rev 1248)
+++ pkg/quantstrat/R/paramsets.R	2012-11-13 20:49:59 UTC (rev 1249)
@@ -379,16 +379,25 @@
         {
             result <- args[[i]]
 
+            full.portfolio.st <- paste('portfolio', result$portfolio.st, sep='.')
+            assign(full.portfolio.st, result$blotter[[full.portfolio.st]], envir=.blotter)
+
+            updatePortf(result$portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+            result$tradeStats <- tradeStats(result$portfolio.st)
+
+            results$tradeStats <- rbind(results$tradeStats, cbind(result$param.combo, result$tradeStats))
             results[[result$portfolio.st]] <- result
         }
         return(results)
     }
 
-    results <- foreach(param.combo=iter(param.combos,by='row'), .packages='quantstrat',
+    results <- foreach(param.combo=iter(param.combos,by='row'),
+        .verbose=verbose, .packages='quantstrat',
         .combine=combine, .multicombine=TRUE, .maxcombine=100,
         .export=c(env.functions, 'env.blotter', 'env.instrument', 'env.strategy', 'symbol.list', symbol.names)) %dopar%
     {
-        if(verbose) print(param.combo)
+        print(param.combo)
 
         # environment data accumulate with each transition through the foreach loop, so must be cleaned
         rm(list=ls(pos=.blotter), pos=.blotter)
@@ -414,26 +423,16 @@
 
         strategy <- install.param.combo(strategy, param.combo, paramset.label)
 
-        applyStrategy(strategy, portfolios=result$portfolio.st, verbose=TRUE)
-        updatePortf(result$portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''))
+        applyStrategy(strategy, portfolios=result$portfolio.st, verbose=verbose)
 
-        result$tradeStats <- tradeStats(result$portfolio.st)
+        result$blotter <- as.list(.blotter)
 
-        if(verbose) result$blotter <- as.list(.blotter)
-
         return(result)
     }
 
-    for(result in results)
-    {
-        results$tradeStats <- rbind(results$tradeStats, cbind(result$param.combo, result$tradeStats))
-    }
+    results$distributions <- distributions
+    results$constraints <- constraints
 
-    if(verbose)
-    {
-        results$distributions <- distributions
-        results$constraints <- constraints
-    }
     return(results)
 }
 



More information about the Blotter-commits mailing list