FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Economics and finance

Description
Problem name and type, featuresDifficultyRelated examples
H‑1 Choice of loans *
calculation of net present value
H‑2 Publicity campaign *
forall-do
H‑3 Portfolio selection ** h7qportf.mos
sets of integers, second formulation with semi-continuous, parameters
H‑4 Financing an early retirement scheme **
inline if, selection with `|'
H‑5 Family budget **
formulation of monthly balance constraints including different payment frequencies; as, mod, inline if, selection with `|'
H‑6 Choice of expansion projects ** capbgt_graph.mos
experiment with solutions: solve LP problem explicitly, ``round'' some almost integer variable and re-solve
H‑7 Mean variance portfolio selection: Quadratic Programming problem *** folioqp_graph.mos
parameters, forall-do, min, max, loop over problem solving


Further explanation of this example: 'Applications of optimization with Xpress-MP', Chapter 13: Economics and finance problems

mosel_app_8.zip[download all files]

Source Files

Data Files





h7qportf.mos

(!******************************************************
   Mosel Example Problems
   ======================

   file h7qportf.mos
   `````````````````
   Mean-variance portfolio selection
  
   An investor considers 4 different securities to invest 
   capital. The mean yield on each invested dollar in each
   of the securities is known. The investor gets estimates 
   of the variance/covariance matrix of estimated returns 
   on the securities. What fraction of the total capital 
   should be invested in each security? 
   
   Two problem variants are proposed. Problem 1: Which 
   investment strategy should the investor adopt to minimize 
   the variance subject to getting some specified minimum 
   target yield?  Problem 2: Which is the least variance 
   investment strategy if the investor wants to choose 
   at most two different securities (again subject to 
   getting some specified minimum target yield)?
   
   For problem 1, a quadratic program (quadratic objective 
   function subject to linear constraints and continuous 
   variables) is presented. For problem 2, the model is 
   extended by introducing binary decision variables leading 
   to a Mixed Integer Quadratic Program. The module 'mmnl' 
   is used in both cases to handle such a quadratic (non-
   linear) feature.

   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Aug. 2002, rev. Sep. 2017
*******************************************************!)

model "H-7 QP Portfolio"
 uses "mmxprs", "mmnl"

 parameters
  TARGET = 7.0                      ! Minimum target yield
  MAXASSETS = 4                     ! Maximum number of assets in portfolio
 end-parameters 

 declarations
  SECS = 1..4                       ! Set of securities
  
  RET: array(SECS) of real          ! Expected yield of securities
  VAR: array(SECS,SECS) of real     ! Variance/covariance matrix of
                                    ! estimated returns

  frac: array(SECS) of mpvar        ! Fraction of capital used per security
 end-declarations

 initializations from 'h7qportf.dat'
  RET VAR
 end-initializations

! **** First problem: unlimited number of assets ****

! Objective: mean variance
 Variance:=  sum(s,t in SECS) VAR(s,t)*frac(s)*frac(t)

! Spend all the capital
 sum(s in SECS)  frac(s) = 1
 
! Target yield
 sum(s in SECS) RET(s)*frac(s) >=  TARGET

! Solve the problem
 minimize(Variance)
 
! Solution printing
 declarations
  NAMES: array(SECS) of string
 end-declarations
 
 initializations from 'h7qportf.dat'   ! Get the names of the assets
  NAMES
 end-initializations

 writeln("With a target of ", TARGET, " minimum variance is ", getobjval)
 forall(s in SECS) writeln(NAMES(s), ": ", getsol(frac(s))*100, "%")  

! **** Second problem: limit total number of assets ****
 declarations
  buy: array(SECS) of mpvar         ! 1 if asset is in portfolio, 0 otherwise
 end-declarations

! Limit the total number of assets
 sum(s in SECS) buy(s) <= MAXASSETS

 forall(s in SECS) do
  buy(s) is_binary
  frac(s) <= buy(s)
 end-do
   
! Solve the problem
 minimize(Variance)

 writeln("With a target of ", TARGET," and at most ", MAXASSETS,
          " assets, minimum variance is ", getobjval)
 forall(s in SECS) writeln(NAMES(s), ": ", getsol(frac(s))*100, "%") 

end-model

Back to examples browserPrevious exampleNext example