<?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 proc optmodel in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel/m-p/481314#M2341</link>
    <description>&lt;P&gt;Hi, I am using the following code to minimize the variance of the following optimization problem;&lt;/P&gt;&lt;PRE&gt;min VAR(R.f - SUM[w_i * R.s_i]) = min VAR(F - w*S)
  s.t. SUM(w_i) = 1; w_i &amp;gt; 0

where:
R.f   Fund returns
R.s   Style returns
w_i   Style weights&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on how to modify this and run my optimization using by variables?&lt;/P&gt;&lt;PRE&gt;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 &amp;lt;str&amp;gt; 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} &amp;lt;cov[_name_,i]=col(i)&amp;gt;;
/* let w1, w2, w3, w4 be the amount invested in each asset */
   var x{1..4} &amp;gt;= 0;
   /* declare optimization model */
   var W {BENCH} &amp;gt;= 0 &amp;lt;= 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;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Jul 2018 01:23:37 GMT</pubDate>
    <dc:creator>Amalik</dc:creator>
    <dc:date>2018-07-26T01:23:37Z</dc:date>
    <item>
      <title>proc optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel/m-p/481314#M2341</link>
      <description>&lt;P&gt;Hi, I am using the following code to minimize the variance of the following optimization problem;&lt;/P&gt;&lt;PRE&gt;min VAR(R.f - SUM[w_i * R.s_i]) = min VAR(F - w*S)
  s.t. SUM(w_i) = 1; w_i &amp;gt; 0

where:
R.f   Fund returns
R.s   Style returns
w_i   Style weights&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on how to modify this and run my optimization using by variables?&lt;/P&gt;&lt;PRE&gt;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 &amp;lt;str&amp;gt; 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} &amp;lt;cov[_name_,i]=col(i)&amp;gt;;
/* let w1, w2, w3, w4 be the amount invested in each asset */
   var x{1..4} &amp;gt;= 0;
   /* declare optimization model */
   var W {BENCH} &amp;gt;= 0 &amp;lt;= 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;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Jul 2018 01:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel/m-p/481314#M2341</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2018-07-26T01:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel/m-p/481319#M2342</link>
      <description>&lt;P&gt;This&amp;nbsp;Usage Note illustrates how to implement BY-group processing in PROC OPTMODEL:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/42/332.html" target="_blank"&gt;http://support.sas.com/kb/42/332.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 02:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel/m-p/481319#M2342</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-07-26T02:09:40Z</dc:date>
    </item>
  </channel>
</rss>

