<?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: Cross-correlation across all stocks in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674617#M203160</link>
    <description>&lt;P&gt;Do you want simple averages or weighted averages?&lt;/P&gt;</description>
    <pubDate>Tue, 04 Aug 2020 23:51:44 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-08-04T23:51:44Z</dc:date>
    <item>
      <title>Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674246#M203004</link>
      <description>&lt;P&gt;I have a dataset of daily stock returns and trading volume. I want to check the cross-correlogram between returns and trading volumes across stocks. How do I achieve this? Right now, my code can get the CCF for each stock. Do I just get the average across stocks using PROC MEANS? or is there a way to do it without the averaging step?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc timeseries data=sample outcrosscorr=crosscor;
	var volume r;
	by stock;
	id date interval=weekday; 
	crosscorr lag n ccf;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 02:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674246#M203004</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2020-08-04T02:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674266#M203010</link>
      <description>&lt;P&gt;The proc timeseries you present will do crosscorrelations of r and vol WITHIN stocks, not across stocks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get cross correlations you will need to reshape the data, so that there are two columns (i.e. two variables) for each stock.&amp;nbsp; And of course, you'll quickly run into scalability problems as the number of stocks increases - for N stocks, it will produce&amp;nbsp;&amp;nbsp; N*(N-1) cross-corellation series (defaults to lag15 to lead15 I believe).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 04:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674266#M203010</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-04T04:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674277#M203016</link>
      <description>&lt;P&gt;yeah I mean just within stocks, I don't expect Volume of stock A correlates with returns of stock B. So I can just compute the cross-correlation within each stock, and then average across them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 06:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674277#M203016</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2020-08-04T06:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674317#M203037</link>
      <description>Better post it at Forecasting forum .</description>
      <pubDate>Tue, 04 Aug 2020 11:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674317#M203037</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-04T11:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674617#M203160</link>
      <description>&lt;P&gt;Do you want simple averages or weighted averages?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 23:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674617#M203160</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-04T23:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674620#M203161</link>
      <description>&lt;P&gt;I did simple&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 00:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674620#M203161</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2020-08-05T00:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-correlation across all stocks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674626#M203162</link>
      <description>&lt;P&gt;Your original questions were:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Do I just get the average across stocks using PROC MEANS?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ans: Yes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;or is there a way to do it without the averaging step?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not that I know of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the timeseries output dataset (crosscor in your example) identifies correlations by&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;_name_ (the first var)&lt;/LI&gt;
&lt;LI&gt;_cross_&amp;nbsp; (the other var)&lt;/LI&gt;
&lt;LI&gt;lag&amp;nbsp; (offset, which appears to have a default range of 15 to -15&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;you should use them as the class identifiers, with ccf as the analysis variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=crosscor noprint  nway;
  var ccf;
  class _name_ _cross_ lag;
  output out=crosscor_means mean=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;crosscor_means has what you want.&amp;nbsp; But note it has some duplication.&amp;nbsp;&amp;nbsp; It presents correlations of X and lag(Y) for lag=-15 through lag=15&amp;nbsp;&amp;nbsp; (one of them is lead15, but I didn't bother to check). That's 31 rows, but the dataset actually has 62 rows, because it also presents correlations of Y and lag(X), again for lag=-15 through 15.&amp;nbsp; So CCF for x with y for the lag=-10 row&amp;nbsp;&amp;nbsp; is the same value as CCF for y with x for the lag=+10 row.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 00:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cross-correlation-across-all-stocks/m-p/674626#M203162</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-05T00:51:24Z</dc:date>
    </item>
  </channel>
</rss>

