```01: // --------------------------------------------------------------------------
02: // Licensed Materials - Property of IBM
03: //
04: // 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55
06: //
07: // Note to U.S. Government Users Restricted Rights:
08: // Use, duplication or disclosure restricted by GSA ADP Schedule
09: // Contract with IBM Corp.
10: // --------------------------------------------------------------------------
11:
12: /******************************************************************************
13:  *
14:  * OPL Model for Investment Portfolio Problem
15:  *
16:  * Charles H. Rosa
17:
18:  * This model is described in the documentation.
19:  * See IDE and OPL > Language and Interfaces Examples.
20:  *
21: ******************************************************************************/
22:
23: {string} Investments = ...;
24: float Return[Investments] = ...;
25: float Covariance[Investments][Investments] = ...;
26: float Wealth = ...;
27: float Rho = ...;  // Variance Penalty (increasing rho from 0.001 to 1.0
28:                   //                   produces a distribution of funds
29:                   //                   with smaller and smaller variability).
30:
31: /******************************************************************************
32:  * MODEL DECLARATIONS
33:  ******************************************************************************/
34:
35: range float FloatRange = 0.0..Wealth;
36:
37: dvar float  Allocation[Investments] in FloatRange;  // Investment Level
38:
39:
40: /******************************************************************************
41:  * MODEL
42:  ******************************************************************************/
43:
44: dexpr float Objective =
45:   (sum(i in Investments) Return[i]*Allocation[i])
46:     - (Rho/2)*(sum(i,j in Investments) Covariance[i][j]*Allocation[i]*Allocation[j]);
47:
48: maximize Objective;
49:
50: subject to {
51:   // sum of allocations equals amount to be invested
52:   allocate: (sum (i in Investments) (Allocation[i])) == Wealth;
53: }
54:
55: tuple AllocationSolutionT{
56:         string Investments;
57:         float value;
58: };
59: {AllocationSolutionT} AllocationSolution = {<i0,Allocation[i0]> | i0 in Investments};
60:
61:
62: float TotalReturn = sum(i in Investments) Return[i]*Allocation[i];
63: float TotalVariance = sum(i,j in Investments) Covariance[i][j]*Allocation[i]*Allocation[j];
64:
65: execute DISPLAY {
66:   writeln("Total Expected Return: ", TotalReturn);
67:   writeln("Total Variance       : ", TotalVariance);
68: }
```