[Returnanalytics-commits] r2247 - in pkg/PortfolioAnalytics: demo sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 19 14:43:45 CEST 2012


Author: hezkyvaron
Date: 2012-08-19 14:43:44 +0200 (Sun, 19 Aug 2012)
New Revision: 2247

Added:
   pkg/PortfolioAnalytics/demo/testing_GenSA.R
   pkg/PortfolioAnalytics/demo/testing_ROI.R
   pkg/PortfolioAnalytics/demo/testing_pso.R
Removed:
   pkg/PortfolioAnalytics/sandbox/testing_GenSA.R
   pkg/PortfolioAnalytics/sandbox/testing_ROI.R
   pkg/PortfolioAnalytics/sandbox/testing_pso.R
Modified:
   pkg/PortfolioAnalytics/demo/00Index
Log:
- moved testing scripts for ROI, pso, and GenSA to demo
- updated index in demo to reflect these changes

Modified: pkg/PortfolioAnalytics/demo/00Index
===================================================================
--- pkg/PortfolioAnalytics/demo/00Index	2012-08-19 12:10:30 UTC (rev 2246)
+++ pkg/PortfolioAnalytics/demo/00Index	2012-08-19 12:43:44 UTC (rev 2247)
@@ -1,2 +1,5 @@
 constrained_optim	Demonstrate creating and using constrained portfolio optimization using the dataset 'edhec'.  Includes examples of both DEoptim and random portfolio optimization.
 sortino             Maximize the Sortino Ratio of the portfolio 
+testing_ROI  Demonstrate creating constraint object and solve five basic convex portfolio optimization problems with ROI using the 'edhec' dataset.
+testing_pso  Demonstrate creating constraint object and solve portfolio optimization problems with pso using the 'edhec' dataset.  These sample problems are similar to those used in testing_ROI, so that one can compare solutions easily.
+testing_GenSA  Demonstrate the creating constraint object and solve portfolio optimization problems with GenSA using the 'edhec' datset.  These sample problems are similar to those used in testing_ROI, so that one can compare solutions easily.
\ No newline at end of file

Added: pkg/PortfolioAnalytics/demo/testing_GenSA.R
===================================================================
--- pkg/PortfolioAnalytics/demo/testing_GenSA.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/demo/testing_GenSA.R	2012-08-19 12:43:44 UTC (rev 2247)
@@ -0,0 +1,63 @@
+# # # # # # # # # # # # # # # # #
+#  OPTIMIZATION TESTING: ROI
+#
+
+library(xts)
+library(quadprog)
+library(Rglpk)
+library(PerformanceAnalytics)
+library(ROI)
+library(ROI.plugin.glpk)
+library(ROI.plugin.quadprog)
+library(Ecdat)
+library(PortfolioAnalytics)
+library(DEoptim)
+library(pso)
+library(GenSA)
+
+# General Parameters for sample code
+data(edhec)
+N <- 4
+R <- edhec[,1:N]
+funds <- names(R)
+mu.port <- mean(colMeans(R))
+
+gen.constr <- constraint(assets = funds, min=-2, max=2, min_sum=0.99, max_sum=1.01, risk_aversion=1)
+gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=FALSE, target=mu.port)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="var", enabled=FALSE, risk_aversion=10)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="CVaR", enabled=FALSE)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="sd", enabled=FALSE)
+
+
+# =====================
+# Max return under box constraints, fully invested
+max.port <- gen.constr
+max.port$min <- rep(0.01,N)
+max.port$max <- rep(0.30,N)
+max.port$objectives[[1]]$enabled <- TRUE
+max.port$objectives[[1]]$target <- NULL
+max.port$objectives[[1]]$multiplier  <- -1
+max.solution <- optimize.portfolio(R, max.port, "GenSA", trace=TRUE)
+
+
+# =====================
+# Mean-variance:  Fully invested, Global Minimum Variance Portfolio
+gmv.port <- gen.constr
+gmv.port$objectives[[4]]$enabled <- TRUE
+gmv.solution <- optimize.portfolio(R, gmv.port, "GenSA", trace=TRUE)
+
+
+
+# ========================
+# Minimize CVaR with target return
+#
+cvar.port <- gen.constr
+cvar.port$min <- rep(0,N)
+cvar.port$max <- rep(1,N)
+cvar.port$objectives[[3]]$enabled <- TRUE
+cvar.port$objectives[[3]]$arguments <- list(p=0.95, clean="boudt")
+cvar.solution <- optimize.portfolio(R, cvar.port, "pso")
+
+
+
+

