Skip to content

Commit

Permalink
SCS instead of OSQP
Browse files Browse the repository at this point in the history
  • Loading branch information
xinran1228 committed Oct 27, 2024
1 parent a974b9a commit f80fe27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions R/optimize.portfolio.R
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ optimize.portfolio_v1 <- function(
#' The \code{multiplier} argument in \code{\link{add.objective}} passed into the complete constraint object are ignored by the ROI solver.
#'
#' If \code{optimize_method="CVXR"} is specified, a default solver will be selected based on the optimization problem.
#' The default solver for Linear Problem and Quadratic Programming will be \code{OSQP},
#' and the default solver for Second-Order Cone Programming will be \code{SCS}.
#' The default solver for Quadratic Programming will be \code{OSQP},
#' and the default solver for Linear Problem and Second-Order Cone Programming will be \code{SCS}.
#' Specified CVXR solver can be given by using \code{optimize_method=c("CVXR", "CVXRsolver")}.
#' CVXR supports some commercial solvers, including CBC, CPLEX, GUROBI and MOSEK, and some open source solvers, including GLPK, GLPK_MI, OSQP, SCS and ECOS.
#' For example, \code{optimize_method = c("CVXR", "ECOS")} can be specified and the optimization problem will be solved via CVXR using the ECOS solver.
Expand Down Expand Up @@ -2974,10 +2974,10 @@ optimize.portfolio <- optimize.portfolio_v2 <- function(
prob_cvxr <- CVXR::Problem(CVXR::Minimize(obj), constraints = constraints_cvxr)

if(cvxr_default){
if(risk_ES || risk_CSM || maxSTARR || CSMratio){
result_cvxr <- CVXR::solve(prob_cvxr, solver = "SCS", ... = ...)
} else {
if(risk || maxSR){
result_cvxr <- CVXR::solve(prob_cvxr, solver = "OSQP", ... = ...)
} else {
result_cvxr <- CVXR::solve(prob_cvxr, solver = "SCS", ... = ...)
}
} else {
result_cvxr <- CVXR::solve(prob_cvxr, solver = optimize_method, ... = ...)
Expand Down
8 changes: 4 additions & 4 deletions vignettes/cvxrPortfolioAnalytics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ The PortfolioAnalytics package provides the following two main wrapper functions

`optimize.portfolio.rebalancing(R =, portfolio =, optimize_method =, rebalance_on =, training_period =, rolling_window =)`

Different solvers support different types of portfolio optimization problems, which should be specified by the argument `optimize_method`. The `optimize_method=c("CVXR", {CVXRsolver})` argument of the function `optimize.portfolio` and `optimize.portfolio.rebalancing` allows the user to specify the solver to use with CVXR. If the argument is `optimize_method="CVXR"`, the default solver for LP and QP type portfolio optimization problems, such as maximum mean return and minimum variance portfolio optimization is OSQP, and the default solver for SOCP type portfolio optimizations, such as "robust portfolio optimization" to control for alpha uncertainty, and Coherent Second Moment (CSM) portfolio optimization, is SCS.
Different solvers support different types of portfolio optimization problems, which should be specified by the argument `optimize_method`. The `optimize_method=c("CVXR", {CVXRsolver})` argument of the function `optimize.portfolio` and `optimize.portfolio.rebalancing` allows the user to specify the solver to use with CVXR. If the argument is `optimize_method="CVXR"`, the default solver for QP type portfolio optimization problems, such as minimum variance portfolio optimization is OSQP, and the default solver for LP and SOCP type portfolio optimizations, such as maximum mean return, "robust portfolio optimization" to control for alpha uncertainty, and Coherent Second Moment (CSM) portfolio optimization, is SCS.

| Solver | LP | QP | SOCP |
| :-- | :----: | :----: | :----: |
|CBC|$\checkmark$| | |
|GLPK|$\checkmark$| | |
|GLPK_MI|$\checkmark$| | |
|OSQP|$\colorbox{gray}{\checkmark}$|$\colorbox{gray}{\checkmark}$| |
|SCS|$\checkmark$|$\checkmark$|$\colorbox{gray}{\checkmark}$|
|OSQP|$\checkmark$|$\colorbox{gray}{\checkmark}$| |
|SCS|$\colorbox{gray}{\checkmark}$|$\checkmark$|$\colorbox{gray}{\checkmark}$|
|ECOS|$\checkmark$|$\checkmark$|$\checkmark$|
|CPLEX|$\checkmark$|$\checkmark$|$\checkmark$|
|GUROBI|$\checkmark$|$\checkmark$|$\checkmark$|
Expand Down Expand Up @@ -120,7 +120,7 @@ pspec_maxret
```

## 3.2 Optimization
The next step is to run the optimization. Note that `optimize_method = c("CVXR", {CVXRsolver})` should be specified in the function `optimize.portfolio` to use CVXR solvers for the optimization, or use the default solver by giving `optimize_method = "CVXR"`. For maximizing mean return problem, which is a linear programming, the default solver is `OSQP`.
The next step is to run the optimization. Note that `optimize_method = c("CVXR", {CVXRsolver})` should be specified in the function `optimize.portfolio` to use CVXR solvers for the optimization, or use the default solver by giving `optimize_method = "CVXR"`. For maximizing mean return problem, which is a linear programming, the default solver is `SCS`.
```{r}
# Run the optimization with default solver
opt_maxret <- optimize.portfolio(R = ret_edhec, portfolio = pspec_maxret,
Expand Down
Binary file modified vignettes/cvxrPortfolioAnalytics.pdf
Binary file not shown.

0 comments on commit f80fe27

Please sign in to comment.