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;
 SETS:
  STOCKS/ATT, GMC, USX/: AMT, RET;
  COVMAT(STOCKS, STOCKS): VARIANCE;
 ENDSETS
 DATA:
    STARTW = 1.0;  ! How much we start with;
      PROB = .05;! Risk threshold, must be < .5;
!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);
! Maximize value not at risk, note Z < 0;
[VAR] Max = ARET + Z * SD;

!  Use exactly 100% of the starting budget;
     @SUM( STOCKS: AMT) = STARTW;

! Expected terminal value;
  ARET = @SUM( STOCKS: AMT * RET) ;

! Compute standard deviation;
  SD = (@SUM( COVMAT(I, J): AMT(I) * AMT(J) * VARIANCE(I, J)))^.5;
END
