 FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home   Economics and finance

Description
H‑1 H‑2 H‑3 Problem name and type, features Difficulty Choice of loans * calculation of net present value Publicity campaign * forall-do Portfolio selection ** sets of integers, second formulation with semi-continuous, parameters Financing an early retirement scheme ** inline if, selection with `|' Family budget ** formulation of monthly balance constraints including different payment frequencies; as, mod, inline if, selection with `|' Choice of expansion projects ** experiment with solutions: solve LP problem explicitly, ``round'' some almost integer variable and re-solve 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

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   