<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Assistance with PROC OPTMODEL in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529262#M2552</link>
    <description>&lt;P&gt;If you want RC to depend on the variable W, you should declare it as an IMPVAR instead of a NUM.&amp;nbsp; Also, your&amp;nbsp;algebraic expression for RC does not match the IML matrix multiplication.&amp;nbsp; Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;impvar RC{k in 1..4} = W[k] * (sum{j in 1..4}MVC[k,j]*W[j]) / sqrt(sum{i in 1..4, j in 1..4} W[i]*MVC[i,j]*W[j]);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The objective should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;minimize f = sum{i in 1..4, j in 1..4 diff {i}}(RC[i] - RC[j])^2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Equivalently:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;minimize f = sum{i in 1..4, j in 1..4: i ne j}(RC[i] - RC[j])^2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To initialize to equal values, do this before the solver call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;num n = 4;
for {i in 1..n} W[i] = 1/n;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, the SQP solver was retired as of SAS 9.3 in July 2011.&amp;nbsp; You can just do this to invoke the NLP solver:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;solve;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With these changes (and with or without initializing W), the resulting solution matches your Excel output:&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;[1]&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;W&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.31337&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;0.17488&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.13054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;0.38121&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jan 2019 21:01:16 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2019-01-22T21:01:16Z</dc:date>
    <item>
      <title>Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529007#M2550</link>
      <description>&lt;P&gt;Hello everyone,&lt;BR /&gt;While still practicing with proc optmodel, I tried to build a simple portfolio where each asset contributes equally to the portfolio risk.&lt;BR /&gt;The risk contribution (RC) of an asset depending on its weight, the problem is endogeneous. The authors of this methodology recommend to use a sequential quadratic programming algorithm and minimize the total squared differences between the RC of all pairs of assets. Everything is wrote here after in IML (optimal weights were found using Excel Solver), but my PROC OPTMODEL does not work. Perhaps the problem comes from the fact that the optimal solution W is not directly in the objective function?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	MVC = {0.0225 0.015 0 -.0015, 0.015  0.04  0.012 0.008,
		   0 0.012 0.09 0.021, -.0015 0.008 0.021 0.01};
	W = {0.31337624982391 0.174869881146739 0.130532835089507 0.381221033939844}; /* Results from Excel solver */
	RC = W` # ((MVC * W`) / sqrt(W * MVC * W`)); print RC;

/* Risk Contribution of the 1st Asset */
	i = 1;
	Element1 = MVC[i,1]*W[,1] + MVC[i,2]*W[,2] + MVC[i,3]*W[,3] + MVC[i,4]*W[,4];
	Var1 = W[,1]*MVC[1,1]*W[,1] + W[,1]*MVC[1,2]*W[,2] + W[,1]*MVC[1,3]*W[,3] + W[,1]*MVC[1,4]*W[,4]
		 + W[,2]*MVC[2,1]*W[,1] + W[,2]*MVC[2,2]*W[,2] + W[,2]*MVC[2,3]*W[,3] + W[,2]*MVC[2,4]*W[,4]
		 + W[,3]*MVC[3,1]*W[,1] + W[,3]*MVC[3,2]*W[,2] + W[,3]*MVC[3,3]*W[,3] + W[,3]*MVC[3,4]*W[,4]
		 + W[,4]*MVC[4,1]*W[,1] + W[,4]*MVC[4,2]*W[,2] + W[,4]*MVC[4,3]*W[,3] + W[,4]*MVC[4,4]*W[,4];
	RC1 = W[,i] * ((Element1) / sqrt(Var1)); print RC1;

/* Objective function */
	f =  (RC[1,]-RC[2,])##2 + (RC[1,]-RC[3,])##2 + (RC[1,]-RC[4,])##2
	   + (RC[2,]-RC[1,])##2 + (RC[2,]-RC[3,])##2 + (RC[2,]-RC[4,])##2
	   + (RC[3,]-RC[1,])##2 + (RC[3,]-RC[2,])##2 + (RC[3,]-RC[4,])##2
	   + (RC[4,]-RC[1,])##2 + (RC[4,]-RC[2,])##2 + (RC[4,]-RC[3,])##2;

/* Sanity check */
	RC2 = sqrt(W * MVC * W`)/ncol(MVC);
	/* RC of each asset should be equal to portfolio risk divided by the number of assets */
quit;

