The OPTQP Procedure

Example 7.2 Portfolio Optimization

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 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 invested in each asset, script upper B be the amount of capital 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 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 = 1000, 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 follows:

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-equal-to 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-equal-to 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-equal-to 4th Column 0 EndLayout

The corresponding QPS-format input data set is as follows:

data portdata;
   input field1 $ field2 $ field3 $ field4 field5 $ field6 @;
datalines;
NAME  .         PORT     .          .         .
ROWS  .         .        .          .         .
N     OBJ.FUNC  .        .          .         .
L     BUDGET    .        .          .         .
G     GROWTH    .        .          .         .
COLUMNS .       .        .          .         .
.     X1        BUDGET   1.0        GROWTH    0.05
.     X2        BUDGET   1.0        GROWTH    -.20
.     X3        BUDGET   1.0        GROWTH    0.15
.     X4        BUDGET   1.0        GROWTH    0.30
RHS   .         .        .          .         .
.     RHS       BUDGET   10000      .         .
.     RHS       GROWTH   1000       .         .
RANGES .        .        .          .         .
BOUNDS .        .        .          .         .
QUADOBJ .        .       .           .        .
.     X1        X1       0.16       .         .
.     X1        X2       -.10       .         .
.     X1        X3       -.10       .         .
.     X1        X4       -.10       .         .
.     X2        X2       0.32       .         .
.     X2        X3       -.04       .         .
.     X2        X4       -.04       .         .
.     X3        X3       0.70       .         .
.     X3        X4       0.12       .         .
.     X4        X4       0.70       .         .
ENDATA .        .        .          .         .
;

Use the following SAS statements to solve the problem:

data mycas.portdata;
   set portdata;
   _id_ = _n_;
run;
proc optqp data = mycas.portdata
  printlevel = 0
  primalout = mycas.portpout
  dualout   = mycas.portdout;
run;

The optimal solution is shown in Output 7.2.1.

Output 7.2.1: Portfolio Optimization

The OPTQP Procedure
Primal Solution

ObsObjective Function IDRHS IDVariable
Name
Variable
Type
Linear
Objective
Coefficient
Lower
Bound
Upper BoundVariable ValueVariable
Status
1OBJ.FUNCRHSX1N001.7977E3083452.86O
2OBJ.FUNCRHSX2N001.7977E3080.00O
3OBJ.FUNCRHSX3N001.7977E3081068.81O
4OBJ.FUNCRHSX4N001.7977E3082223.45O


Thus, the minimum variance portfolio that earns an expected return of at least 10% is x 1 equals 3452.86, x 2 equals 0, x 3 equals 1068.81, x 4 equals 2223.45. Asset 2 gets nothing, because its expected return is minus20% and its covariance with the other assets is not sufficiently negative for it to bring any diversification benefits. What if you drop the nonnegativity assumption? You need to update the BOUNDS section in the existing QPS-format data set to indicate that the decision variables are free.

   ...
   RANGES .        .        .          .         .
   BOUNDS .        .        .          .         .
   FR    BND1      X1       .          .         .
   FR    BND1      X2       .          .         .
   FR    BND1      X3       .          .         .
   FR    BND1      X4       .          .         .
   QUADOBJ .        .       .          .         .
   ...

Financially, that means you are allowed to short-sell—that is, sell low-mean-return assets and use the proceeds to invest in high-mean-return assets. In other words, you put a negative portfolio weight in low-mean assets and "more than 100%" in high-mean assets. You can see in the optimal solution displayed in Output 7.2.2 that the decision variable x 2, denoting Asset 2, is equal to minus1563.61, which means short sale of that asset.

Output 7.2.2: Portfolio Optimization with Short-Sale Option

The OPTQP Procedure
Primal Solution

ObsObjective Function IDRHS IDVariable
Name
Variable
Type
Linear
Objective
Coefficient
Lower BoundUpper BoundVariable ValueVariable
Status
1OBJ.FUNCRHSX1F0-1.7977E3081.7977E3081684.35O
2OBJ.FUNCRHSX2F0-1.7977E3081.7977E308-1563.61O
3OBJ.FUNCRHSX3F0-1.7977E3081.7977E308682.51O
4OBJ.FUNCRHSX4F0-1.7977E3081.7977E3081668.95O


Last updated: October 07, 2021