[R] question concerning the acf function

Jean-Christophe BOUËTTÉ jcbouette at gmail.com
Tue Sep 20 16:41:15 CEST 2011


Hi Samir,
I do vaguely understand your intention. However I'm not sure taking
the mean of acf's makes any sense.
I do not know what your final goal is (what do you want to do with the
data?) but here is a suggestion. Instead of trying to aggregate acfs
computed on different series, why don't you:
1. define properly what your goal is for each series
2. find a way to reduce this series to a small set of number using an
automated procedure (for example, the coefficients of an AR, the order
of which has been determined via a rule of thumb or in a more
scientific way. see ?ar)
3. apply this automated procedure to each series to get 3000 small
sets of numbers.
This way, you'll be more able to capture the peculiarities of each series.

This approach leaves open the question of correlation between
different series, of course, but this is a first step. ar handles
multivariate series too.
Jean-Christophe

PS: since this conversation started on R-help, I reply to the list.
Others may offer more meaningful advice!

2011/9/20 Samir Benzerfa <benzerfa at gmx.ch>:
> Actually, you are right. Autocorrelation is simply cross-correlation with
> itself. However, what I would like to have is, instead of
> calculating/plotting the acf for 3000 different series (I have 3000 stocks
> in my dataset) which would take too much time, simply to take something like
> the mean of all acf's. My goal is to see how large the autocorrelation in my
> whole dataset is, in order to apply an autoregressive model to my data.
>
> Do you understand my intention?
>
> THX, SB
>
> -----Ursprüngliche Nachricht-----
> Von: Jean-Christophe BOUËTTÉ [mailto:jcbouette at gmail.com]
> Gesendet: Freitag, 16. September 2011 17:31
> An: Samir Benzerfa
> Cc: r-help at r-project.org
> Betreff: Re: [R] question concerning the acf function
>
> Hi Samir,
> to me, autocorrelation is the cross-correlation of a signal with
> itself. Which is why I don't really understand the meaning of your
> question.
> Are you looking for cross-correlation, for example the ccf function
> documented in the same help page as acf ?
>
> JC
>
>
> 2011/9/16 Samir Benzerfa <benzerfa at gmx.ch>:
>> Below you can see a sample of my data.
>>
>> I learned that I can calculate the autocorrelation of such time series by
>> using the function acf(Stock A) or pacf(Stock A) and the same for the
> other
>> stocks. What I would like to do, is to calculate the overall
> autocorrelation
>> in the whole set (so for all stocks together).
>>
>> Any ideas?
>>
>> Thanks,
>> SB
>>
>>
>> Date    Stock A         Stock B
>> 01.01.1980      0                       0
>> 02.01.1980      0                       0
>> 03.01.1980      0.002149977             0
>> 04.01.1980      -0.002149977    0.003966489
>> 07.01.1980      0                       0
>> 08.01.1980      0.007478811             0
>> 09.01.1980      0.007352198             0.00393059
>> 10.01.1980      0.003113235             0.009673601
>> 11.01.1980      -0.008352074    -0.003843623
>> 14.01.1980      0                       0
>> 15.01.1980      -0.006371182    -0.009760568
>> 16.01.1980      0.007424018             0.00393059
>> 17.01.1980      0.007299239             0.001952035
>> 18.01.1980      -0.008352074    -0.001952035
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Jean-Christophe BOUËTTÉ [mailto:jcbouette at gmail.com]
>> Gesendet: Freitag, 16. September 2011 15:20
>> An: Samir Benzerfa
>> Cc: r-help at r-project.org
>> Betreff: Re: [R] question concerning the acf function
>>
>> Hi,
>> you did not supply a reproducible example. We do not know what your
>> data nor your code looks like.
>> Please follow the recommandations found at the bottom of this email!
>> You're more likely to get a quick and meaningful reply.
>> JC
>>
>> 2011/9/16 Samir Benzerfa <benzerfa at gmx.ch>:
>>> Hi everyone,
>>>
>>>
>>>
>>> I've got a question concerning the function acf(.) in R for calculating
>> the
>>> autocorrelation in my data.
>>>
>>>
>>>
>>> I have a table with daily returns of several stocks over time and I would
>>> like to calculate the autocorrelation for all the series (not only for
> one
>>> time series). How can I do this?
>>>
>>> After that I want to apply an autoregressive model based on the estimated
>>> lag in the data and finally extract the residuals for further
>> calculations.
>>>
>>>
>>>
>>> Many thanks & best regards
>>>
>>> Benzerfa
>>>
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>  PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>  and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>



More information about the R-help mailing list