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, featuresDifficulty
H‑1 Choice of loans *
calculation of net present value
H‑2 Publicity campaign *
forall-do
H‑3 Portfolio selection **
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 **
experiment with solutions: solve LP problem explicitly, ``round'' some almost integer variable and re-solve
H‑7 Mean variance portfolio selection: Quadratic Programming problem ***
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
   
   (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