[Returnanalytics-commits] r3473 - pkg/PortfolioAnalytics/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 18 03:40:26 CEST 2014


Author: rossbennett34
Date: 2014-07-18 03:40:25 +0200 (Fri, 18 Jul 2014)
New Revision: 3473

Removed:
   pkg/PortfolioAnalytics/demo/demo_ROI.R
   pkg/PortfolioAnalytics/demo/demo_group_ROI.R
   pkg/PortfolioAnalytics/demo/demo_maxret_ROI.R
   pkg/PortfolioAnalytics/demo/risk_budget_backtesting.R
Modified:
   pkg/PortfolioAnalytics/demo/00Index
Log:
Removing a few of the demos that are redundant

Modified: pkg/PortfolioAnalytics/demo/00Index
===================================================================
--- pkg/PortfolioAnalytics/demo/00Index	2014-07-18 01:35:16 UTC (rev 3472)
+++ pkg/PortfolioAnalytics/demo/00Index	2014-07-18 01:40:25 UTC (rev 3473)
@@ -3,12 +3,9 @@
 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 creating the 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.
-demo_ROI Demonstrate constraints and objectives that can be solved with ROI.
 demo_DEoptim Demonstrate solving portfolio optimization problems using DEoptim as the solver. The demo solvers 4 problems: 1) Maximize mean return per unit mETL 2) Minimize annualized standard deviation 3) Minimize annualized standard deviation with equal contribution to risk using standard deviation as the risk measure 4) Maximize mean return with equal contribution to risk using modified ETL as the risk measure.
 demo_efficient_frontier Demonstrate how to create and chart efficient frontiers.
 demo_factor_exposure Demonstrate how to use the factor_exposure constraint.
-demo_group_ROI Demonstrate how to use group constraints using the ROI solver.
-demo_maxret_ROI Demonstrate maximizing return using the ROI solver.
 demo_opt_combine Demonstrate how to combine and chart the optimal weights for multiple optimizations.
 demo_weight_concentration Demonstrate how to use the weight concentration objective.
 backwards_compat Demonstrate how to solve optimization problems using v1 specification with a v1_constraint object.
@@ -25,7 +22,6 @@
 demo_min_expected_shortfall Demonstrate objective to minimize expected shortfall.
 demo_risk_budgets Demonstrate using risk budget objectives.
 demo_roi_solvers Demonstrate specifying a solver using ROI.
-risk_budget_backtesting Demonstrate optimize.portfolio.rebalancing with standard deviation risk budget objective.
 chart_concentration Demonstrate chart.Concentration
 multiple_portfolio_optimization Demonstrate passing a list of portfolios to optimize.portfolio and optimize.portfolio.rebalancing
 regime_switching       Demonstrate optimization with support for regime switching to switch portfolios based on the regime.

