$title Standard QP Model (QP1,SEQ=171): Modified for risk/return balance $Ontext The first in a series of variations on the standard QP formulation. The subsequent models exploit data and problem structures to arrive at formulations that have sensational computational advantages. Additional information can be found at: http://www.gams.com/modlib/adddocs/qp1doc.htm Brooke, A, Kendrick, D, and Meeraus, A, GAMS: A User's Guide. The Scientific Press, Redwood City, California, 1988. This version is modified to make the objective function a tradeoff between risk and return, where return is quantified by the mean of the portfolio and risk by its variance. A nonnegative parameter rho is used to weight these two objective. Smaller values of rho place more weight on reducing risk; larger values place more weight on increasing return. Good values to try are rho=0.1, 1.0, 10. $Offtext option limrow=0, limcol=0; $include qpdata.inc scalar rho /.1/; set d(days) selected days s(stocks) selected stocks alias(s,t); set properties /avReturn, variance/; * setect subset of stocks and periods d(days) = ord(days) >1 and ord(days) < 31; s(stocks) = ord(stocks) < 51; parameter mean(stocks) mean of daily return dev(stocks,days) deviations covar(stocks,sstocks) covariance matrix of returns (upper) meanvar(stocks,properties) mean and var of each stock totmean total mean return; mean(s) = sum(d, return(s,d))/card(d); dev(s,d) = return(s,d)-mean(s); * calculate covariance * to save memory and time we only compute the uppertriangular * part as the covariance matrix is symmetric covar(upper(s,t)) = sum(d, dev(s,d)*dev(t,d))/(card(d)-1); * fill out the properties of each stock and print meanvar(stocks,'avReturn') = mean(stocks); meanvar(stocks,'variance') = covar(stocks,stocks); display meanvar; totmean = sum(s, mean(s))/(card(s)); variables z objective x(stocks) investments ; positive variables x; equations obj objective budget ; obj.. z =e= rho * sum(s, mean(s)*x(s)) - 0.5 * (sum(upper(s,t), x(s)*covar(s,t)*x(t)) + sum(lower(s,t), x(s)*covar(t,s)*x(t))); budget.. sum(s, x(s)) =e= 1.0; model qp1 /all/; solve qp1 using nlp maximizing z; display x.l; scalar meanFinal, varFinal; meanFinal = sum(s, mean(s)*x.l(s)); varFinal = sum(upper(s,t), x.l(s)*covar(s,t)*x.l(t)) + sum(lower(s,t), x.l(s)*covar(t,s)*x.l(t)); display meanFinal, varFinal, z.l;