Lindo Systems
    MODEL:
! Markowitz portfolio Matching model   (PortMatch);
! We want to match the first or "benchmark" asset
  with the remaining ones;
! Keywords: Hedging, Markowitz, Matching, Portfolio optimization;
 SETS:
  ASSET: RET, X;
  TMAT( ASSET, ASSET) | &1 #GE# &2: COV;
 ENDSETS
 DATA:
  ASSET=  SP500     ATT       GMC       USX;
! The expected returns;
   RET = 1.191458  1.089083, 1.21367, 1.23458;
! Covariance matrix;
   COV =
       .02873661
       .01266498   .01080754
       .03562763   .01240721   .05839170
       .04378880   .01307513   .05542639   .09422681;
 ! The desired return;
   TARGET = 1.191458;
 ENDDATA
!-------------------------------------------------;
!  Min the var in portfolio return;
 [OBJ] MIN = (@SUM( ASSET(I): COV(I, I) * X( I)^2)
         + 2 * @SUM( TMAT( I, J) | I #NE# J:
                     COV( I, J) * X( I) * X( J))) ;
!Matching is equivalent to being short the benchmark;
   X( 1) = -1;
   @FREE( X( 1));
!  Budget constraint(applies to remaining assets);
 [BUDGET] @SUM( ASSET( I)| I #GT# 1: X( I)) = 1;
!  Return requirement(applies to remaining assets);
 [RETURN] @SUM( ASSET( I)| I #GT# 1:
                       RET( I) * X( I)) >= TARGET;
END