proc optmodel ;
/* Declare the variable */
	var W{1..4} &amp;gt;= 0; /* Long-only constraint */

/* Populate the model by reading in the specific data instance */
	number MVC{1..4, 1..4} = [0.0225 0.015 0     -.0015 
							  0.015  0.04  0.012 0.008 
							  0		 0.012 0.09  0.021 
							  -.0015 0.008 0.021 0.01];

	number RC{1..4}; for {k in 1..4} RC[k] = sum{i in 1..4, j in 1..4}W[k] * ((MVC[k,j]*W[j]) / sqrt(W[i]*MVC[i,j]*W[j]));

/* Minimize the objective function (total squared differences between the RC of all pairs of assets) */
	minimize f = sum{i in 1..4}(RC[i] - RC[i])^2;

/* Subject to the following constraints */
	con BUDGET: sum{i in 1..4}W[i] = 1;

/* Starting points */
	W[1] = 0.25; W[2] = 0.25; W[3] = 0.25; W[4] = 0.25;

	solve with sqp;
	print W;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Could you please help me make it work, and how could I replace the starting points (equal weights) with something more generic like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;for {i in 1..4} W[i] = 1/_N_&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Thank you very much in advance for your help,&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 10:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529007#M2550</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-01-22T10:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529262#M2552</link>
      <description>&lt;P&gt;If you want RC to depend on the variable W, you should declare it as an IMPVAR instead of a NUM.&amp;nbsp; Also, your&amp;nbsp;algebraic expression for RC does not match the IML matrix multiplication.&amp;nbsp; Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;impvar RC{k in 1..4} = W[k] * (sum{j in 1..4}MVC[k,j]*W[j]) / sqrt(sum{i in 1..4, j in 1..4} W[i]*MVC[i,j]*W[j]);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The objective should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;minimize f = sum{i in 1..4, j in 1..4 diff {i}}(RC[i] - RC[j])^2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Equivalently:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;minimize f = sum{i in 1..4, j in 1..4: i ne j}(RC[i] - RC[j])^2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To initialize to equal values, do this before the solver call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;num n = 4;
for {i in 1..n} W[i] = 1/n;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, the SQP solver was retired as of SAS 9.3 in July 2011.&amp;nbsp; You can just do this to invoke the NLP solver:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;solve;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With these changes (and with or without initializing W), the resulting solution matches your Excel output:&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;[1]&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;W&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;0.31337&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;0.17488&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;0.13054&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;0.38121&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 21:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529262#M2552</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-01-22T21:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529357#M2554</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;I can't thank you enough for your huge help, this is working perfectly fine! I apologize but I would have a very last question: by adapting this code for a by-group processing, using this &lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/Complicated-loop-with-PROC-OPTMODEL/m-p/525002#M2537" target="_self"&gt;thread&lt;/A&gt;, I obtain the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Problem generation will use 4 threads.
ERROR: Out of memory during problem generation.
NOTE: Unable to create problem instance due to previous errors.
969
970      create data Work.Weights_ERC from [&amp;amp;byvar i] W=W_sol;
NOTE: The data set Work.WEIGHTS_ERC has 1124 observations and 3 variables.
971  quit;
ERROR: The SAS System stopped processing this step because of insufficient memory.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Given that this is a test sample with only 3 groups, I think this is more likely due to an error in my following code that the fact this optimization problem is solved using NLP, perhaps more resource intensive that in the reference thread where this is a simpler optimization problem solved with QP:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let byvar = grp;
proc optmodel printlevel=0;
	set OBS;
	num grp {OBS};
	set &amp;lt;string&amp;gt; Assets;
	set &amp;lt;num,str&amp;gt; GROUPS_ASSETS;
	number MVC{GROUPS_ASSETS, Assets};

	read data Work.MVC into Assets=[Name];
	read data Work.MVC into OBS=[_N_] grp;
	read data Work.MVC nomiss into GROUPS_ASSETS=[k=grp i=Name] {j in Assets} &amp;lt;MVC[k,i,j]=col(j)&amp;gt;;

	set BYSET = setof {i in OBS} &amp;amp;byvar.[i];
	num by;

	set OBS_BY = {i in OBS: &amp;amp;byvar.[i] = by};
	set Assets_BY = setof {o in OBS_BY, &amp;lt;(grp[o]),a&amp;gt; in GROUPS_ASSETS} a;
	var W{Assets_BY} &amp;gt;= 0;
	impvar RC{l in Assets_BY} = W[l]*(sum{j in Assets_BY}MVC[by,l,j]*W[j]) / sqrt(sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j]);

	minimize f = sum{i in Assets_BY, j in Assets_BY: i ne j}(RC[i] - RC[j])^2;
	con BUDGET: sum{i in Assets_BY}W[i] = 1;

	num W_sol {GROUPS_ASSETS};
	do by = BYSET;
		put by=;
		solve;
		for {i in Assets_BY} W_sol[by,i] = W[i].sol;
	end;

	create data Work.Weights_ERC from [&amp;amp;byvar i] W=W_sol;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 09:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529357#M2554</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-01-23T09:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529401#M2559</link>
      <description>&lt;P&gt;I have a couple of suggestions to improve the efficiency.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The denominator of RC[l] does not depend on l, so you might try the following instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;impvar Denom = sqrt(sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j]);
