Markowitz Efficient Frontier - The Model

Here’s the model we will use to generate points along the efficient frontier:

MODEL:

! Solves the generic Markowitz portfolio

 model in a loop to generate the points

 on the efficient frontier;

SETS:

  ASSET: RATE, UB, X;

  COVMAT( ASSET, ASSET): V;

  POINTS: XRET, YVAR;

ENDSETS

 

DATA:

! Number of points on the

  efficient frontier graph;

 NPOINTS = 10;

 POINTS = 1..NPOINTS;

! The stocks;

 ASSET = GOOGLE, YAHOO, CISCO;

! Expected growth rate of each asset;

 RATE = 1.3   1.2  1.08;

! Upper bound on investment in each;

 UB   = .75   .75   .75;

! Covariance matrix;

 V    =   3     1   -.5

          1     2   -.4

        -.5   -.4     1;

ENDDATA

 

! Below are the three objectives we'll use;

SUBMODEL SUB_RET_MAX:

  [OBJ_RET_MAX] MAX = RETURN;

ENDSUBMODEL

 

SUBMODEL SUB_RET_MIN:

  [OBJ_RET_MIN] MIN = RETURN;

ENDSUBMODEL

 

SUBMODEL SUB_MIN_VAR:

  [OBJ_MIN_VAR] MIN =

   @SUM( COVMAT( I, J): V( I, J) * X( I) * X( J));

ENDSUBMODEL

 

!and the constraints;

SUBMODEL SUB_CONSTRAINTS:

  ! Compute return;

  RETURN = @SUM( ASSET: RATE * X);

  ! Must be fully invested;

  @SUM( ASSET: X) = 1;

  ! Upper bounds on each;

  @FOR( ASSET: @BND( 0, X, UB));

  ! Must achieve target return;

  RETURN >= RET_LIM;

ENDSUBMODEL

 

CALC:

! Set some parameters;

  ! Reset all params;

  @SET( 'DEFAULT');

  ! Minimize output;

  @SET( 'TERSEO', 1);

  ! Suppress status window;

  @SET( 'STAWIN', 0);

 

! Capture unwanted output;

  @DIVERT( 'LINGO.LOG');

 

! Solve to get maximum return;

  RET_LIM = 0;

  @SOLVE( SUB_RET_MAX, SUB_CONSTRAINTS);

 

! Save maximum return;

  RET_MAX = OBJ_RET_MAX;

 

! Solve to get minimum return;

  @SOLVE( SUB_RET_MIN, SUB_CONSTRAINTS);

 

! Save minimum return;

  RET_MIN = OBJ_RET_MIN;

 

! Interval between return points;

  INTERVAL =

   ( RET_MAX - RET_MIN) / ( NPOINTS-1);

 

! Loop over range of possible returns

 minimizing variance;

  RET_LIM = RET_MIN;

  @FOR( POINTS( I):

     @SOLVE( SUB_MIN_VAR, SUB_CONSTRAINTS);

     XRET( I) = RET_LIM;

     YVAR( I) = OBJ_MIN_VAR;

     RET_LIM = RET_LIM + INTERVAL;

  );

 

! Close log file;

  @DIVERT();

 

! Display the results;

  @WRITE( '     Return     Variance', @NEWLINE( 1));

  @FOR( POINTS: @WRITE( @FORMAT( XRET, '#12.6G'),

   @FORMAT( YVAR, '#12.6G'), @NEWLINE( 1))

  );

ENDCALC
END

Model: LOOPPORT