I'm trying to simulate an MA(1) model in R from scratch in order to obtain more insight into the theoretical underpinnings of the model.
The moving average is defined as follows:
$X_t = \mu + \varepsilon_t + \theta_1 \varepsilon_{t-1} + \cdots + \theta_q \varepsilon_{t-q}$
Where $\epsilon_{t}$ is defined as white noise terms.
This MA(1) model has expected value and autocovariances as written down below:
$E(X_t) = 0$
$Cov(Y_{t} , Y_{t - 1}) = \gamma_{1} = -\theta \sigma_{e}^{2}$
$Cov(Y_{t} , Y_{t - k}) = \gamma_{k} = 0$
I will post my R code below.
ma.sim = function( ma_parameter = c(0.4 , 0.5) , number){
ma_mod_vals = rep(0 , times = number)
# Obtain the sequence of coefficients.
for(i in 1:number){
# create two white noise terms:
white_noise = arima.sim(model = list() , n = 2)
ma_mod_vals[i] = white_noise[1] + ma_parameter[1] * white_noise[2]
}
lister = list(output = ma_mod_vals)
}
I used the code below to generate the 2 white noise terms present in the MA(1) model.
white_noise = arima.sim(model = list() , n = 2)
What I don't understand is why I don't obtain a similar acf plot to the arima.sim function which is used to generate arima models.
For example values simulated using my function yields the following acf plot:
It is clear according to the theory that the acf plot of a MA(1) model should be significant at lag 1. But we see in this plot that the acf value at lag 1 is not significant at all. I suspect that the white noise terms that I am generating are not correct. I think that they should be correlated in some way, but I do not know how to do this.