impvar RC{l in Assets_BY} = W[l]*(sum{j in Assets_BY}MVC[by,l,j]*W[j]) / Denom;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The objective consists of pairs of equal summands, so you can cut the number of summands in half as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;minimize f = 2*sum{i in Assets_BY, j in Assets_BY: i &amp;lt; j}(RC[i] - RC[j])^2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If these improvements are still not enough, please supply your data.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 14:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529401#M2559</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-01-23T14:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529481#M2561</link>
      <description>&lt;P&gt;Thank you so much for your help. The good news is that my code was correct, the bad news is that this optimization problem is actually very resource extensive. With your more efficient code, I can at least find the optimal weights, even if this is incredibly long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested with 3 groups of 1,000 assets (the maximum number of assets in my study). Please find enclosed the covariance matrix for the 1st group (in .csv due to the upload limitation). With 2 other portfolios solved with QP this is pretty quick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;minimize Variance = sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j];
con BUDGET: sum{i in Assets_BY}W[i] = 1;

NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           52.32 seconds
      cpu time            1:59.94


minimize DR = 1/2 * sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j];
con VARIANCE: sum{i in Assets_BY}W[i]*MVC[by,i,i] = 1;

NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           51.74 seconds
      cpu time            2:00.30&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but with this portfolio solved with NLP this is extremely long:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           30:23.27
      cpu time            1:35:21.13&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;In the paper &lt;A href="https://www.researchgate.net/publication/264087166_Computing_equal_risk_contribution_portfolios" target="_self"&gt;here&lt;/A&gt;, they compare several solvers for this portfolio. In table 2, with 500 assets, we can observe a huge difference in computation time among solvers. I also noticed in their paper that the scaling constraint:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;con BUDGET: sum{i in Assets_BY}W[i] = 1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;is very time consuming, so I tried to remove it, and rescale weights afterwards, but in my case this is even worse!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           40:49.35
      cpu time            2:16:08.05&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the log I see that there were actually more iterations without the constraint: 18, 16, 20 iterations without rescaling, and 12, 12, 12 iterations with the rescale constraint.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still waiting for a new SAS licence that our secretary purchased a few days ago and that I will install on a more powerful computer (i5-8400 2.8GHZ and 16GB RAM), compared to currently I5-5200U 2.2GHz and 8GB RAM. So I will run more tests and the full program on the new computer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I mark this topic as solved since the optimization code now works, but if you have more ideas to make it even more efficient I will gladly take them!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 10:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529481#M2561</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-01-24T10:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529590#M2562</link>
      <description>&lt;P&gt;After consulting with some of my colleagues, I have a few more suggestions that seem to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace the impvar Denom with an explicit var and con, and square both sides to avoid the sqrt:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*   impvar Denom = sqrt(sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j]);*/
   var Denom &amp;gt;= 0;
   con DenomCon: Denom^2 = sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Clear the denominator:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*   con RCCon{l in Assets_BY}: RC[l] = W[l]*(sum{j in Assets_BY}MVC[by,l,j]*W[j]) / Denom;*/
   con RCCon{l in Assets_BY}: RC[l]*Denom = W[l]*(sum{j in Assets_BY}MVC[by,l,j]*W[j]);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the only nonlinearities are quadratic.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 00:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529590#M2562</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-01-24T00:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529643#M2563</link>
      <description>&lt;P&gt;Thank you very much for your suggestions and I'm sorry I just realized that in the uploaded file I forgot to add the column "Name" with _1, _2, ..., _1000 (please find it enclosed).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tested the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let byvar = grp;
