(!****************************************************** Mosel QP Examples ================= file portf1.mos ``````````````` Portfolio Management. (c) 2002 Dash Associates author: S. Heipcke *******************************************************!) model "Portfolio" uses "mmxprs","mmquad","mmetc" declarations NVAL = 30 ! Total number of values RV = 1..NVAL LIMIT = 20 ! Maximum number to be chosen LCOST: array(RV) of real ! Coeff. of lin. part of the obj. QCOST: array(RV,RV) of real ! Coeff. of quad. part of the obj. UBND: array(RV) of real ! Upper bound values x: array(RV) of mpvar ! Amount of value taken into the portfolio y: array(RV) of mpvar ! 1 if value i is chosen, else 0 Cost: qexp ! Objective function end-declarations diskdata(ETC_SPARSE, "pfubds.dat", UBND) diskdata(ETC_SPARSE, "pflcost.dat", LCOST) diskdata(ETC_SPARSE, "pfqcost.dat", QCOST) Cost:= sum(i in RV) ( LCOST(i)*x(i) + QCOST(i,i)*x(i)^2 + sum(j in i+1..NVAL) QCOST(i,j)*x(i)*x(j) ) ! Amounts of values chosen must add up to 100% sum(i in RV) x(i) = 100 ! Upper limits forall(i in RV) do x(i) <= UBND(i)*y(i) x(i) <= UBND(i) y(i) is_binary end-do ! Limit on total number of values sum(i in RV) y(i) <= LIMIT ! exportprob(EP_MIN, "portf.lp", Cost) ! exportprob(EP_MPS, "portf.mat", Cost) minimize(Cost) writeln("Solution: ", getobjval) forall(i in RV) if(getsol(y(i))>0) then writeln(i, ": ", getsol(x(i))) end-if end-model