Simulating a time series including a shock

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?

• Did you perhaps mean "shocking it at time 20" instead of "shocking it at lag 20"? – Richard Hardy Dec 17 '15 at 15:00
• Uhm, I see what you mean. Yeah, that's probably the correct way to say it in words. Anyway, ϵ20=30 is what I mean. – scoglio Dec 17 '15 at 16:59
• I changed "lag" to "time". – Richard Hardy Dec 17 '15 at 17:00

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

Plotting a trajectory yields 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.

• Thank you very much. You're right, I didn't think about that. Actually, I need to represent it in the form Yt=Yt−1+ϵt, with the innovation distributed as GWN(0,1). – scoglio Dec 17 '15 at 14:34
• Just replace the last line with y <- cumsum(innovs) – Christoph Hanck Dec 17 '15 at 14:41
• It sure did! I did, but it doesn't show up, probably because of limitation on my newly created account. – scoglio Dec 17 '15 at 17:01