<?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: efficient frontier of portfolio with proc iml : results summary and adding constraints in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/234391#M2489</link>
    <description>&lt;P&gt;It would have been helpful if you had linked to this paper when you asked your question:&lt;A href="http://abeweb.org/proceedings/proceedings10/thompson.pdf" target="_self"&gt; "&lt;STRONG&gt;&lt;FONT color="#0066cc"&gt;SAS and the Efficient Portfolio &lt;/FONT&gt;&lt;/STRONG&gt; &lt;/A&gt;&lt;A style="text-decoration: none;" href="http://abeweb.org/proceedings/proceedings10/thompson.pdf" target="_self"&gt;by Thomas H. Thompson and Ashraf El-Houbi&lt;/A&gt;&lt;A href="http://abeweb.org/proceedings/proceedings10/thompson.pdf" target="_self"&gt;"&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Nov 2015 15:19:51 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2015-11-12T15:19:51Z</dc:date>
    <item>
      <title>efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232161#M2449</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose that I have the following stock return data for 3 stocks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data returns;&lt;BR /&gt;input abc def zzz;&lt;BR /&gt;datalines;&lt;BR /&gt;10 2 5&lt;BR /&gt;3 -5 7&lt;BR /&gt;-1 -7 6&lt;BR /&gt;1 3 -2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the following code to calculate the efficient frontier, i.e, for each level of risk (variance) to find the optimal return and the weights of the stocks that correspond to each risk-return combination:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc IML;&lt;BR /&gt;use returns;&lt;BR /&gt;read all var _num_ into RMAT[colname=varNames];&lt;BR /&gt;Print RMAT;&lt;BR /&gt;f = 1;&lt;BR /&gt;g = 2;&lt;BR /&gt;n = 4; /* number of rows*/&lt;BR /&gt;k = 3; /* number of columns*/&lt;BR /&gt;RAVG = j(f,k,0);&lt;BR /&gt;RAVG=RMAT[:,]; /* to calculate column average returns, a 1 x k matrix*/&lt;BR /&gt;Print RAVG;&lt;BR /&gt;xbar = REPEAT(RAVG,n,f); /* to create an n x k matrix*/&lt;BR /&gt;Print xbar;&lt;BR /&gt;RMX = j(n,k,0);&lt;BR /&gt;RMX = RMAT-xbar; /* to calculate RMX*/&lt;BR /&gt;Print RMX;&lt;BR /&gt;V = j(k,k,0);&lt;BR /&gt;V=RMX`*RMX /(n-1); /* to calculate covariance matrix*/&lt;BR /&gt;Print V;&lt;BR /&gt;VINV =j(k,k,0);&lt;BR /&gt;VINV = INV(V); /* to take inverse of V*/&lt;BR /&gt;Print VINV;&lt;BR /&gt;P = 0.05;&lt;BR /&gt;M={1,.05}; /* to define M and required return (must change)*/&lt;BR /&gt;Print M;&lt;BR /&gt;DIG = j(1,k,1);&lt;BR /&gt;R = j(g,k,0);&lt;BR /&gt;R =DIG//RAVG; /* to concatenate (combine) DIG and RAVG to a 2 x k matrix*/&lt;BR /&gt;Print R;&lt;BR /&gt;H =j(2,2,0);&lt;BR /&gt;H = R*inv(V)*R`; /* to calculate H*/&lt;BR /&gt;Print H;&lt;BR /&gt;HINV = j(2,2,0);&lt;BR /&gt;HINV = INV(H); /* to take inverse of H*/&lt;BR /&gt;PRINT HINV;&lt;BR /&gt;Do until (P&amp;lt;=0);&lt;BR /&gt;W = j(1,k,0);&lt;BR /&gt;W = VINV*R`*HINV*M; /* to calculate portfolio weights*/&lt;BR /&gt;Print W;&lt;BR /&gt;PVAR = j(1,1,0);&lt;BR /&gt;PVAR = W`*V*W; /* to calculate portfolio variance given a return and weights*/&lt;BR /&gt;Print PVAR;&lt;BR /&gt;P = P-.005;&lt;BR /&gt;M = M - {0, .005};&lt;BR /&gt;end;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically the core of the code is done, what I need are 2 special additions:&lt;/P&gt;