Deleted: pkg/PortfolioAnalytics/demo/demo_ROI.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_ROI.R	2014-07-18 01:35:16 UTC (rev 3472)
+++ pkg/PortfolioAnalytics/demo/demo_ROI.R	2014-07-18 01:40:25 UTC (rev 3473)
@@ -1,220 +0,0 @@
-# ROI examples
-
-# The following objectives can be solved with optimize_method=ROI
-# maximize return
-# minimum variance
-# maximize quadratic utility
-# minimize ETL
-
-library(PortfolioAnalytics)
-library(ROI)
-library(Rglpk)
-require(ROI.plugin.glpk)
-require(ROI.plugin.quadprog)
-
-# Load the returns data
-data(edhec)
-ret <- edhec[, 1:4]
-funds <- colnames(ret)
-
-# Create portfolio specification
-pspec <- portfolio.spec(assets=funds)
-
-##### Constraints #####
-# Constraints will be specified as separate objects, but could also be added to
-# the portfolio object (see the portfolio vignette for examples of specifying 
-# constraints)
-
-# Full investment constraint
-fi_constr <- weight_sum_constraint(min_sum=1, max_sum=1)
-
-# Long only constraint
-lo_constr <- box_constraint(assets=pspec$assets, min=0, max=1)
-
-# Box constraints
-box_constr <- box_constraint(assets=pspec$assets, 
-                             min=c(0.05, 0.04, 0.1, 0.03),
-                             max=c(0.65, 0.45, 0.7, 0.6))
-
-# Position limit constraint
-pl_constr <- position_limit_constraint(assets=pspec$assets, max_pos=2)
-
-# Target mean return constraint
-ret_constr <- return_constraint(return_target=0.007)
-
-# Group constraint
-group_constr <- group_constraint(assets=pspec$assets, groups=list(1, 2:3, 4), 
-                                 group_min=0, group_max=0.5)
-
-# Factor exposure constraint
-# Industry exposures are used in this example, but other factors could be used as well
-# Note that exposures to industry factors are similar to group constraints
-facexp_constr <- factor_exposure_constraint(assets=pspec$assets, 
-                                            B=cbind(c(1, 0, 0, 0),
-                                                    c(0, 1, 1, 0),
-                                                    c(0, 0, 0, 1)), 
-                                            lower=c(0.1, 0.15, 0.05), 
-                                            upper=c(0.45, 0.65, 0.60))
-
-##### Objectives #####
-# Return objective
-ret_obj <- return_objective(name="mean")
-
-# Variance objective
-var_obj <- portfolio_risk_objective(name="var")
-
-# ETL objective
-etl_obj <- portfolio_risk_objective(name="ETL")
-
-##### Maximize Return Optimization #####
-# The ROI solver uses the glpk plugin to interface to the Rglpk package for 
-# objectives to maximimize mean return
-
-# Full investment and long only constraints
-opt_maxret <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, lo_constr), 
-                                 objectives=list(ret_obj), 
-                                 optimize_method="ROI")
-opt_maxret
-
-# Full investment, box, and target return constraints
-opt_maxret <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, box_constr, ret_constr), 
-                                 objectives=list(ret_obj), 
-                                 optimize_method="ROI")
-opt_maxret
-
-# Full investment, box, and position_limit constraints
-opt_maxret <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, box_constr, pl_constr), 
-                                 objectives=list(ret_obj), 
-                                 optimize_method="ROI")
-opt_maxret
-
-# Full investment, box, and group constraints
-opt_maxret <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, box_constr, group_constr), 
-                                 objectives=list(ret_obj), 
-                                 optimize_method="ROI")
-opt_maxret
-
-# Full investment, box, and factor exposure constraints
-opt_maxret <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, box_constr, facexp_constr), 
-                                 objectives=list(ret_obj), 
-                                 optimize_method="ROI")
-opt_maxret
-
-##### Minimize Variance Optimization #####
-# The ROI solver uses the quadprog plugin to interface to the quadprog package for 
-# objectives to minimize variance
-
-# Global minimum variance portfolio. Only specify the full investment constraint
-opt_minvar <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr),
-                                 objectives=list(var_obj),
-                                 optimize_method="ROI")
-opt_minvar
-
-# Full investment, box, and target mean_return constraints
-opt_minvar <- optimize.portfolio(R=ret, portfolio=pspec,
-                                 constraints=list(fi_constr, box_constr, ret_constr),
-                                 objectives=list(var_obj),
-                                 optimize_method="ROI")
-opt_minvar
-
-# Full investment, box, and group constraints
-opt_minvar <- optimize.portfolio(R=ret, portfolio=pspec,
-                                 constraints=list(fi_constr, box_constr, group_constr),
-                                 objectives=list(var_obj),
-                                 optimize_method="ROI")
-opt_minvar
-
-# Full investment, box, and exposure constraints
-opt_minvar <- optimize.portfolio(R=ret, portfolio=pspec,
-                                 constraints=list(fi_constr, box_constr, facexp_constr),
-                                 objectives=list(var_obj),
-                                 optimize_method="ROI")
-opt_minvar
-
-##### Maximize Quadratic Utility Optimization #####
-# The ROI solver uses the quadprog plugin to interface to the guadprog package for 
-# objectives to maximimize quadratic utility
-
-# Create the variance objective with a large risk_aversion paramater
-# A large risk_aversion parameter will approximate the global minimum variance portfolio
-var_obj <- portfolio_risk_objective(name="var", risk_aversion=1e4)
-
-# Full investment and box constraints
-opt_qu <- optimize.portfolio(R=ret, portfolio=pspec, 
-                             constraints=list(fi_constr, box_constr),
-                             objectives=list(ret_obj, var_obj),
-                             optimize_method="ROI")
-opt_qu
-
-# Change the risk_aversion parameter in the variance objective to a small number
-# A small risk_aversion parameter will approximate the maximum portfolio
-var_obj$risk_aversion <- 1e-4
-
-# Full investment and long only constraints
-opt_qu <- optimize.portfolio(R=ret, portfolio=pspec, 
-                             constraints=list(fi_constr, lo_constr),
-                             objectives=list(ret_obj, var_obj),
-                             optimize_method="ROI")
-opt_qu
-
-# Change the risk_aversion parameter to a more reasonable value
-var_obj$risk_aversion <- 0.25
-# Full investment, long only, and factor exposure constraints
-opt_qu <- optimize.portfolio(R=ret, portfolio=pspec, 
-                             constraints=list(fi_constr, lo_constr, facexp_constr),
-                             objectives=list(ret_obj, var_obj),
-                             optimize_method="ROI")
-opt_qu
-
-# Full investment, long only, target return, and group constraints
-# opt_qu <- optimize.portfolio(R=ret, portfolio=pspec, 
-#                              constraints=list(fi_constr, lo_constr, ret_constr, group_constr),
-#                              objectives=list(ret_obj, var_obj),
-#                              optimize_method="ROI")
-# opt_qu
-
-##### Minimize ETL Optimization #####
-# The ROI solver uses the glpk plugin to interface to the Rglpk package for 
-# objectives to minimimize expected tail loss
-
-# Full investment and long only constraints
-opt_minetl <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, lo_constr),
-                                 objectives=list(etl_obj),
-                                 optimize_method="ROI")
-opt_minetl
-
-# Full investment, box, and target return constraints
-opt_minetl <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, lo_constr, ret_constr),
-                                 objectives=list(etl_obj),
-                                 optimize_method="ROI")
-opt_minetl
-
-# Full investment, long only, and position limit constraints
-opt_minetl <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, lo_constr, pl_constr),
-                                 objectives=list(etl_obj),
-                                 optimize_method="ROI")
-opt_minetl
-
-# Full investment, long only, and group constraints
-opt_minetl <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, lo_constr, group_constr),
-                                 objectives=list(etl_obj),
-                                 optimize_method="ROI")
-opt_minetl
-
-# Full investment, long only, and factor exposure constraints
-opt_minetl <- optimize.portfolio(R=ret, portfolio=pspec, 
-                                 constraints=list(fi_constr, lo_constr, facexp_constr),
-                                 objectives=list(etl_obj),
-                                 optimize_method="ROI")
-opt_minetl
-

