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.

102

10.4.4 Simulations and Correlograms

AR(1)

Let us begin with an AR(1) process. This is similar to a random walk, except that α 1 does

not have to equal unity. Our model is going to have α 1 = 0.6. The R code for creating this

simulation is given as follows:

> set.seed(1)

> x <- w <- rnorm(100)

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

Notice that our for loop is carried out from 2 to 100, not 1 to 100, as x[t-1] when t = 0 is

not indexable. Similarly for higher order AR(p) processes, t must range from p to 100 in this

loop.

We can plot the realisation of this model and its associated correlogram using the layout

function, given in Figure 10.1.

> layout(1:2)

> plot(x, type="l")

> acf(x)

Figure 10.1: Realisation of AR(1) Model, with α 1 = 0.6 and Associated Correlogram.

We can now try fitting an AR(p) process to the simulated data that we have just generated

to see if we can recover the underlying parameters. You may recall that we carried out a similar

procedure in the previous chapter on white noise and random walks.

R provides a useful command ar to fit autoregressive models. We can use this method to

firstly tell us the best order p of the model (as determined by the AIC above) and provide us

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

Saved successfully!

Ooh no, something went wrong!