proc optmodel printlevel=0;
	set OBS;
	num grp {OBS};
	set &amp;lt;string&amp;gt; Assets;
	set &amp;lt;num,str&amp;gt; GROUPS_ASSETS;
	number MVC{GROUPS_ASSETS, Assets};

	read data Work.MVC into Assets=[Name];
	read data Work.MVC into OBS=[_N_] grp;
	read data Work.MVC nomiss into GROUPS_ASSETS=[k=grp i=Name] {j in Assets} &amp;lt;MVC[k,i,j]=col(j)&amp;gt;;

	set BYSET = setof {i in OBS} &amp;amp;byvar.[i];
	num by;

	set OBS_BY = {i in OBS: &amp;amp;byvar.[i] = by};
	set Assets_BY = setof {o in OBS_BY, &amp;lt;(grp[o]),a&amp;gt; in GROUPS_ASSETS} a;
	var W{Assets_BY} &amp;gt;= 0;
	/* impvar Denom = sqrt(sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j]); */
	var Denom &amp;gt;= 0;
	impvar RC{l in Assets_BY} = W[l]*(sum{j in Assets_BY}MVC[by,l,j]*W[j]) / Denom;
	con DenomCon: Denom^2 = sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j];
	con RCCon{l in Assets_BY}: RC[l]*Denom = W[l]*(sum{j in Assets_BY}MVC[by,l,j]*W[j]);

	minimize f = 2*sum{i in Assets_BY, j in Assets_BY: i &amp;lt; j}(RC[i] - RC[j])^2;
	con BUDGET: sum{i in Assets_BY}W[i] = 1;

	num W_sol {GROUPS_ASSETS};
	do by = BYSET;
		put by=;
		solve;
		for {i in Assets_BY} W_sol[by,i] = W[i].sol;
	end;

	create data Work.Weights_ERC from [&amp;amp;byvar i] W=W_sol;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And sadly this is actually worse. It's longer with more iterations. 28, 21, 26 without the constraint:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           1:07:00.72
      cpu time            3:38:05.89&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and 17, 24 and 35 with the constraint:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           1:03:14.33
      cpu time            3:20:49.47&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;While comparing results, I also noticed that they were slightly&amp;nbsp; different (due to the different number of iterations I presume?).&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 10:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529643#M2563</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-01-24T10:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529675#M2564</link>
      <description>&lt;P&gt;Sorry that I failed to mention one additional change that goes along with the introduction of the RCCon constraint. &amp;nbsp;Replace the impvar RC declaration with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var RC{Assets_BY};&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jan 2019 13:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529675#M2564</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-01-24T13:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529696#M2565</link>
      <description>&lt;P&gt;My bad, I launched the code with the modifications this morning without thinking. This is indeed much better!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: PROCEDURE OPTMODEL used (Total process time):
      real time           11:35.57
      cpu time            36:20.17&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With only 7 iterations in the 3 cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 14:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529696#M2565</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-01-24T14:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529789#M2566</link>
      <description>&lt;P&gt;Glad to help.&amp;nbsp; By the way, which SAS/OR version are you running, and which version are you upgrading to?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 18:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529789#M2566</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-01-24T18:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529807#M2567</link>
      <description>&lt;P&gt;I currently have the 14.1 and I suppose I will receive the last one since this is a single-user licence. Will it make a difference in the speed of execution?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 19:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529807#M2567</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-01-24T19:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529869#M2568</link>
      <description>&lt;P&gt;SAS/OR 14.1 was released in July 2015.&amp;nbsp; The latest production version is SAS/OR 15.1, which was released in November 2018.&amp;nbsp; Performance of the NLP solver with default options on this particular instance is similar in 14.1 versus 15.1.&amp;nbsp; But I would still recommend the latest version for the new features and overall performance improvements.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 21:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/529869#M2568</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-01-24T21:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with PROC OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/532284#M2590</link>
      <description>&lt;P&gt;Just received my new licence and this is 9.4TS1M5 with SAS/OR 14.3... I guess I will discover the 15.1 when you'll be at version 16 or higher &lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://communities.sas.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 16:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Assistance-with-PROC-OPTMODEL/m-p/532284#M2590</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2019-02-02T16:17:51Z</dc:date>
    </item>
  </channel>
</rss>

