(!****************************************************** Mosel Example Problems ====================== file foliograph.mos ``````````````````` Modeling a small LP problem to perform portfolio optimization. -- Re-solving with varied parameter settings, graphical solution display -- (c) 2003 Dash Associates author: S. Heipcke *******************************************************!) model "Portfolio optimization with LP" uses "mmxprs", "mmive" ! Use Xpress-Optimizer with IVE graphing parameters DATAFILE= "folio.dat" ! File with problem data DEVDATA= "foliodev.dat" ! File with deviation data MAXVAL = 0.3 ! Max. investment per share MINAM = 0.5 ! Min. investment into N.-American values end-parameters declarations SHARES: set of string ! Set of shares RISK: set of string ! Set of high-risk values among shares NA: set of string ! Set of shares issued in N.-America RET: array(SHARES) of real ! Estimated return in investment DEV: array(SHARES) of real ! Standard deviation SOLRET: array(range) of real ! Solution values (total return) SOLDEV: array(range) of real ! Solution values (average deviation) end-declarations initializations from DATAFILE RISK RET NA end-initializations initializations from DEVDATA DEV end-initializations declarations frac: array(SHARES) of mpvar ! Fraction of capital used per share Return, Risk: linctr end-declarations ! Objective: total return Return:= sum(s in SHARES) RET(s)*frac(s) ! Minimum amount of North-American values sum(s in NA) frac(s) >= MINAM ! Spend all the capital sum(s in SHARES) frac(s) = 1 ! Upper bounds on the investment per share forall(s in SHARES) frac(s) <= MAXVAL ! Solve the problem for different limits on high-risk shares ct:=0 forall(r in 0..20) do ! Limit the percentage of high-risk values Risk:= sum(s in RISK) frac(s) <= r/20 maximize(Return) ! Solve the problem if (getprobstat = XPRS_OPT) then ! Save the optimal solution value ct+=1 SOLRET(ct):= getobjval SOLDEV(ct):= getsol(sum(s in SHARES) DEV(s)*frac(s)) else writeln("No solution for high-risk values <= ", 100*r/20, "%") end-if end-do ! Drawing a graph to represent results (`plot1') and data (`plot2' & `plot3') declarations plot1, plot2, plot3: integer end-declarations plot1 := IVEaddplot("Solution values", IVE_BLACK) plot2 := IVEaddplot("Low risk", IVE_YELLOW) plot3 := IVEaddplot("High risk", IVE_RED) forall(r in 1..ct) IVEdrawpoint(plot1, SOLRET(r), SOLDEV(r)); forall(r in 2..ct) IVEdrawline(plot1, SOLRET(r-1), SOLDEV(r-1), SOLRET(r), SOLDEV(r)) forall (s in SHARES - RISK) do IVEdrawpoint(plot2, RET(s), DEV(s)) IVEdrawlabel(plot2, RET(s)+3.4, 1.3*(DEV(s)-1), s) end-do forall (s in RISK) do IVEdrawpoint(plot3, RET(s), DEV(s)) IVEdrawlabel(plot3, RET(s)-2.5, DEV(s)-2, s) end-do end-model