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.

107

This allows us to compare "apples to apples" between equities, indexes or any other asset,

for use in later multivariate statistics, such as when calculating a covariance matrix.

Let us create a new series, amznrt, to hold our differenced log returns:

> amznrt = diff(log(Cl(AMZN)))

Once again, we can plot the series, as given in Figure 10.5.

> plot(amznrt)

Figure 10.5: First Order Differenced Daily Logarithmic Returns of AMZN Closing Prices.

At this stage we want to plot the correlogram. We are looking to see if the differenced series

looks like white noise. If it does not then there is unexplained serial correlation, which might be

"explained" by an autoregressive model. See Figure 10.6.

> acf(amznrt, na.action=na.omit)

We notice a statististically significant peak at k = 2. Hence there is a reasonable possibility

of unexplained serial correlation. Be aware though, that this may be due to sampling bias. As

such, we can try fitting an AR(p) model to the series and produce confidence intervals for the

parameters:

> amznrt.ar <- ar(amznrt, na.action=na.omit)

> amznrt.ar$order

[1] 2

> amznrt.ar$ar

[1] -0.02779869 -0.06873949

> amznrt.ar$asy.var

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

Saved successfully!

Ooh no, something went wrong!