0

Below is a plot of ACF for 30 days. My problem though is, that the x axis is in seconds. Its an xts object and I guess the problem is, that its class is POSIX as discussed here: R / Time Series: What's the lag unit for autocorrelation function (acf)?

However, they didn't discuss solutions. Is there anyway to convert the scale to days, or change the xts dataset so it won't be counted in seconds? Any help is very much appreciated. Below is info and structure of the data and the ACF code.

> class(AxtsPer)
    [1] "xts" "zoo"
    > str(AxtsPer)
    An ‘xts’ object on 2000-01-04/2020-04-30 containing:
      Data: num [1:5113, 1] -8.81 1.45 -9.05 4.63 -1.77 ...
     - attr(*, "dimnames")=List of 2
      ..$ : NULL
      ..$ : chr "new return"
      Indexed by objects of class: [POSIXlt,POSIXt] TZ: UTC
      xts Attributes:  
     NULL
    > head(AxtsPer)
               new return
    2000-01-04  -8.810021
    2000-01-05   1.452810
    2000-01-06  -9.051401
    2000-01-07   4.628075
    2000-01-10  -1.774445
    2000-01-11  -5.250550

acf(AxtsPer, lag.max = 30, main="Return ACF");

ACF in seconds

Anders
  • 73
  • 7

1 Answers1

0

The answer, it turned out, was very simple. I just needed to convert the index class to date instead of POSIX.

The code below worked for me.

tclass(AxtsPer) <- "Date"
Anders
  • 73
  • 7
  • 1
    You only need to be careful about timezones. For example, if you have timestamp of 2000-01-04 00:00:00 for January the 4th, this may be first converted to 2000-01-03 19:00:00 EST, then 2000-01-03 (if you're on the US East coast) – Emil Bode May 04 '20 at 15:51
  • Thank you. I have added `Sys.setenv(TZ="UTC")` in the top of the script, as the data is in UTC. I hope that will be an easy solution. – Anders May 04 '20 at 15:59