!Keywords: Downside Risk / Financial / Markowitz / Portfolio / Semi-Variance / Stocks;
! Minimize the semivariance
! The MIN row simply gives the order of the
! primal variables...;
 MIN Y1 + Y2 + Y3 + Y4  + Y5  + Y6 
   + Y7 + Y8 + Y9 + Y10 + Y11 + Y12
   + ATT + GMC + USX + MEAN 
! and the dual/price variables;
   + PS1 + PS2 + PS3 + PS4  + PS5  + PS6
   + PS7 + PS8 + PS9 + PS10 + PS11 + PS12
   + PBUD + PDEF + PRET 
  Subject to
! The first order conditions on the Y's
 FY1) .1666666 Y1 - PS1 >= 0 
 FY2) .1666666 Y2 - PS2 >= 0 
 FY3) .1666666 Y3 - PS3 >= 0 
 FY4) .1666666 Y4 - PS4 >= 0 
 FY5) .1666666 Y5 - PS5 >= 0 
 FY6) .1666666 Y6 - PS6 >= 0 
 FY7) .1666666 Y7 - PS7 >= 0 
 FY8) .1666666 Y8 - PS8 >= 0 
 FY9) .1666666 Y9 - PS9 >= 0 
 FY10) .1666666 Y10 - PS10 >= 0 
 FY11) .1666666 Y11 - PS11 >= 0 
 FY12) .1666666 Y12 - PS12 >= 0 
! First order conditions on the investments; 
 FATT) - 1.3 PS1   - 1.103 PS2 - 1.216 PS3 - 0.954 PS4
       - 0.929 PS5 - 1.056 PS6 - 1.038 PS7 - 1.089 PS8
       - 1.09 PS9  - 1.083 PS10 - 1.035 PS11 - 1.176 PS12
       + PBUD + 1.089083 PDEF >= 0
 FGMC) - 1.225 PS1 - 1.29 PS2  - 1.216 PS3 - 0.728 PS4
       - 1.144 PS5 - 1.107 PS6 - 1.321 PS7 - 1.305 PS8
       - 1.195 PS9 - 1.39 PS10 - 0.928 PS11 - 1.715 PS12
       + PBUD  + 1.213667 PDEF >= 0
 FUSX) - 1.149 PS1 - 1.26 PS2  - 1.419 PS3 - 0.922 PS4
       - 1.169 PS5 - 0.965 PS6 - 1.133 PS7 - 1.732 PS8
       - 1.021 PS9 - 1.131 PS10 - 1.006 PS11 - 1.908 PS12 
       + PBUD + 1.234583 PDEF >= 0
! First order conditions on the mean;
 FMEAN) + PS1  + PS2  + PS3  + PS4 + PS5 + PS6 + PS7 + PS8 
        + PS9  + PS10 + PS11 + PS12 - PDEF - PRET >= 0
! Here are the real constraints, compute Y, the deviation 
!   below target, for each scenario;
 S1)   Y1 + 1.3   ATT + 1.225 GMC + 1.149 USX - MEAN >= 0
 S2)   Y2 + 1.103 ATT + 1.29  GMC + 1.26  USX - MEAN >= 0
 S3)   Y3 + 1.216 ATT + 1.216 GMC + 1.419 USX - MEAN >= 0
 S4)   Y4 + 0.954 ATT + 0.728 GMC + 0.922 USX - MEAN >= 0
 S5)   Y5 + 0.929 ATT + 1.144 GMC + 1.169 USX - MEAN >= 0
 S6)   Y6 + 1.056 ATT + 1.107 GMC + 0.965 USX - MEAN >= 0
 S7)   Y7 + 1.038 ATT + 1.321 GMC + 1.133 USX - MEAN >= 0
 S8)   Y8 + 1.089 ATT + 1.305 GMC + 1.732 USX - MEAN >= 0
 S9)   Y9 + 1.09  ATT + 1.195 GMC + 1.021 USX - MEAN >= 0
 S10) Y10 + 1.083 ATT + 1.39  GMC + 1.131 USX - MEAN >= 0
 S11) Y11 + 1.035 ATT + 0.928 GMC + 1.006 USX - MEAN >= 0
 S12) Y12 + 1.176 ATT + 1.715 GMC + 1.908 USX - MEAN >= 0
! The Budget constraint;
BUD) ATT + GMC + USX = 1
! compute the mean;
 DEF) 1.089083 ATT + 1.213667 GMC + 1.234583 USX - MEAN = 0
! The target Return constraint;
RET) MEAN >= 1.15
END
! Tell LINDO that this is a quadratic problem with 
!  first real constraint being row 18;
QCP 18