title: Calculate correlation of any pair of stocks
body: <p>I want to get the correlation between monthly returns for each pair of stocks... </p>
  
  <p>Let me show you a simple version of my data:</p>
  
  <pre><code>&gt; head(x, 20)
  # A tibble: 20 x 4
     PERMNO     date         COMNAM       RET
      &lt;int&gt;    &lt;int&gt;          &lt;chr&gt;     &lt;dbl&gt;
   1  10107 20160129 MICROSOFT CORP -0.007030
   2  10107 20160229 MICROSOFT CORP -0.069886
   3  10107 20160331 MICROSOFT CORP  0.085495
   4  10107 20160429 MICROSOFT CORP -0.097049
   5  10107 20160531 MICROSOFT CORP  0.069982
   6  10107 20160630 MICROSOFT CORP -0.034528
   7  10107 20160729 MICROSOFT CORP  0.107680
   8  10107 20160831 MICROSOFT CORP  0.020113
   9  10107 20160930 MICROSOFT CORP  0.002436
  10  10107 20161031 MICROSOFT CORP  0.040278
  11  10107 20161130 MICROSOFT CORP  0.012183
  12  10107 20161230 MICROSOFT CORP  0.031198
  13  14593 20160129      APPLE INC -0.075242
  14  14593 20160229      APPLE INC -0.001335
  15  14593 20160331      APPLE INC  0.127211
  16  14593 20160429      APPLE INC -0.139921
  17  14593 20160531      APPLE INC  0.071368
  18  14593 20160630      APPLE INC -0.042660
  19  14593 20160729      APPLE INC  0.090063
  20  14593 20160831      APPLE INC  0.023606
  </code></pre>
  
  <p>Ideally, I would like a correlation measure for pairs of stocks in my data (Microsoft and Apple, Microsoft and Costco, etc)</p>