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.

94

created the difference series, we wish to plot the correlogram and then assess how close this is to

discrete white noise, see Figure 9.4.

> acf(diff(x))

Figure 9.4: Correlogram of the Difference Series from a Simulated Random Walk.

What can we notice from this plot? There is a statistically significant peak at k = 10, but only

marginally. Remember, that we expect to see at least 5% of the peaks be statistically significant,

simply due to sampling variation.

Hence we can reasonably state that the the correlogram looks like that of discrete white noise.

It implies that the random walk model is a good fit for our simulated data. This is exactly what

we should expect, since we simulated a random walk in the first place!

Fitting to Financial Data

Let us now apply our random walk model to some actual financial data. As with the Python

library Pandas we can use the R package quantmod to easily extract financial data from Yahoo

Finance.

We are going to see if a random walk model is a good fit for some equities data. In particular,

I am going to choose Microsoft (MSFT), but you can experiment with your favourite ticker

symbol.

Before we are able to download any of the data we must install quantmod since it is not part

of the default R installation. Run the following command and select the R package mirror server

that is closest to your location:

> install.packages(’quantmod’)

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

Saved successfully!

Ooh no, something went wrong!