Deleted: pkg/PortfolioAnalytics/demo/demo_group_ROI.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_group_ROI.R	2014-07-18 01:35:16 UTC (rev 3472)
+++ pkg/PortfolioAnalytics/demo/demo_group_ROI.R	2014-07-18 01:40:25 UTC (rev 3473)
@@ -1,42 +0,0 @@
-
-library(PortfolioAnalytics)
-library(ROI)
-library(ROI.plugin.quadprog)
-library(ROI.plugin.glpk)
-
-
-data(edhec)
-R <- edhec[, 1:4]
-colnames(R) <- c("CA", "CTAG", "DS", "EM")
-funds <- colnames(R)
-
-# set up portfolio with objectives and constraints
-pspec <- portfolio.spec(assets=funds)
-pspec <- add.constraint(portfolio=pspec, type="full_investment")
-pspec <- add.constraint(portfolio=pspec, type="long_only")
-# add two levels of grouping
-pspec <- add.constraint(portfolio=pspec, type="group",
-                        groups=list(groupA=c(1, 3),
-                                    groupB=c(2, 4),
-                                    geoA=c(1, 2, 4),
-                                    geoB=3),
-                        group_min=c(0.15, 0.25, 0.15, 0.2),
-                        group_max=c(0.4, 0.7, 0.8, 0.62))
-pspec
-
-maxret <- add.objective(portfolio=pspec, type="return", name="mean")
-opt_maxret <- optimize.portfolio(R=R, portfolio=maxret, optimize_method="ROI")
-summary(opt_maxret)
-
-minvar <- add.objective(portfolio=pspec, type="risk", name="var")
-opt_minvar <- optimize.portfolio(R=R, portfolio=minvar, optimize_method="ROI")
-summary(opt_minvar)
-
-minetl <- add.objective(portfolio=pspec, type="risk", name="ETL")
-opt_minetl <- optimize.portfolio(R=R, portfolio=minetl, optimize_method="ROI")
-summary(opt_minetl)
-
-maxqu <- add.objective(portfolio=pspec, type="return", name="mean")
-maxqu <- add.objective(portfolio=maxqu, type="risk", name="var", risk_aversion=0.25)
-opt_maxqu <- optimize.portfolio(R=R, portfolio=maxqu, optimize_method="ROI")
-summary(opt_maxqu)