Added: pkg/PortfolioAnalytics/demo/testing_ROI.R
===================================================================
--- pkg/PortfolioAnalytics/demo/testing_ROI.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/demo/testing_ROI.R	2012-08-19 12:43:44 UTC (rev 2247)
@@ -0,0 +1,101 @@
+# # # # # # # # # # # # # # # # #
+#  OPTIMIZATION TESTING: ROI
+#
+
+library(xts)
+library(quadprog)
+library(Rglpk)
+library(PerformanceAnalytics)
+library(ROI)
+library(ROI.plugin.glpk)
+library(ROI.plugin.quadprog)
+library(Ecdat)
+library(PortfolioAnalytics)
+
+
+# General Parameters for sample code
+data(edhec)
+funds <- names(edhec)
+mu.port <- mean(colMeans(edhec))
+N <- length(funds)
+
+gen.constr <- constraint(assets = colnames(edhec), min=-Inf, max =Inf, min_sum=1, max_sum=1, risk_aversion=1)
+gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=FALSE, multiplier=0, target=mu.port)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="var", enabled=FALSE, multiplier=0, risk_aversion=10)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="CVaR", enabled=FALSE, multiplier=0)
+
+
+# =====================
+# Max return under box constraints, fully invested
+#
+max.port <- gen.constr
+max.port$min <- rep(0.01,N)
+max.port$max <- rep(0.30,N)
+max.port$objectives[[1]]$enabled <- TRUE
+max.port$objectives[[1]]$target <- NULL
+max.solution <- optimize.portfolio(edhec, max.port, "ROI")
+
+
+# =====================
+# Mean-variance:  Fully invested, Global Minimum Variance Portfolio
+#
+gmv.port <- gen.constr
+gmv.port$objectives[[2]]$enabled <- TRUE
+gmv.port$objectives[[2]]$risk_aversion <- 1
+gmv.solution <- optimize.portfolio(edhec, gmv.port, "ROI")
+
+
+# ========================
+# Mean-variance:  Maximize quadratic utility, fully invested, target portfolio return
+#
+target.port <- gen.constr
+target.port$objectives[[1]]$enabled <- TRUE
+target.port$objectives[[2]]$enabled <- TRUE
+target.solution <- optimize.portfolio(edhec, target.port, "ROI")
+
+
+# ========================
+# Mean-variance:  Maximize quadratic utility, dollar-neutral, target portfolio return
+#
+dollar.neu.port <- gen.constr
+dollar.neu.port$min_sum <- 0
+dollar.neu.port$max_sum <- 0
+dollar.neu.port$objectives[[1]]$enabled <- TRUE
+dollar.neu.port$objectives[[2]]$enabled <- TRUE
+dollar.neu.solution <- optimize.portfolio(edhec, dollar.neu.port, "ROI")
+
+
+# ========================
+# Minimize CVaR with target return
+#
+cvar.port <- gen.constr
+cvar.port$objectives[[1]]$enabled <- TRUE
+cvar.port$objectives[[3]]$enabled <- TRUE
+cvar.solution <- optimize.portfolio(edhec, cvar.port, "ROI")
+
+
+# =====================
+# Mean-variance:  Fully invested, Global Minimum Variance Portfolio, Groups Constraints
+#
+groups.port <- gen.constr
+groups <- c(3,3,3,4)
+groups.port$groups <- groups 
+groups.port$cLO <- rep(0.15,length(groups))
+groups.port$cUP <- rep(0.30,length(groups)) 
+groups.port$objectives[[2]]$enabled <- TRUE
+groups.port$objectives[[2]]$risk_aversion <- 1
+groups.solution <- optimize.portfolio(edhec, groups.port, "ROI")
+
+
+# ========================
+# Minimize CVaR with target return and group constraints
+#
+group.cvar.port <- gen.constr
+groups <- c(3,3,3,4)
+group.cvar.port$groups <- groups
+group.cvar.port$cLO <- rep(0.15,length(groups))
+group.cvar.port$cUP <- rep(0.30,length(groups))
+group.cvar.port$objectives[[1]]$enabled <- TRUE
+group.cvar.port$objectives[[3]]$enabled <- TRUE
+group.cvar.solution <- optimize.portfolio(edhec, group.cvar.port, "ROI")
+