&lt;P&gt;1) I would like to create a table which will contain the information in the following way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Weight abc&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Abc1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Abc2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Etc.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Weight def&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Def1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Def2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Weight zzz&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Zzz1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Zzz2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;return&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Ret1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Ret2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;variance&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Var1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Var2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) I would like to add the constraint of no short selling, i.e, the weights should all be greater or equal to 0. I just don't know how to add constraints into Proc IML&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much!!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 03:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232161#M2449</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-10-29T03:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232170#M2450</link>
      <description>&lt;P&gt;I don't have a complete understanding of what you are trying to do here, but I think I can answer your first question. You need to create a matrix large enough to hold all the results and then use a do loop with a counter. Then as the loop iterates, write submatrices of the results table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rtab = j(k+1, 10);
do i = 1 to 10;
  &amp;lt;existing code from do loop here&amp;gt;
  rtab[1:k, i] = W;
  rtab[k+1, i] = PVAR;
end;
print rtab [rowname=varNames];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A few other comments. V = COV(RMAT) will give the covariance matrix in just one statement, and note that there is no need to write declarative statements like V = j(k, k, 0);&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 08:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232170#M2450</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2015-10-29T08:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232280#M2452</link>
      <description>&lt;P&gt;And here are some general programming tips to simplify your code:&lt;BR /&gt;1) Use the NROW and NCOL functions to get the number of rows and columns for RMAT&lt;/P&gt;
