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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 10 17:34:35 CEST 2013


Author: rossbennett34
Date: 2013-09-10 17:34:34 +0200 (Tue, 10 Sep 2013)
New Revision: 3042

Modified:
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
Log:
Adding code to optimize.portfolio for proportional transaction cost constraints.

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-09-10 14:51:46 UTC (rev 3041)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2013-09-10 15:34:34 UTC (rev 3042)
@@ -733,11 +733,23 @@
     if("var" %in% names(moments)){
       # Minimize variance if the only objective specified is variance
       # Maximize Quadratic Utility if var and mean are specified as objectives
-      if(!is.null(constraints$turnover_target)){
-        qp_result <- gmv_opt_toc(R=R, constraints=constraints, moments=moments, lambda=lambda, target=target, init_weights=portfolio$assets)
-        weights <- qp_result$weights
-        obj_vals <- constrained_objective(w=weights, R=R, portfolio, trace=TRUE, normalize=FALSE)$objective_measures
-        out <- list(weights=weights, objective_measures=obj_vals, opt_values=obj_vals, out=roi_result$out, call=call)
+      if(!is.null(constraints$turnover_target) | !is.null(constraints$ptc)){
+        if(!is.null(constraints$turnover_target) & !is.null(constraints$ptc)){
+          warning("Turnover and proportional transaction cost constraints detected, only running optimization for turnover constraint.")
+          constraints$ptc <- NULL
+        }
+        if(!is.null(constraints$turnover_target) & is.null(constraints$ptc)){
+          qp_result <- gmv_opt_toc(R=R, constraints=constraints, moments=moments, lambda=lambda, target=target, init_weights=portfolio$assets)
+          weights <- qp_result$weights
+          obj_vals <- constrained_objective(w=weights, R=R, portfolio, trace=TRUE, normalize=FALSE)$objective_measures
+          out <- list(weights=weights, objective_measures=obj_vals, opt_values=obj_vals, out=roi_result$out, call=call)
+        }
+        if(!is.null(constraints$ptc) & is.null(constraints$turnover_target)){
+          qp_result <- gmv_opt_ptc(R=R, constraints=constraints, moments=moments, lambda=lambda, target=target, init_weights=portfolio$assets)
+          weights <- qp_result$weights
+          obj_vals <- constrained_objective(w=weights, R=R, portfolio, trace=TRUE, normalize=FALSE)$objective_measures
+          out <- list(weights=weights, objective_measures=obj_vals, opt_values=obj_vals, out=roi_result$out, call=call)
+        }
       } else {
         roi_result <- gmv_opt(R=R, constraints=constraints, moments=moments, lambda=lambda, target=target, lambda_hhi=lambda_hhi, conc_groups=conc_groups)
         weights <- roi_result$weights



More information about the Returnanalytics-commits mailing list