[Returnanalytics-commits] r2915 - pkg/PortfolioAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 28 07:08:12 CEST 2013


Author: rossbennett34
Date: 2013-08-28 07:08:11 +0200 (Wed, 28 Aug 2013)
New Revision: 2915

Modified:
   pkg/PortfolioAnalytics/R/extract.efficient.frontier.R
Log:
Using foreach and dopar to create mean-var and mean-etl efficient frontiers.

Modified: pkg/PortfolioAnalytics/R/extract.efficient.frontier.R
===================================================================
--- pkg/PortfolioAnalytics/R/extract.efficient.frontier.R	2013-08-28 04:32:44 UTC (rev 2914)
+++ pkg/PortfolioAnalytics/R/extract.efficient.frontier.R	2013-08-28 05:08:11 UTC (rev 2915)
@@ -164,9 +164,14 @@
   
   out <- matrix(0, nrow=length(ret_seq), ncol=length(extractStats(tmp)))
   
-  for(i in 1:length(ret_seq)){
+#   for(i in 1:length(ret_seq)){
+#     portfolio$objectives[[mean_idx]]$target <- ret_seq[i]
+#     out[i, ] <- extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
+#   }
+  stopifnot("package:foreach" %in% search() || require("foreach",quietly = TRUE))
+  out <- foreach(i=1:length(ret_seq), .inorder=TRUE, .combine=rbind, .errorhandling='remove') %dopar% {
     portfolio$objectives[[mean_idx]]$target <- ret_seq[i]
-    out[i, ] <- extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
+    extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
   }
   colnames(out) <- names(stats)
   return(structure(out, class="efficient.frontier"))
@@ -243,9 +248,14 @@
   
   out <- matrix(0, nrow=length(ret_seq), ncol=length(extractStats(tmp)))
   
-  for(i in 1:length(ret_seq)){
+#   for(i in 1:length(ret_seq)){
+#     portfolio$objectives[[mean_idx]]$target <- ret_seq[i]
+#     out[i, ] <- extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
+#   }
+  stopifnot("package:foreach" %in% search() || require("foreach",quietly = TRUE))
+  out <- foreach(i=1:length(ret_seq), .inorder=TRUE, .combine=rbind, .errorhandling='remove') %dopar% {
     portfolio$objectives[[mean_idx]]$target <- ret_seq[i]
-    out[i, ] <- extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
+    extractStats(optimize.portfolio(R=R, portfolio=portfolio, optimize_method="ROI"))
   }
   colnames(out) <- names(stats)
   return(structure(out, class="efficient.frontier"))



More information about the Returnanalytics-commits mailing list