The Conic Optimization Solver

Example 11.1 Portfolio Optimization

This example is shown as a quadratic programming problem in Example 18.2: Portfolio Optimization in Chapter 18, The Quadratic Programming Solver. It is included here to show how to transform a QP problem into an SOCP problem.

Consider a portfolio optimization example. The two competing goals of investment are (1) long-term growth of capital and (2) low risk. A good portfolio grows steadily without wild fluctuations in value. The Markowitz model is an optimization model for balancing the return and risk of a portfolio. The decision variables are the amounts that are invested in each asset. The objective is to minimize the variance of the portfolio’s total return, subject to the constraints that (1) the expected growth of the portfolio reaches at least some target level and (2) you do not invest more capital than you have.

Let x 1 comma ellipsis comma x Subscript n Baseline be the amount that is invested in each asset, script upper B be the amount of capital that you have, bold upper R be the random vector of asset returns over some period, and bold r be the expected value of bold upper R. Let G be the minimum growth that you hope to obtain and script upper C be the covariance matrix of bold upper R. The objective function is normal upper V normal a normal r left parenthesis sigma summation Underscript i equals 1 Overscript n Endscripts x Subscript i Baseline upper R Subscript i Baseline right parenthesis, which can be equivalently denoted as bold x Superscript normal upper T Baseline script upper C bold x.

Assume, for example, n = 4. Let script upper B = 10,000, G = 1,000, bold r equals left bracket 0.05 comma negative 0.2 comma 0.15 comma 0.30 right bracket, and

StartLayout 1st Row 1st Column script upper C 2nd Column equals 3rd Column Start 4 By 4 Matrix 1st Row 1st Column 0.08 2nd Column negative 0.05 3rd Column negative 0.05 4th Column negative 0.05 2nd Row 1st Column negative 0.05 2nd Column 0.16 3rd Column negative 0.02 4th Column negative 0.02 3rd Row 1st Column negative 0.05 2nd Column negative 0.02 3rd Column 0.35 4th Column 0.06 4th Row 1st Column negative 0.05 2nd Column negative 0.02 3rd Column 0.06 4th Column 0.35 EndMatrix EndLayout

The QP formulation can be written as

StartLayout 1st Row 1st Column min 2nd Column 0.08 x 1 squared minus 0.1 x 1 x 2 minus 0.1 x 1 x 3 minus 0.1 x 1 x 4 plus 0.16 x 2 squared 2nd Row 1st Column Blank 2nd Column minus 0.04 x 2 x 3 minus 0.04 x 2 x 4 plus 0.35 x 3 squared plus 0.12 x 3 x 4 plus 0.35 x 4 squared EndLayout
StartLayout 1st Row 1st Column normal s normal u normal b normal j normal e normal c normal t normal t normal o 2nd Column Blank 3rd Column Blank 4th Column Blank 2nd Row 1st Column left parenthesis normal b normal u normal d normal g normal e normal t right parenthesis 2nd Column x 1 plus x 2 plus x 3 plus x 4 3rd Column less than or equals 4th Column 10000 3rd Row 1st Column left parenthesis normal g normal r normal o normal w normal t normal h right parenthesis 2nd Column 0.05 x 1 minus 0.2 x 2 plus 0.15 x 3 plus 0.30 x 4 3rd Column greater than or equals 4th Column 1000 4th Row 1st Column Blank 2nd Column x 1 comma x 2 comma x 3 comma x 4 3rd Column greater than or equals 4th Column 0 EndLayout

Because the covariance matrix script upper C is positive semidefinite, there exists a matrix script upper F such that

script upper C equals script upper F Superscript normal upper T Baseline script upper F

There are some practical ways to decompose a positive semidefinite matrix. For example, if you apply Cholesky decomposition, then

