13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

113

1 if k = 0

⎪⎨ q−k

q∑

ACF: ρ k = β i β i+k / if k = 1, . . . , q

i=0

i=0

β 2 i

⎪⎩

0 if k > q

Where β 0 = 1.

We are now going to generate some simulated data and use it to create correlograms. This

will make the above formula for ρ k somewhat more concrete.

10.5.4 Simulations and Correlograms

MA(1)

Let us start with a MA(1) process. If we set β 1 = 0.6 we obtain the following model:

x t = w t + 0.6w t−1 (10.15)

As with the AR(p) model we can use R to simulate such a series and then plot the correlogram.

Since we have had a lot of practice in the previous sections of carrying out plots, I will write the

R code in full, rather than splitting it up:

> set.seed(1)

> x <- w <- rnorm(100)

> for (t in 2:100) x[t] <- w[t] + 0.6*w[t-1]

> layout(1:2)

> plot(x, type="l")

> acf(x)

The output is given in Figure 10.10.

As we saw above in the formula for ρ k , for k > q, all autocorrelations should be zero. Since

q = 1, we should see a significant peak at k = 1 and then insignificant peaks subsequent to that.

However, due to sampling bias we should expect to see 5% (marginally) significant peaks on a

sample autocorrelation plot.

This is precisely what the correlogram shows us in this case. We have a significant peak

at k = 1 and then insignificant peaks for k > 1, except at k = 4 where we have a marginally

significant peak.

This is a useful way of determining whether an MA(q) model is appropriate. By taking a

look at the correlogram of a particular series we can see how many sequential non-zero lags exist.

If q such lags exist then we can legitimately attempt to fit a MA(q) model to a particular series.

Since we have evidence from our simulated data of a MA(1) process we are now going to try

and fit a MA(1) model to our simulated data. Unfortunately there is no equivalent ma command

to the autoregressive model ar command in R.

Instead we must use the more general arima command and set the autoregressive and integrated

components to zero. We do this by creating a 3-vector and setting the first two components

(the autogressive and integrated parameters, respectively) to zero:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!