Added: pkg/PortfolioAnalytics/demo/testing_pso.R
===================================================================
--- pkg/PortfolioAnalytics/demo/testing_pso.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/demo/testing_pso.R	2012-08-19 12:43:44 UTC (rev 2247)
@@ -0,0 +1,62 @@
+# # # # # # # # # # # # # # # # #
+#  OPTIMIZATION TESTING: ROI
+#
+
+library(xts)
+library(quadprog)
+library(Rglpk)
+library(PerformanceAnalytics)
+library(ROI)
+library(ROI.plugin.glpk)
+library(ROI.plugin.quadprog)
+library(Ecdat)
+library(PortfolioAnalytics)
+library(DEoptim)
+library(pso)
+
+# General Parameters for sample code
+data(edhec)
+N <- 4
+R <- edhec[,1:N]
+funds <- names(R)
+mu.port <- mean(colMeans(R))
+
+gen.constr <- constraint(assets = funds, min=-2, max=2, min_sum=0.99, max_sum=1.01, risk_aversion=1)
+gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=FALSE, target=mu.port)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="var", enabled=FALSE, risk_aversion=10)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="CVaR", enabled=FALSE)
+gen.constr <- add.objective(constraints=gen.constr, type="risk", name="sd", enabled=FALSE)
+
+
+# =====================
+# Max return under box constraints, fully invested
+max.port <- gen.constr
+max.port$min <- rep(0.01,N)
+max.port$max <- rep(0.30,N)
+max.port$objectives[[1]]$enabled <- TRUE
+max.port$objectives[[1]]$target <- NULL
+max.port$objectives[[1]]$multiplier  <- -1
+max.solution <- optimize.portfolio(R, max.port, "pso", trace=TRUE)
+
+
+# =====================
+# Mean-variance:  Fully invested, Global Minimum Variance Portfolio
+gmv.port <- gen.constr
+gmv.port$objectives[[4]]$enabled <- TRUE
+gmv.solution <- optimize.portfolio(R, gmv.port, "pso", trace=TRUE)
+
+
+
+# ========================
+# Minimize CVaR with target return
+#
+cvar.port <- gen.constr
+cvar.port$min <- rep(0,N)
+cvar.port$max <- rep(1,N)
+cvar.port$objectives[[3]]$enabled <- TRUE
+cvar.port$objectives[[3]]$arguments <- list(p=0.95, clean="boudt")
+cvar.solution <- optimize.portfolio(R, cvar.port, "pso", trace=TRUE)
+
+
+
+