StartLayout 1st Row 1st Column script upper F 2nd Column equals 3rd Column Start 4 By 4 Matrix 1st Row 1st Column 0.2828427 2nd Column negative 0.1767767 3rd Column negative 0.1767767 4th Column negative 0.17677670 2nd Row 1st Column 0 2nd Column 0.3588175 3rd Column negative 0.1428303 4th Column negative 0.14283027 3rd Row 1st Column 0 2nd Column 0 3rd Column 0.5462138 4th Column 0.01528617 4th Row 1st Column 0 2nd Column 0 3rd Column 0 4th Column 0.54599986 EndMatrix EndLayout

Then the objective becomes to minimize

bold x Superscript normal upper T Baseline script upper C bold x equals StartMetric script upper F bold x EndMetric squared

By introducing one auxiliary variable, you can write the portfolio optimization problem in the following SOCP formulation:

StartLayout 1st Row 1st Column min 2nd Column x 5 3rd Column Blank 4th Column Blank 2nd Row 1st Column normal s normal u normal b normal j normal e normal c normal t normal t normal o 2nd Column Blank 3rd Column Blank 4th Column Blank 3rd Row 1st Column left parenthesis normal b normal u normal d normal g normal e normal t right parenthesis 2nd Column x 1 plus x 2 plus x 3 plus x 4 3rd Column less than or equals 4th Column 10000 4th Row 1st Column left parenthesis normal g normal r normal o normal w normal t normal h right parenthesis 2nd Column 0.05 x 1 minus 0.2 x 2 plus 0.15 x 3 plus 0.30 x 4 3rd Column greater than or equals 4th Column 1000 5th Row 1st Column left parenthesis normal s normal o normal c right parenthesis 2nd Column StartMetric script upper F bold x EndMetric squared 3rd Column less than or equals 4th Column x 5 squared 6th Row 1st Column Blank 2nd Column x 1 comma x 2 comma x 3 comma x 4 comma x 5 3rd Column greater than or equals 4th Column 0 EndLayout

Use the following SAS statements to solve the problem:

/* example 1: portfolio optimization */
proc optmodel;
   /* let x1, x2, x3, x4 be the amount invested in each asset      */
   /* x5 is the auxiliary variable introduced for SOCP formulation */
   var x{1..5} >= 0;

   num r{1..4}=[0.05 -.20 0.15 0.30];

   /* objective function is the auxiliary variable */
   minimize f = x[5];

   /* subject to the following constraints */
   con BUDGET: sum{i in 1..4}x[i] <= 10000;
   con GROWTH: sum{i in 1..4}r[i]*x[i] >= 1000;

   /* second-order cone constraint to
      minimize the variance of the portfolio's total return */
   con cone: soc(x[5],
      (0.2828427*x[1] - 0.1767767*x[2] - 0.1767767*x[3] - 0.17677670*x[4])
                       (0.3588175*x[2] - 0.1428303*x[3] - 0.14283027*x[4])
                                        (0.5462138*x[3] + 0.01528617*x[4])
                                                         (0.54599986*x[4])
   );

   solve with conic;

   /* print the optimal solution */
   print x;
quit;

The output and optimal solution are displayed in Output 11.1.1.

Output 11.1.1: Portfolio Optimization

The OPTMODEL Procedure

Problem Summary
Objective SenseMinimization
Objective Functionf
Objective TypeLinear
  
Number of Variables5
Bounded Above0
Bounded Below5
Bounded Below and Above0
Free0
Fixed0
  
Number of Constraints3
Linear LE (<=)1
Linear EQ (=)0
Linear GE (>=)1
Linear Range0
Second-Order Cone1

Solution Summary
SolverConic
AlgorithmInterior Point
Objective Functionf
Solution StatusOptimal
Objective Value1494.0927851
  
Primal Infeasibility6.2712091E-9
Dual Infeasibility2.923827E-9
Bound Infeasibility0
Duality Gap3.5817563E-7
Complementarity2.7568982E-7
  
Iterations9
Presolve Time0.00
Solution Time0.00

[1]x
13452.6
20.0
31068.8
42223.5
51494.1


Compared with the QP formulation, the optimal solution that you obtain from solving the SOCP formulation is exactly the same, whereas the optimal objective function value is the square root.

Last updated: September 09, 2026