BookmarkSubscribeRSS Feed
Alain38
Quartz | Level 8

Dear all,

I would like to run the following optimization process with IML:

 

proc optmodel;
	var W{1..6};

	num MVC{1..6, 1..6} = [0.00111	0.00069	0.00073	0.00053	0.00070	0.00123
		  	       0.00069	0.00081	0.00070	0.00043	0.00064	0.00117
		   	       0.00073	0.00070	0.00091	0.00050	0.00075	0.00126
		   	       0.00053	0.00043	0.00050	0.00133	0.00120	0.00185
		   	       0.00070	0.00064	0.00075	0.00120	0.00164	0.00238
		   	       0.00123	0.00117	0.00126	0.00185	0.00238	0.00430];
	num E{1..6} = [0.00690 0.00360 0.00138 -0.00169 0.00436 -0.01439];
	num Var_Rm = 0.001483;

	maximize Expected = sum{i in 1..6}W[i]*E[i];
	con sum{i in 1..6, j in 1..6}W[i]*MVC[i,j]*W[j] = Var_Rm;
	con BUDGET: sum{i in 1..6}W[i] = 1;

	solve; print W;
quit;

Ideally something simple in a first time like:

 

proc iml;
MVC = { 0.00111	0.00069	0.00073	0.00053	0.00070	0.00123
	    0.00069	0.00081	0.00070	0.00043	0.00064	0.00117
	    0.00073	0.00070	0.00091	0.00050	0.00075	0.00126
	    0.00053	0.00043	0.00050	0.00133	0.00120	0.00185
	    0.00070	0.00064	0.00075	0.00120	0.00164	0.00238
	    0.00123	0.00117	0.00126	0.00185	0.00238	0.00430 };
e = { 0.00690 0.00360 0.00138 -0.00169 0.00436 -0.01439 }
Var_Rm = { 0.001483 };

start max(w);
	w = p`; /* Transpose w into a colum vector, the NLP routines passing in a row vector as the parameter */
   return e * w;
finish;

/* specify linear constraints ????  */
con w` * MVC * w = Var_Rm;
con sum(w) = 1;

w0 = {0.17 0.17 0.17 0.17 0.17 0.15};
optn = { ?????? }

call nlpnra(rc, w_Opt, "max", w0, optn, con);
maxVal = max(w_Opt);

print w_Opt;
quit;

Thank you in advance for any help,

2 REPLIES 2
Rick_SAS
SAS Super FREQ

The constraint on the variance is not a linear constraint. It is quadratic. Therefore, you have to use a user-defined function module for that constraint. You can use a GLOBAL clause for the MVC and Var_Rm parameters and compute the constraint as  

conVar = w * MVC * w` - Var_Rm;  /* constrain this eqn to 0 */

Because you have a nonlinear constraint, you need to use the NLPQN (quasi-Newton) method instead of the Newton-Raphson function in your original post.

 

The SAS/IML documentation has a four-parameter example that is similar to your six-parameter problem. See the Getting Started example for the "Rosen-Suzuki Problem."

 

In addition to the linear constraint sum(w)=1, you should also specify the bounds  0 <= w[i] <= 1.

 

Ksharp
Super User

@Rick_SAS  already gave you an example , in IML there is an build-in function can solve this kind of question.

Or check  my paper :

 

"Get Tangency Portfolio by SAS/IML"
http://support.sas.com/resources/papers/proceedings17/0997-2017.pdf

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 435 views
  • 7 likes
  • 3 in conversation