From: db on
Hi, Does anyone know how to calculate cumulative correlation
coefficient by date and time ?
I would like to calculate correlation coefficient that start from
7:00:00 and finishes at 21:00:00 every day.
Currently logic gives me rolling window of correlation coefficient.

Thanks, db

data input;
format date:mmddyy10. time :time7.;
input date $ time $ stock1 stock2;
cards;
01/04/2010 7:00:00 5989.5 1115.25
01/04/2010 7:01:00 5998.5 1116
01/04/2010 7:02:00 5996.5 1115.75
01/04/2010 7:05:00 6000 1115.5
01/04/2010 20:55:00 6042 1128.5
01/04/2010 20:56:00 6040.5 1128.5
01/04/2010 20:57:00 6040.5 1128.75
01/04/2010 20:58:00 6040.5 1128.5
01/04/2010 20:59:00 6040.5 1128.5
01/04/2010 21:00:00 6036 1128.75
01/05/2010 7:00:00 6035.5 1128.5
01/05/2010 7:01:00 6037 1128.5
01/05/2010 7:02:00 6037 1128.5
01/05/2010 7:03:00 6038 1128.5
01/05/2010 7:06:00 6038.5 1128.25
01/05/2010 20:56:00 6042 1131.5
01/05/2010 20:57:00 6042.5 1132
01/05/2010 20:58:00 6042 1132
01/05/2010 20:59:00 6041.5 1131.75
01/05/2010 21:00:00 6041.5 1132.25
01/06/2010 7:00:00 6039 1129.75
01/06/2010 7:01:00 6035 1129.25
01/06/2010 7:02:00 6035 1129.5
01/06/2010 7:07:00 6035 1129.25
01/06/2010 20:38:00 6036 1134
01/06/2010 20:39:00 6038.5 1134.25
01/06/2010 20:59:00 6035.5 1133
01/06/2010 21:00:00 6035.5 1133
;
run;

%let wsize=5;
data corr;
array xx(&wsize) (&wsize * 0);
array yy(&wsize) (&wsize * 0);
retain xx : yy :;
x2remove = xx(mod(_n_ - 1, &wsize) + 1);
*put x2remove;
y2remove = yy(mod(_n_ - 1, &wsize) + 1);
set input ( rename = (stock2 = y stock1 = x)) ;
xx(mod(_n_ - 1, &wsize) + 1) = x;
yy(mod(_n_ - 1, &wsize) + 1) = y;
sumx + x - x2remove ;
sumxsq + x**2 - x2remove**2;
sumy + y - y2remove;
sumysq + y**2 - y2remove**2;
sumxy + x * y - x2remove * y2remove;
if _n_ >= &wsize then
r = (sumxy - sumx * sumy / &wsize)/sqrt((sumxsq - sumx ** 2 /
&wsize) * (sumysq - sumy ** 2 / &wsize));
run;