Dear all, I would like to solve an optimization problem, every month and over many decades. The parameters are determined beforehand with PROC IML and consist of a matrix called "MVC", which represents the covariance matrix of stock returns. The difficulty is that each month, not only the stocks can be different, but also their number (e.g. month 1: stocks A, B, C; month 2: stocks A, C, D, E, F). Nonetheless, I could standardize the names of the stocks (let say: month1: 1,2,3; month2: 1,2,3,4,5) to append the MVC for each month, one under the other, even if they have different sizes (until this point I would manage to do it). Then, the idea would be to create a temporary dataset including solely one MVC at a time to run the optimization problem, in the spirit of rolling-window regressions: data Work.Rwin(keep= Y X1 X2 X3 X4) / view=Work.Rwin;
do grp = 0 to nrecs-60;
do j = 1 + grp to 60 + grp;
set Work.Sample nobs=nrecs point=j;
output;
end;
end;
stop;
run;
proc reg data=Work.Rwin outest=Work.Coeff noprint;
by grp;
model Y = X1 X2 X3 X4;
run;
quit; the additional difficulty of course being that the number of observations is different for each group (grp), but hopefully could be determined thanks to the standardized name (1, 2, ..., N with N different for each grp). The optimization code is the following: ods select none; *Output weights without printing;
proc optmodel ;
ods output PrintTable=Work.Weights; /* Output results */
/* Declare the sets of parameters and data indexed by sets */
set <string> Assets; /* Stock names defined in the set "Assets" */
number MVC{Assets, Assets}; /* MVC data indexed by the set "Assets" */
/* Populate the model by reading in the specific data instance */
read data Work.MVC into Assets=[Name]; /* Read from the variable "Name" in Work.MVC */
read data Work.MVC into [i=Name] {j in Assets} <MVC[i,j]=col(j)>;
/* Declare the variable */
var W{Assets} >= 0; /* Positive weights constraint */
/* Minimize the objective function (variance of the portfolio) */
minimize Variance = sum{i in Assets, j in Assets}W[i]*MVC[i,j]*W[j];
/* Subject to the following constraints */
con BUDGET: sum{i in Assets}W[i] = 1;
solve with qp;
print W; /* print the optimal solution */
quit;
ods select all; Results (vectors of weights) would be all output in the same dataset. What do you think of this solution and if it is the best way to do, could you please help me implement it? Otherwise, how could I proceed? I considered for example running the optimization problem directly in IML but I read on this forum that PROC OPTMODEL, being specifically designed for it, is the procedure to use for this kind of problems rather than a simple home-made IML program. There may be also much simpler solutions that I haven't thought about, so any suggestion most welcomed, as well as assistance for writing the code,
... View more