Deleted: pkg/PortfolioAnalytics/sandbox/testing_GenSA.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_GenSA.R	2012-08-19 12:10:30 UTC (rev 2246)
+++ pkg/PortfolioAnalytics/sandbox/testing_GenSA.R	2012-08-19 12:43:44 UTC (rev 2247)
@@ -1,63 +0,0 @@
-# # # # # # # # # # # # # # # # #
-#  OPTIMIZATION TESTING: ROI
-#
-
-library(xts)
-library(quadprog)
-library(Rglpk)
-library(PerformanceAnalytics)
-library(ROI)
-library(ROI.plugin.glpk)
-library(ROI.plugin.quadprog)
-library(Ecdat)
-library(PortfolioAnalytics)
-library(DEoptim)
-library(pso)
-library(GenSA)
-
-# General Parameters for sample code
-data(edhec)
-N <- 4
-R <- edhec[,1:N]
-funds <- names(R)
-mu.port <- mean(colMeans(R))
-
-gen.constr <- constraint(assets = funds, min=-2, max=2, min_sum=0.99, max_sum=1.01, risk_aversion=1)
-gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=FALSE, target=mu.port)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="var", enabled=FALSE, risk_aversion=10)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="CVaR", enabled=FALSE)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="sd", enabled=FALSE)
-
-
-# =====================
-# Max return under box constraints, fully invested
-max.port <- gen.constr
-max.port$min <- rep(0.01,N)
-max.port$max <- rep(0.30,N)
-max.port$objectives[[1]]$enabled <- TRUE
-max.port$objectives[[1]]$target <- NULL
-max.port$objectives[[1]]$multiplier  <- -1
-max.solution <- optimize.portfolio(R, max.port, "GenSA", trace=TRUE)
-
-
-# =====================
-# Mean-variance:  Fully invested, Global Minimum Variance Portfolio
-gmv.port <- gen.constr
-gmv.port$objectives[[4]]$enabled <- TRUE
-gmv.solution <- optimize.portfolio(R, gmv.port, "GenSA", trace=TRUE)
-
-
-
-# ========================
-# Minimize CVaR with target return
-#
-cvar.port <- gen.constr
-cvar.port$min <- rep(0,N)
-cvar.port$max <- rep(1,N)
-cvar.port$objectives[[3]]$enabled <- TRUE
-cvar.port$objectives[[3]]$arguments <- list(p=0.95, clean="boudt")
-cvar.solution <- optimize.portfolio(R, cvar.port, "pso")
-
-
-
-

Deleted: pkg/PortfolioAnalytics/sandbox/testing_ROI.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_ROI.R	2012-08-19 12:10:30 UTC (rev 2246)
+++ pkg/PortfolioAnalytics/sandbox/testing_ROI.R	2012-08-19 12:43:44 UTC (rev 2247)
@@ -1,101 +0,0 @@
-# # # # # # # # # # # # # # # # #
-#  OPTIMIZATION TESTING: ROI
-#
-
-library(xts)
-library(quadprog)
-library(Rglpk)
-library(PerformanceAnalytics)
-library(ROI)
-library(ROI.plugin.glpk)
-library(ROI.plugin.quadprog)
-library(Ecdat)
-library(PortfolioAnalytics)
-
-
-# General Parameters for sample code
-data(edhec)
-funds <- names(edhec)
-mu.port <- mean(colMeans(edhec))
-N <- length(funds)
-
-gen.constr <- constraint(assets = colnames(edhec), min=-Inf, max =Inf, min_sum=1, max_sum=1, risk_aversion=1)
-gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=FALSE, multiplier=0, target=mu.port)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="var", enabled=FALSE, multiplier=0, risk_aversion=10)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="CVaR", enabled=FALSE, multiplier=0)
-
-
-# =====================
-# Max return under box constraints, fully invested
-#
-max.port <- gen.constr
-max.port$min <- rep(0.01,N)
-max.port$max <- rep(0.30,N)
-max.port$objectives[[1]]$enabled <- TRUE
-max.port$objectives[[1]]$target <- NULL
-max.solution <- optimize.portfolio(edhec, max.port, "ROI")
-
-
-# =====================
-# Mean-variance:  Fully invested, Global Minimum Variance Portfolio
-#
-gmv.port <- gen.constr
-gmv.port$objectives[[2]]$enabled <- TRUE
-gmv.port$objectives[[2]]$risk_aversion <- 1
-gmv.solution <- optimize.portfolio(edhec, gmv.port, "ROI")
-
-
-# ========================
-# Mean-variance:  Maximize quadratic utility, fully invested, target portfolio return
-#
-target.port <- gen.constr
-target.port$objectives[[1]]$enabled <- TRUE
-target.port$objectives[[2]]$enabled <- TRUE
-target.solution <- optimize.portfolio(edhec, target.port, "ROI")
-
-
-# ========================
-# Mean-variance:  Maximize quadratic utility, dollar-neutral, target portfolio return
-#
-dollar.neu.port <- gen.constr
-dollar.neu.port$min_sum <- 0
-dollar.neu.port$max_sum <- 0
-dollar.neu.port$objectives[[1]]$enabled <- TRUE
-dollar.neu.port$objectives[[2]]$enabled <- TRUE
-dollar.neu.solution <- optimize.portfolio(edhec, dollar.neu.port, "ROI")
-
-
-# ========================
-# Minimize CVaR with target return
-#
-cvar.port <- gen.constr
-cvar.port$objectives[[1]]$enabled <- TRUE
-cvar.port$objectives[[3]]$enabled <- TRUE
-cvar.solution <- optimize.portfolio(edhec, cvar.port, "ROI")
-
-
-# =====================
-# Mean-variance:  Fully invested, Global Minimum Variance Portfolio, Groups Constraints
-#
-groups.port <- gen.constr
-groups <- c(3,3,3,4)
-groups.port$groups <- groups 
-groups.port$cLO <- rep(0.15,length(groups))
-groups.port$cUP <- rep(0.30,length(groups)) 
-groups.port$objectives[[2]]$enabled <- TRUE
-groups.port$objectives[[2]]$risk_aversion <- 1
-groups.solution <- optimize.portfolio(edhec, groups.port, "ROI")
-
-
-# ========================
-# Minimize CVaR with target return and group constraints
-#
-group.cvar.port <- gen.constr
-groups <- c(3,3,3,4)
-group.cvar.port$groups <- groups
-group.cvar.port$cLO <- rep(0.15,length(groups))
-group.cvar.port$cUP <- rep(0.30,length(groups))
-group.cvar.port$objectives[[1]]$enabled <- TRUE
-group.cvar.port$objectives[[3]]$enabled <- TRUE
-group.cvar.solution <- optimize.portfolio(edhec, group.cvar.port, "ROI")
-

