4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Did you perhaps mean "shocking it at time 20" instead of "shocking it at lag 20"? $\endgroup$ – Richard Hardy Dec 17 '15 at 15:00
  • $\begingroup$ 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. $\endgroup$ – scoglio Dec 17 '15 at 16:59
  • 1
    $\begingroup$ I changed "lag" to "time". $\endgroup$ – Richard Hardy Dec 17 '15 at 17:00
4
$\begingroup$
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.

$\endgroup$
  • $\begingroup$ 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). $\endgroup$ – scoglio Dec 17 '15 at 14:34
  • $\begingroup$ Just replace the last line with y <- cumsum(innovs) $\endgroup$ – Christoph Hanck Dec 17 '15 at 14:41
  • 1
    $\begingroup$ It sure did! I did, but it doesn't show up, probably because of limitation on my newly created account. $\endgroup$ – scoglio Dec 17 '15 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.