## Portfolio Optimization (qpsole02)

```/***************************************************************/
/*                                                             */
/*          S A S   S A M P L E   L I B R A R Y                */
/*                                                             */
/*    NAME: qpsole02                                           */
/*   TITLE: Portfolio Optimization (qpsole02)                  */
/* PRODUCT: OR                                                 */
/*  SYSTEM: ALL                                                */
/*    KEYS: OR                                                 */
/*   PROCS: OPTMODEL                                           */
/*    DATA:                                                    */
/*                                                             */
/* SUPPORT:                             UPDATE:                */
/*     REF:                                                    */
/*    MISC: Example 2 from the Quadratic Programming Solver    */
/*          chapter of Mathematical Programming.               */
/*                                                             */
/***************************************************************/

/* example 2: portfolio optimization */
proc optmodel;
/* let x1, x2, x3, x4 be the amount invested in each asset */
var x{1..4} >= 0;

num coeff{1..4, 1..4} = [0.08 -.05 -.05 -.05
-.05 0.16 -.02 -.02
-.05 -.02 0.35 0.06
-.05 -.02 0.06 0.35];
num r{1..4}=[0.05 -.20 0.15 0.30];

/* minimize the variance of the portfolio's total return */
minimize f = sum{i in 1..4, j in 1..4}coeff[i,j]*x[i]*x[j];

/* 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;

solve with qp;

/* print the optimal solution */
print x;

/* example 2: portfolio optimization with short-sale option */
/* dropping nonnegativity assumption */
for {i in 1..4} x[i].lb=-x[i].ub;

solve with qp;

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

```