&lt;P&gt;2) Use the&amp;nbsp;MEAN and COV functions for&amp;nbsp;the computations of RAVG and V.&lt;/P&gt;
&lt;P&gt;3) You don't need to use the REPEAT statement to make the mean vector a full matrix. SAS/IML knows &lt;A href="http://blogs.sas.com/content/iml/2010/12/06/shorthand-notation-for-row-and-column-operations.html" target="_self"&gt;how to subtract a mean vector from each row of a matrix&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;4) There is no need to "pre-allocate" every variable before you assign to it.&amp;nbsp; Just make the assignment and the dimensions of the variable will be determined automatically.&lt;/P&gt;
&lt;P&gt;5) [Optional] You can get rid of the final loop if you want.&amp;nbsp; You can create a 2&amp;nbsp;x 10 matrix&amp;nbsp;of all the values of W and use that matrix in the computations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The simplified code looks like this:&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;
Proc IML;
use returns;
read all var _num_ into RMAT[colname=varNames];
n = nrow(RMAT);    /* number of rows*/
k = ncol(RMAT);    /* number of columns*/
RAVG = mean(RMAT); /* mean of columns */
V = cov(RMAT);     /* covariance matrix */
VINV = INV(V);     /* inverse of V */
R = j(1,k,1) // RAVG; /* concatenate DIG and RAVG to a 2 x k matrix*/
H = R*VINV*R`;   

P = do(0.05, 0.005, -0.005);  /* sequence of values for P */
M = j(1, ncol(P), 1) // P; 
W = VINV*R`*inv(H)*M;         /* portfolio weights*/
PVAR = T( vecdiag(W`*V*W ));  /* portfolio variance given a return and weights*/
print W[colname=(char(P)) rowname=varNames],
      PVAR[colname=(char(P))];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="2"&gt;&lt;FONT color="#008000" face="Courier New" size="2"&gt;&lt;FONT color="#008000" face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 17:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232280#M2452</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-10-29T17:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232281#M2453</link>
      <description>&lt;P&gt;For (2), do you mean that you want to replace any negative weights with zeros?&amp;nbsp; If so, you can use the &lt;A href="http://blogs.sas.com/content/iml/2014/12/15/elementwise-minmax-operators.html" target="_self"&gt;elementwise maximum operator&lt;/A&gt;&amp;nbsp;as follows:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;W = W &amp;lt;&amp;gt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 17:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232281#M2453</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-10-29T17:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232548#M2454</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you for your code, now I have the weights in W and the variances in PVAR, for any given level of return. But is it possible to cretae data tables for both W and PVAR becasue when I tried doing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data all;&lt;BR /&gt; set w pvar;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got an error message that tables w and pvar don't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second part of the question, I just realized that I forgot to mention that there is another constraint: the sum of all weights should be equal to one - and this constraint is also applicable to the code that I put in the beginning of this topic.&lt;/P&gt;
&lt;P&gt;So the additional constraint that each weight is &amp;gt;=0 would affect the entire calculaton from the beginning, otherwise the result would lose its meaning if all the negative weights are made = 0 and all the others kept as they are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Oct 2015 01:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232548#M2454</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-10-31T01:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232632#M2455</link>
      <description>&lt;P&gt;See this article about &lt;A href="http://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html" target="_self"&gt;how to write data from SAS/IML matrices to SAS data sets.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your goal is to&amp;nbsp;find the optimal solution for a linear problem with constraints, that operation is called "linear programming." See the &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_genstatexpls_sect011.htm" target="_self"&gt;"Linear programming" example in the SAS/IML documentation.&lt;/A&gt;&amp;nbsp;In SAS/IML 13.1 and beyond, use the LPSOLVE call to solve linear programming problems.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 12:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232632#M2455</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-11-01T12:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232650#M2456</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I went to the link for the discussion on your blog and managed to create 2 tables. But now I have 2 small problems with the names of the columns and rows.&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data returns;&lt;BR /&gt;input abc def zzz;&lt;BR /&gt;datalines;&lt;BR /&gt;10 2 5&lt;BR /&gt;3 -5 7&lt;BR /&gt;-1 -7 6&lt;BR /&gt;1 3 -2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc IML;&lt;BR /&gt;use returns;&lt;BR /&gt;read all var _num_ into RMAT[colname=varNames];&lt;BR /&gt;n = nrow(RMAT); /* number of rows*/&lt;BR /&gt;k = ncol(RMAT); /* number of columns*/&lt;BR /&gt;RAVG = mean(RMAT); /* mean of columns */&lt;BR /&gt;V = cov(RMAT); /* covariance matrix */&lt;BR /&gt;VINV = INV(V); /* inverse of V */&lt;BR /&gt;R = j(1,k,1) // RAVG; /* concatenate DIG and RAVG to a 2 x k matrix*/&lt;BR /&gt;H = R*VINV*R`;&lt;/P&gt;
&lt;P&gt;P = do(0.05, 0.005, -0.005); /* sequence of values for P */&lt;BR /&gt;M = j(1, ncol(P), 1) // P; &lt;BR /&gt;W = VINV*R`*inv(H)*M; /* portfolio weights*/&lt;BR /&gt;PVAR = T( vecdiag(W`*V*W )); /* portfolio variance given a return and weights*/&lt;BR /&gt;print W[colname=(char(P)) rowname=varNames],&lt;BR /&gt; PVAR[colname=(char(P)) rowname={'variance'}];&lt;BR /&gt; create Weights from W [colname=(char(p)) ] ;&lt;BR /&gt;append from W;&lt;BR /&gt;close Weights;&lt;BR /&gt;create Variance from pvar [colname=(char(P))] ;&lt;BR /&gt;append from pvar;&lt;BR /&gt;close Variance;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) the column names for both new tables are output in a strange way. For ex, it should be 0.05 but I get _0D05&lt;/P&gt;
&lt;P&gt;2) for the new table Weights instead of getting the stock names on the left I get numbers 1,2,3.&lt;/P&gt;
&lt;P&gt;I tried doing&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;create Weights from W [colname=(char(p)) rowname=varNames&amp;nbsp; ] ;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but then didn't get any table at all and an error message saying that "number of columns in W does not match witht he number of variables in the data set".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 16:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232650#M2456</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-11-01T16:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232665#M2457</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;
&lt;P&gt;concerning my first reply to your last poste I think that I managed to the tables that I wanted with the necessary column and row names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*creating tables return and Variance - the vector P contains the returns!!!*/&lt;/P&gt;
&lt;P&gt;create ret from p&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;append from p;&lt;/P&gt;
&lt;P&gt;close ret;&lt;/P&gt;
&lt;P&gt;create variance from pvar&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;append from pvar;&lt;/P&gt;
&lt;P&gt;close variance; &lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*to put return and variance together*/&lt;/P&gt;
&lt;P&gt;/*transposing and renaming*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;transpose&lt;/STRONG&gt; data=variance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out=var_transposed;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; ret_transposed;&lt;/P&gt;
&lt;P&gt;set ret_transposed (rename=(col1=return)); run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*adding n*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&amp;nbsp; var_transposed;&lt;/P&gt;
&lt;P&gt;set&amp;nbsp; var_transposed;&lt;/P&gt;
&lt;P&gt;n=_n_;run;&lt;/P&gt;
&lt;P&gt;/*merging*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; return_variance;&lt;/P&gt;
&lt;P&gt;merge ret_transposed var_transposed;&lt;/P&gt;
&lt;P&gt;by n; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*to put all together*/&lt;/P&gt;
&lt;P&gt;/*extracting the stock names*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;contents&lt;/STRONG&gt; data=returns out=stocks (keep=NAME) ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt; ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;print&lt;/STRONG&gt; data=stocks ; &lt;STRONG&gt;run&lt;/STRONG&gt; ;&lt;/P&gt;
&lt;P&gt;/*creating the name "variance"*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; v;&lt;/P&gt;
&lt;P&gt;input name$;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;variance&lt;/P&gt;
&lt;P&gt;; run;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; names;&lt;/P&gt;
&lt;P&gt;set stocks v;&lt;/P&gt;
&lt;P&gt;n=_n_; run;&lt;/P&gt;
&lt;P&gt;/*setting the weights and variance*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; weights_variance;&lt;/P&gt;
&lt;P&gt;set weights variance;&lt;/P&gt;
&lt;P&gt;n=_n_; run;&lt;/P&gt;
&lt;P&gt;/*combining all into a table*/&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; swv;&lt;/P&gt;
&lt;P&gt;merge weights_variance names;&lt;/P&gt;
&lt;P&gt;by n; run;&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;P&gt;As for my question about the constraint, is it possible to do an efficient frontier in proc iml with the constraint (becasue linear optimization is a one-by-one case)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!!!&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 23:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/232665#M2457</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-11-01T23:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/234391#M2489</link>
      <description>&lt;P&gt;It would have been helpful if you had linked to this paper when you asked your question:&lt;A href="http://abeweb.org/proceedings/proceedings10/thompson.pdf" target="_self"&gt; "&lt;STRONG&gt;&lt;FONT color="#0066cc"&gt;SAS and the Efficient Portfolio &lt;/FONT&gt;&lt;/STRONG&gt; &lt;/A&gt;&lt;A style="text-decoration: none;" href="http://abeweb.org/proceedings/proceedings10/thompson.pdf" target="_self"&gt;by Thomas H. Thompson and Ashraf El-Houbi&lt;/A&gt;&lt;A href="http://abeweb.org/proceedings/proceedings10/thompson.pdf" target="_self"&gt;"&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 15:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/234391#M2489</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-11-12T15:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: efficient frontier of portfolio with proc iml : results summary and adding constraints</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/234743#M2490</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what a coincidence, I actually also found this paper before posting this question but the paper handles only the unrestricted case (i.e, short selling allowed so that the weights of the stocks can be negative) and that's the reason why I posted this question, in order to do the restricted case when short selling is not allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2015 01:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/efficient-frontier-of-portfolio-with-proc-iml-results-summary/m-p/234743#M2490</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-11-14T01:53:50Z</dc:date>
    </item>
  </channel>
</rss>

