MODEL: ! Markowitz Value at Risk Portfolio Model(PORTVAR);
! Find a portfolio that minimizes the loss threshold that
   has a probability of .05 of being exceeded;
! Keywords: value at risk, Markowitz, portfolio, Second order cone, SOC;
SETS:
  STOCKS: AMT, RET;
  COVMAT(STOCKS, STOCKS): VARIANCE;
 ENDSETS
DATA: STOCKS = ATT, GMC, USX; STARTW = 1.0; ! How much we start with; PROB = .05;! Risk threshold, must be < .05; !Covariance matrix and expected returns, see Markowitz(1959); VARIANCE = .01080754 .01240721 .01307513 .01240721 .05839170 .05542639 .01307513 .05542639 .09422681 ; RET = 1.0890833 1.213667 1.234583 ; ENDDATA !----------------------------------------------------------; ! Get the s.d. corresponding to this risk threshold; PROB = @PSN( Z); @FREE( Z); ! Generally, Z < 0; ! Maximize value not at risk, note Z < 0; [VAR] MAX = ARET + Z * RISK; ! Use exactly 100% of the starting budget; @SUM( STOCKS: AMT) = STARTW; ! Expected terminal value; ARET = @SUM( STOCKS: AMT * RET) ; ! This is a second order cone constraint, and thus tends to solve fast; ! In squared form; @SUM( COVMAT(I, J): AMT(I) * AMT(J) * VARIANCE(I, J)) <= SD^2 ; ! In squared form using an "=" constraint. The "<=" relaxation is SOC; ! @SUM( COVMAT(I, J): AMT(I) * AMT(J) * VARIANCE(I, J)) = SD^2 ; ! In square root form; ! (@SUM( COVMAT(I, J): AMT(I) * AMT(J) * VARIANCE(I, J)))^0.5 <= SD; ! Measure risk by standard deviation; RISK = SD; ! Measure risk by variance rather than SD. This is a "rotated" SOC; ! @SUM( COVMAT(I, J): AMT(I) * AMT(J) * VARIANCE(I, J)) <= RISK; END