Hi, I am using the following code to minimize the variance of the following optimization problem;
min VAR(R.f - SUM[w_i * R.s_i]) = min VAR(F - w*S) s.t. SUM(w_i) = 1; w_i > 0 where: R.f Fund returns R.s Style returns w_i Style weights
I am using the following code for this. This code works perfectly fine, but I want to run this using a by variable (by permno). When I add permno to my data, it tends to calculate treat it as a dependent variable but rather I want to use it as a by variable only.
Any suggestions on how to modify this and run my optimization using by variables?
proc corr data=return1 (drop=date) out=corrout(where=(_type_ ne 'CORR')) cov noprint; run; data stats(drop=_name_); set corrout; if _type_ = 'COV' then delete; run; proc transpose data=stats out=stats; id _type_; run; proc optmodel; /* declare parameters and read data */ set <str> ASSETS; str target = 'f'; set BENCH = ASSETS diff {target}; num cov {ASSETS, ASSETS}; read data stats into ASSETS=[_name_]; read data corrout(where=(_type_='COV')) into [_name_] {i in ASSETS} <cov[_name_,i]=col(i)>; /* let w1, w2, w3, w4 be the amount invested in each asset */ var x{1..4} >= 0; /* declare optimization model */ var W {BENCH} >= 0 <= 1; /* Var(X - Y) = Var(X) + Var(Y) - 2 Cov(X,Y) */ min Variance = sum {i in BENCH, j in BENCH} cov[i,j] * W[i] * W[j] + cov[target,target] - 2 * sum {i in BENCH} cov[i,target] * W[i]; /* subject to the following constraints */ con weights: sum {i in BENCH} W[i] = 1; /* call solver and print optimal solution */ solve; print W; quit;
This Usage Note illustrates how to implement BY-group processing in PROC OPTMODEL:
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.