Deleted: pkg/PortfolioAnalytics/sandbox/testing_pso.R
===================================================================
--- pkg/PortfolioAnalytics/sandbox/testing_pso.R	2012-08-19 12:10:30 UTC (rev 2246)
+++ pkg/PortfolioAnalytics/sandbox/testing_pso.R	2012-08-19 12:43:44 UTC (rev 2247)
@@ -1,62 +0,0 @@
-# # # # # # # # # # # # # # # # #
-#  OPTIMIZATION TESTING: ROI
-#
-
-library(xts)
-library(quadprog)
-library(Rglpk)
-library(PerformanceAnalytics)
-library(ROI)
-library(ROI.plugin.glpk)
-library(ROI.plugin.quadprog)
-library(Ecdat)
-library(PortfolioAnalytics)
-library(DEoptim)
-library(pso)
-
-# General Parameters for sample code
-data(edhec)
-N <- 4
-R <- edhec[,1:N]
-funds <- names(R)
-mu.port <- mean(colMeans(R))
-
-gen.constr <- constraint(assets = funds, min=-2, max=2, min_sum=0.99, max_sum=1.01, risk_aversion=1)
-gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=FALSE, target=mu.port)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="var", enabled=FALSE, risk_aversion=10)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="CVaR", enabled=FALSE)
-gen.constr <- add.objective(constraints=gen.constr, type="risk", name="sd", enabled=FALSE)
-
-
-# =====================
-# Max return under box constraints, fully invested
-max.port <- gen.constr
-max.port$min <- rep(0.01,N)
-max.port$max <- rep(0.30,N)
-max.port$objectives[[1]]$enabled <- TRUE
-max.port$objectives[[1]]$target <- NULL
-max.port$objectives[[1]]$multiplier  <- -1
-max.solution <- optimize.portfolio(R, max.port, "pso", trace=TRUE)
-
-
-# =====================
-# Mean-variance:  Fully invested, Global Minimum Variance Portfolio
-gmv.port <- gen.constr
-gmv.port$objectives[[4]]$enabled <- TRUE
-gmv.solution <- optimize.portfolio(R, gmv.port, "pso", trace=TRUE)
-
-
-
-# ========================
-# Minimize CVaR with target return
-#
-cvar.port <- gen.constr
-cvar.port$min <- rep(0,N)
-cvar.port$max <- rep(1,N)
-cvar.port$objectives[[3]]$enabled <- TRUE
-cvar.port$objectives[[3]]$arguments <- list(p=0.95, clean="boudt")
-cvar.solution <- optimize.portfolio(R, cvar.port, "pso", trace=TRUE)
-
-
-
-



More information about the Returnanalytics-commits mailing list