Get startedGet started for free

Plotting the theoretical and the sample ACF

Still consider the MA(1) model $$Y_t = 0.05 + \epsilon_t + \theta \epsilon_{t-1},$$ with \(|\theta| < 0\) and \(\epsilon_t ~ iid\) \(N(0,(0.1)^2)\).

While we still assume \(\theta = 0.5\), the theoretical value for the first order autocorrelation is \(\rho_1 = \frac{ \theta}{1+\theta^2} = \frac{0.5}{1+0.5^2} = 0.4\). The theoretical autocorrelation function gives you for each lag the autocorrelation implied by the model. In R, you can use the ARMAacf function to calculate the theoretical autocorrelations for an ARMA model. The ma argument should contain the moving average coefficients, and lag.max specifies the maximum number of lags for which the autocorrelations should be calculated.

Based on the simulated data, you can also easily calculate the sample autocorrelation function in R with the acf() function. It automatically generates a plot of the sample autocorrelation function. Check the documentation of acf for more info.

This exercise is part of the course

Intro to Computational Finance with R

View Course

Exercise instructions

  • Use the ARMAacf function to calculate the theoretical autocorrelations up to lag 10. Assign the result to acf_ma1_model.
  • Construct the plot of the sample autocorrelations up to lag 10 by using the acf() function. Set the title of the plot to "Sample ACF".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

set.seed(123)

# Simulate 250 observations from the described MA(1) model
ma1_sim <- arima.sim(model = list(ma = 0.5), n = 250, mean = 0, sd = 0.1) + 0.05

# Generate the theoretical ACF with upto lag 10
acf_ma1_model <- 

# Split plotting window in three rows
par(mfrow = c(3, 1))

# First plot: The simulated observations
plot(ma1_sim, type = "l", main = "MA(1) Process: mu = 0.05, theta = 0.5", xlab = "time", ylab = "y(t)")
abline(h = 0)

# Second plot: Theoretical ACF
plot(1:10, acf_ma1_model[2:11], type = "h", col = "blue",  ylab = "ACF", main = "theoretical ACF")

# Third plot: Sample ACF
# Assign to tmp the Sample ACF
tmp <- 

# Reset graphical window to only one graph
par(mfrow = c(1, 1))
Edit and Run Code