plot_acf: Calculate the autocorrelation function (ACF) for a time...

View source: R/rutils.R

plot_acfR Documentation

Calculate the autocorrelation function (ACF) for a time series of returns, and plot it.

Description

Calculate the autocorrelation function (ACF) for a time series of returns, and plot it.

Usage

plot_acf(
  xtsv,
  lagg = 10,
  plotobj = TRUE,
  xlab = "Lag",
  ylab = "",
  main = "",
  ...
)

Arguments

xtsv

A vector, matrix, or time series of returns.

lagg

The maximum lag at which to calculate the ACF (default is 10).

plotobj

A Boolean argument: should a plot be made? (default is TRUE)

xlab

A string with the x-axis label.

ylab

A string with the y-axis label.

main

A string with the plot title.

...

Additional arguments to the function stats::acf().

Details

The function plot_acf() calculates the autocorrelation function (ACF) for a time series of returns, and plots it. The function plot_acf() is just a wrapper for the function stats::acf(). The function stats::acf() calculates the autocorrelation function, including the lag zero autocorrelation, which is by definition equal to 1.

The function plot_acf() calls the function stats::acf(), removes the spurious lag zero autocorrelation, creates a plot, and returns the ACF data invisibly.

Value

Returns the ACF data invisibly and creates a plot.

Examples

# Plot the ACF of random returns
rutils::plot_acf(rnorm(1e4), lag=10, main="ACF of Random Returns")
# Plot the ACF of VTI returns
rutils::plot_acf(na.omit(rutils::etfenv$returns$VTI), lag=10, main="ACF of VTI Returns")

algoquant/rutils documentation built on April 18, 2024, 12:05 a.m.