#' ---1#' title: "Backwards Compatibility Demo"2#' author: "Ross Bennett"3#' date: "7/17/2014"4#' ---56#' This script demonstrates how to solve optimization problems using what is7#' referred to as the v1 specification. The v1 specification was used in8#' before PortfolioAnalytics version 0.8.3 to define the optimization problem9#' with constraints and objectives.1011library(PortfolioAnalytics)12library(DEoptim)13library(ROI)14require(ROI.plugin.glpk)1516data(edhec)17ret <- edhec[, 1:4]18funds <- colnames(ret)1920#' Set up constraint object using v1 specification21gen.constr <- constraint(assets=funds, min=0, max=0.55, min_sum=0.99, max_sum=1.01,22weight_seq=generatesequence(min=0, max=0.55, by=0.002))23class(gen.constr)2425#' Add an objective to the gen.constr object26gen.constr <- add.objective(constraints=gen.constr, type="return", name="mean", enabled=TRUE)2728#' Here we run the optimization. Note that optimize.portfolio will detect29#' that a v1_constraint object has been passed in and will update to the30#' v2 specification using a portfolio object with constraints and objectives31#' from the v1_constraint object.3233#' Solve the problem using the random portfolios optimization engine34optrpv1 <- optimize.portfolio(R=ret, constraints=gen.constr, optimize_method="random", search_size=2000)35optrpv13637#' Solve the problem using the DEoption (Differential Evolution) optimization engine38optdev1 <- optimize.portfolio(R=ret, constraints=gen.constr, optimize_method="DEoptim", search_size=2000)39optdev14041#' Solve the problem using the ROI (R Optimization Infrastructure) optimization engine42optroiv1 <- optimize.portfolio(R=ret, constraints=gen.constr, optimize_method="ROI")43optroiv14445464748