Deleted: pkg/PortfolioAnalytics/demo/demo_maxret_ROI.R
===================================================================
--- pkg/PortfolioAnalytics/demo/demo_maxret_ROI.R	2014-07-18 01:35:16 UTC (rev 3472)
+++ pkg/PortfolioAnalytics/demo/demo_maxret_ROI.R	2014-07-18 01:40:25 UTC (rev 3473)
@@ -1,56 +0,0 @@
-library(PortfolioAnalytics)
-library(foreach)
-library(iterators)
-library(quadprog)
-library(Rglpk)
-library(ROI)
-require(ROI.plugin.glpk)
-require(ROI.plugin.quadprog)
-
-
-data(edhec)
-ret <- edhec[, 1:4]
-funds <- colnames(ret)
-
-##### Method 1 #####
-# Set up portfolio object with constraints and objectives to maximize return
-# using the portfolio object to add constraints and objectives
-pspec1 <- portfolio.spec(assets=funds)
-pspec1 <- add.constraint(portfolio=pspec1, type="full_investment")
-pspec1 <- add.constraint(portfolio=pspec1, type="box", min=0, max=0.65)
-pspec1 <- add.objective(portfolio=pspec1, type="return", name="mean")
-
-opt1 <- optimize.portfolio(R=ret, portfolio=pspec1, optimize_method="ROI")
-
-##### Method 2 #####
-# Set up portfolio object with constraints and objective to maximize return
-# using separate constraint and objective objects
-pspec2 <- portfolio.spec(assets=funds)
-weight_constr <- weight_sum_constraint(min_sum=1, max_sum=1)
-box_constr <- box_constraint(assets=pspec2$assets, min=0, max=0.65)
-ret_obj <- return_objective(name="mean")
-cset <- list(weight_constr, box_constr)
-obj <- list(ret_obj)
-
-opt2 <- optimize.portfolio(R=ret, portfolio=pspec2, constraints=cset, 
-                           objectives=obj, optimize_method="ROI")
-
-all.equal(extractWeights(opt1), extractWeights(opt2))
-
-##### Method 1 Backtesting #####
-opt_rebal1 <- optimize.portfolio.rebalancing(R=ret, portfolio=pspec1, 
-                                             optimize_method="ROI", 
-                                             rebalance_on="months")
-class(opt_rebal1)
-inherits(opt_rebal1, "optimize.portfolio.rebalancing")
-wts1 <- extractWeights(opt_rebal1)
-
-##### Method 2 Backtesting #####
-opt_rebal2 <- optimize.portfolio.rebalancing(R=ret, portfolio=pspec2, 
-                                             constraints=cset, 
-                                             objectives=obj,
-                                             optimize_method="ROI", 
-                                             rebalance_on="months")
-wts2 <- extractWeights(opt_rebal2)
-all.equal(wts1, wts2)
-

Deleted: pkg/PortfolioAnalytics/demo/risk_budget_backtesting.R
===================================================================
--- pkg/PortfolioAnalytics/demo/risk_budget_backtesting.R	2014-07-18 01:35:16 UTC (rev 3472)
+++ pkg/PortfolioAnalytics/demo/risk_budget_backtesting.R	2014-07-18 01:40:25 UTC (rev 3473)
@@ -1,59 +0,0 @@
-
-library(PortfolioAnalytics)
-data(edhec)
-
-# Use first four columns of edhec data set
-R <- edhec[, 1:4]
-funds <- colnames(R)
-
-# Initialize portfolio and add basic constraints
-init.portf <- portfolio.spec(funds, weight_seq=generatesequence(min=0, max=1, by=0.002))
-init.portf <- add.constraint(init.portf, "weight_sum")#, min_sum=0.99, max_sum=1.01)
-init.portf <- add.constraint(init.portf, "box", min=0, max=0.65)
-
-# Add mean return objective with multiplier=0 so it is calculated, but does
-# not affect optimization
-init.portf <- add.objective(init.portf, type="return", name="mean", multiplier=0)
-
-# Add objective to minimize portfolio standard deviation
-SDRB.portf <- add.objective(init.portf, type="risk", name="StdDev")
-
-# Add StdDev risk budget objective for maximum percentage risk 
-SDRB.portf <- add.objective(SDRB.portf, type="risk_budget", name="StdDev", max_prisk=0.4)
-
-# Generate random portfolios
-rp <- random_portfolios(init.portf, 5000)
-
-# Run out of sample backtest with yearly rebalancing
-SDRB.opt.bt <- optimize.portfolio.rebalancing(R, SDRB.portf,
-                                              optimize_method="random", 
-                                              rp=rp,
-                                              trace=TRUE, 
-                                              rebalance_on="years", 
-                                              training_period=100, 
-                                              trailing_periods=60)
-
-# print method for optimize.portfolio.rebalancing objects
-SDRB.opt.bt
-
-# summary method for optimize.portfolio.rebalancing objects
-tmp_summary <- summary(SDRB.opt.bt)
-names(tmp_summary)
-
-# print method for summary.optimize.portfolio.rebalancing objects
-tmp_summary
-
-# Extractor functions for summary.optimize.portfolio.rebalancing objects
-extractWeights(tmp_summary)
-extractObjectiveMeasures(tmp_summary)
-
-# Extractor functions for optimize.portfolio.rebalancing objects
-tmp_stats <- extractStats(SDRB.opt.bt)
-head(tmp_stats[[1]])
-tmp_weights <- extractWeights(SDRB.opt.bt)
-tmp_obj <- extractObjectiveMeasures(SDRB.opt.bt)
-
-# chart functions for optimize.portfolio.rebalancing
-chart.Weights(SDRB.opt.bt)
-chart.RiskBudget(SDRB.opt.bt, match.col="StdDev", risk.type="percent")
-



More information about the Returnanalytics-commits mailing list