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.

382

natural gas.

The hypothesis presented here is that the stock price of a large aluminum producer, such as

Alcoa Inc. (ARNC) and that of an ETF representing US natural gas prices, such as UNG might

well be cointegrated and thus lead to a potential mean-reverting systematic trading strategy.

27.2 Cointegration Tests in R

To test the above hypothesis the Cointegrated Augmented Dickey Fuller procedure will be carried

out on ARNC and UNG using R. The procedure has been outlined in depth in a previous chapter

and so the R code below will be replicated here with less explanation.

The first task is to import the R quantmod library for data download as well as the tseries

library for the ADF test. The daily bar data of ARNC and UNG is downloaded for the period

November 11th 2014 to January 1st 2017. The data is then set to the adjusted close values,

which handles splits and dividends:

library("quantmod")

library("tseries")

## Obtain ARNC and UNG

getSymbols("ARNC", from="2014-11-11", to="2017-01-01")

getSymbols("UNG", from="2014-11-11", to="2017-01-01")

## Utilise the backwards-adjusted closing prices

aAdj = unclass(ARNC$ARNC.Adjusted)

bAdj = unclass(UNG$UNG.Adjusted)

Figure 27.1 displays a plot of the prices of ARNC (blue) and UNG (red) over the period.

## Plot the ETF backward-adjusted closing prices

plot(aAdj, type="l", xlim=c(0, length(aAdj)), ylim=c(0.0, 45.0),

xlab="November 11th 2014 to January 1st 2017",

ylab="Backward-Adjusted Prices in USD", col="blue")

par(new=T)

plot(bAdj, type="l", xlim=c(0, length(bAdj)), ylim=c(0.0, 45.0),

axes=F, xlab="", ylab="", col="red")

par(new=F)

It can be seen that the prices of ARNC and UNG follow a broadly similar pattern, which

trends downwards for 2015 and then stays flat for 2016. Displaying a scatterplot will provide a

clearer picture of any potential correlation, which is given in Figure 27.2.

## Plot a scatter graph of the ETF adjusted prices

plot(aAdj, bAdj, xlab="ARNC Backward-Adjusted Prices",

ylab="UNG Backward-Adjusted Prices")

The scatterplot is more ambiguous. There is a slight partial positive correlation, as would

be expected for a company that is heavily exposed to natural gas prices, but whether this is

sufficient to allow a structural relationship is less clear.

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

Saved successfully!

Ooh no, something went wrong!