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.

92

9.4.2 Correlogram

The autocorrelation of a random walk (which is also time-dependent) can be derived as follows:

ρ k (t) =

Cov(x t , x t+k )

Var(xt )Var(x t+k ) = tσ 2

tσ2 (t + k)σ = 1

√ (9.7)

2 1 + k/t

Notice that if we are considering a long time series, with short term lags, then we get an

autocorrelation that is almost unity. That is, we have extremely high autocorrelation that does

not decrease very rapidly as the lag increases. We can simulate such a series using R.

Firstly, we set the seed so that you can replicate my results exactly. Then we create two

sequences of random draws (x and w), each of which has the same value (as defined by the seed).

We then loop through every element of x and assign it the value of the previous value of

x plus the current value of w. This gives us the random walk. We then plot the results using

type="l" to give us a line plot, rather than a plot of circular points, see Figure 9.2.

> set.seed(4)

> x <- w <- rnorm(1000)

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

> plot(x, type="l")

Figure 9.2: Realisation of a Random Walk with 1000 timesteps.

It is simple enough to draw the correlogram too, see Figure 9.3.

> acf(x)

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

Saved successfully!

Ooh no, something went wrong!