13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

164

We then created two subsequent series, which I will rename to p t and q t so that we do not

confuse the original names y t and x t with the conventional names for regression reponses and

predictors:

> p <- q <- rep(0, 1000)

> p <- 0.3*z + rnorm(1000)

> q <- 0.6*z + rnorm(1000)

At this stage we can make use of the lm function, which calculates a linear regression between

two vectors. In this instance we will set q t to be the independent variable and p t to be the

dependent variable:

> comb <- lm(p~q)

If we take a look at the comb linear regression model we can see that the estimate for the β

regression coefficient is approximately 0.5, which makes sense given that q t is twice dependent

on z t compared to p t (0.6 compared to 0.3):

> comb

Call:

lm(formula = p ~ q)

Coefficients:

(Intercept)

q

0.1749 0.4745

Finally, we apply the ADF test to the residuals of the linear model in order to test for

stationarity:

> adf.test(comb$residuals, k=1)

Augmented Dickey-Fuller Test

data: comb$residuals

Dickey-Fuller = -23.4463, Lag order = 1, p-value = 0.01

alternative hypothesis: stationary

Warning message:

In adf.test(comb$residuals, k = 1) : p-value smaller than printed p-value

The Dickey-Fuller test statistic is very low, providing us with a low p-value. We can likely

reject the null hypothesis of the presence of a unit root and conclude that we have a stationary

series and hence a cointegrated pair. This is clearly not surprising given that we simulated the

data to have these properties in the first place.

We are now going to apply the CADF procedure to multiple sets of historical financial data.

12.7 CADF on Financial Data

There are many ways of forming a cointegrating set of assets. A common source is to use ETFs

that track similar characteristics. A good example is an ETF representing a basket of gold mining

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

Saved successfully!

Ooh no, something went wrong!