LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Sep 2010 09:11:03 -0500
Reply-To:     Robin R High <rhigh@UNMC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Robin R High <rhigh@UNMC.EDU>
Subject:      Re: first order autocovariance series
Comments: To: MM <WBS.PhD@GMAIL.COM>
In-Reply-To:  <201009081531.o88AmUiY006497@willow.cc.uga.edu>
Content-Type: text/plain; charset="US-ASCII"

MM,

From the following link,

http://mathworld.wolfram.com/SampleVarianceComputation.html

formulas are given for computing mean and variances sequentially through a series of numbers. Formula 30 at the end can be modified to compute the covariance of two variables, as the following DATA step illustrates:

DATA tst; retain mux1 s2x muy1 s2y cvxy; input x y; j=_n_; if _n_ = 1 then do; mux1=x; s2x=0; muy1=y; s2y=0; cvxy=0; output; return; end; if _n_ > 1 then do; mux2 = ((j-1)*mux1 + x ) / j; s2x_1 = ((1 - (1/(j-1))) * s2x) + (j*((mux2 - mux1)**2)); muy2 = ((j-1)*muy1 + y ) / j; s2y_1 = ((1 - (1/(j-1))) * s2y) + (j*((muy2 - muy1)**2));

cvxy_1 = ((1 - (1/(j-1))) * cvxy) + (j*(mux2 - mux1)*(muy2 - muy1)); * covariance of x and y;

output; mux1 = mux2; s2x = s2x_1; muy1 = muy2; s2y = s2y_1; cvxy = cvxy_1; end; cards; 5 4 6 7 3 3 9 8 7 6 4 3 6 5 ;

proc print data=tst NOObs; var j x y mux2 s2x_1 muy2 s2y_1 cvxy_1; run;

proc means data=tst n mean var ; var x y; run;

ods select cov; proc corr data=tst cov; var x y; run;

j x y mux2 s2x_1 muy2 s2y_1 cvxy_1

.... 7 6 5 5.71429 3.90476 5.14286 3.80952 3.54762

The MEANS Procedure

Variable N Mean Variance --------------------------------------------- x 7 5.7142857 3.9047619 y 7 5.1428571 3.8095238

Covariance Matrix, DF = 6

x y

x 3.904761905 ** 3.547619048 ** covariance y 3.547619048 3.809523810

Since you are dealing with a time series, the first observation will be missing for a lagged variable, but should be straightforward to make a dataset that starts the computations at time 2.

Robin High UNMC

From: MM <WBS.PhD@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Date: 09/08/2010 10:31 AM Subject: Re: first order autocovariance series Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>

Thanks Murphy.

I may be wrong but I believe that proc arima only allows me to write the autocovariances (up to a specified number of lags) to an output SAS data set by using OUTCOV option.

However, what I need it is not the first order autocovariance of the complete return series, but a series of first order autocovariances. The ideal output dataset would be for example:

DATE RET COV ...... .... .... 12May2010 0.01 .... 13May2010 0.012 .... 14May2010 0.008 .... ...... .... ....

where COV=Cov(Rt;Rt-1) is re-calculated for each day t (i.e. considering the series of returns and lagged returns up to day t).

Any idea how to do this? Is it still something I can accomplish using proc arima? Or I need iterative procedures?

Many thanks, MM


Back to: Top of message | Previous page | Main SAS-L page