[Returnanalytics-commits] r2509 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 6 15:04:21 CEST 2013
Author: rossbennett34
Date: 2013-07-06 15:04:21 +0200 (Sat, 06 Jul 2013)
New Revision: 2509
Modified:
pkg/PortfolioAnalytics/R/constraint_fn_map.R
Log:
modified rp_transform to stop execution and execute error action
Modified: pkg/PortfolioAnalytics/R/constraint_fn_map.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraint_fn_map.R 2013-07-06 05:55:12 UTC (rev 2508)
+++ pkg/PortfolioAnalytics/R/constraint_fn_map.R 2013-07-06 13:04:21 UTC (rev 2509)
@@ -366,19 +366,23 @@
colnames(portfolio)<-colnames(w)
# checks for infeasible portfolio
+ # Stop execution and return an error if an infeasible portfolio is created
+ # This will be useful in fn_map so that we can catch the error and take
+ # action (try again with more permutations, relax constraints, different
+ # method to normalize, etc.)
if (sum(portfolio)<=min_sum | sum(portfolio)>=max_sum){
portfolio <- w
- warning("Infeasible portfolio created, defaulting to w, perhaps increase max_permutations.")
+ stop("Infeasible portfolio created, perhaps increase max_permutations and/or adjust your parameters.")
}
- if(isTRUE(all.equal(w,portfolio))) {
- if (sum(w)>=min_sum & sum(w)<=max_sum) {
- warning("Unable to generate a feasible portfolio different from w, perhaps adjust your parameters.")
- return(w)
- } else {
- warning("Unable to generate a feasible portfolio, perhaps adjust your parameters.")
- return(NULL)
- }
- }
+# if(isTRUE(all.equal(w,portfolio))) {
+# if (sum(w)>=min_sum & sum(w)<=max_sum) {
+# warning("Unable to generate a feasible portfolio different from w, perhaps adjust your parameters.")
+# return(w)
+# } else {
+# warning("Unable to generate a feasible portfolio, perhaps adjust your parameters.")
+# return(NULL)
+# }
+# }
return(portfolio)
}
More information about the Returnanalytics-commits
mailing list