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.

170

> plot(rdsaAdj, rdsbAdj,

xlab="RDS-A Backward-Adjusted Prices",

ylab="RDS-B Backward-Adjusted Prices")

Figure 12.10: Scatter plot of backward-adjusted closing prices for RDS-A and RDS-B

Once again we utilise the linear model lm function to ascertain the regression coefficients,

making sure to swap the dependent and independent variables for the second regression. We can

then plot the residuals of the first regression:

> comb1 = lm(rdsaAdj~rdsbAdj)

> comb2 = lm(rdsbAdj~rdsaAdj)

> plot(comb1$residuals, type="l",

xlab="January 1st 2006 to December 31st 2015",

ylab="Residuals of RDS-A and RDS-B regression")

Finally, we can calculate the ADF test-statistic to ascertain the optimal hedge ratio. For the

first linear combination:

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

Augmented Dickey-Fuller Test

data: comb1$residuals

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

alternative hypothesis: stationary

Warning message:

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

Saved successfully!

Ooh no, something went wrong!