Solved – Simulating a time series including a shock

arimalagsrsimulationtime series

I want to simulate a time series in R, following an ARMA(1,0) model in the form $Y_t = Y_{t-1} + \epsilon_t$, shocking it at time 20.
In a few words, I therefore have to input $\epsilon_{20} = 30$ (the shock magnitude).

Now, I am using the arima.sim function as it is the one I'm familiar with for simulating a time series, but I am not sure on how to implement a shock into it.

Let's start with a standard simulation, based on 250 observations:

shocksim <- arima.sim(n=250, list(ar = c(0.5)))

How can I input the shock in such a simulation?

Best Answer

n <- 250
innovs <- rnorm(n)
innovs[20] <- 30
y <- arima.sim(n=n,innov=innovs, list(ar = c(0.5)))

Plotting a trajectory yields

enter image description here

Note your code says you want an AR(1) process with coefficient 0.5 while the text specifies a random walk. I did the former.

Related Question