BookmarkSubscribeRSS Feed
somebody
Lapis Lazuli | Level 10

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?

proc timeseries data=sample outcrosscorr=crosscor;
	var volume r;
	by stock;
	id date interval=weekday; 
	crosscorr lag n ccf;
run;

 

 

6 REPLIES 6
mkeintz
PROC Star

The proc timeseries you present will do crosscorrelations of r and vol WITHIN stocks, not across stocks.

 

To get cross correlations you will need to reshape the data, so that there are two columns (i.e. two variables) for each stock.  And of course, you'll quickly run into scalability problems as the number of stocks increases - for N stocks, it will produce   N*(N-1) cross-corellation series (defaults to lag15 to lead15 I believe). 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
somebody
Lapis Lazuli | Level 10

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?

 

Ksharp
Super User
Better post it at Forecasting forum .
mkeintz
PROC Star

Do you want simple averages or weighted averages?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
somebody
Lapis Lazuli | Level 10

I did simple

 

mkeintz
PROC Star

Your original questions were:

 

Do I just get the average across stocks using PROC MEANS?

Ans: Yes

 

or is there a way to do it without the averaging step?

Not that I know of.

 

Since the timeseries output dataset (crosscor in your example) identifies correlations by

  • _name_ (the first var)
  • _cross_  (the other var)
  • lag  (offset, which appears to have a default range of 15 to -15

you should use them as the class identifiers, with ccf as the analysis variable.

 

proc means data=crosscor noprint  nway;
  var ccf;
  class _name_ _cross_ lag;
  output out=crosscor_means mean=;
run;

crosscor_means has what you want.  But note it has some duplication.   It presents correlations of X and lag(Y) for lag=-15 through lag=15   (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.  So CCF for x with y for the lag=-10 row   is the same value as CCF for y with x for the lag=+10 row.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 952 views
  • 0 likes
  • 3 in conversation