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.

166

Figure 12.6: Backward-adjusted closing prices of EWA and EWC

You will notice that it differs slightly from the chart given in Ernie’s work as we are plotting

the adjusted prices here, rather than the unadjusted closing prices. We can also create a scatter

plot of their prices:

> plot(ewaAdj, ewcAdj, xlab="EWA Backward-Adjusted Prices",

ylab="EWC Backward-Adjusted Prices")

At this stage we need to perform the linear regressions between the two price series. However,

we have previously mentioned that it is unclear as to which series is the dependent variable and

which is the independent variable for the regression. Thus we will try both and make a choice

based on the negativity of the ADF test statistic. We will use the R linear model (lm) function

for the regression:

> comb1 = lm(ewcAdj~ewaAdj)

> comb2 = lm(ewaAdj~ewcAdj)

This will provide us with the intercept and regression coefficient for these pairs. We can plot

the residuals and visually assess the stationarity of the series:

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

xlab="April 26th 2006 to April 9th 2012",

ylab="Residuals of EWA and EWC regression")

We can also view the regression coefficients starting with EWA as the independent variable:

> comb1

Call:

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

Saved successfully!

Ooh no, something went wrong!