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.

384

## Carry out linear regression on the two price series

comb = lm(aAdj~bAdj)

> comb

Call:

lm(formula = aAdj ~ bAdj)

Coefficients:

(Intercept)

bAdj

11.039 1.213

In the linear regression where UNG is the independent variable the slope is given by 1.213.

The final task is to carry out the ADF test and determine whether there is any structural

cointegrating relationship:

## Now we perform the ADF test on the residuals,

## or "spread" of the model, using a single lag order

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

Augmented Dickey-Fuller Test

data: comb$residuals

Dickey-Fuller = -2.5413, Lag order = 1, p-value = 0.3492

alternative hypothesis: stationary

This analysis shows that there is not sufficient evidence to reject the null hypothesis of no

cointegrating relationship. However despite this it is instructive to continue implementing the

strategy with the hedging ratio calculated above for two reasons:

1. Any other potential cointegration-based analysis as derived from the CADF or the Johansen

test can be backtested using the following code since it has been written to be flexible

enough to cope with large cointegrated portfolios.

2. It is valuable to see how a strategy performs when there is insufficient evidence to reject

the null hypothesis. Perhaps the pair is still tradeable even though a relationship has not

been detected on this small dataset.

The trading strategy mechanism will now be outlined.

27.3 The Trading Strategy

In order to actually generate tradeable signals with a mean-reverting "spread" of prices from a

linear combination of ARNC and UNG a technique known as Bollinger Bands will be utilised.

Bollinger Bands involve taking a rolling simple moving average (SMA) of a price series and

then forming "bands" surrounding the series that are a scalar multiple of the rolling standard

deviation of the price series. The lookback period for the moving average and standard deviation

is identical. In essence they are an estimate of current volatility for a price series.

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

Saved successfully!

Ooh no, something went wrong!