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.

80

8.2 Correlation

Correlation is a dimensionless measure of how two variables vary together, or "co-vary". In

essence, it is the covariance of two random variables normalised by their respective spreads. The

(population) correlation between two variables is often denoted by ρ(x, y):

ρ(x, y) = E[(x − µ x)(y − µ y )] σ(x, y)

= (8.2)

σ x σ y σ x σ y

The denominator product of the two spreads will constrain the correlation to lie within the

interval [−1, 1]:

• A correlation of ρ(x, y) = +1 indicates exact positive linear association

• A correlation of ρ(x, y) = 0 indicates no linear association at all

• A correlation of ρ(x, y) = −1 indicates exact negative linear association

As with the covariance, we can define the sample correlation, Cor(x, y):

Cor(x, y) =

Cov(x,y)

sd(x)sd(y)

(8.3)

Where Cov(x, y) is the sample covariance of x and y, while sd(x) is the sample standard

deviation of x.

8.2.1 Example: Sample Correlation in R

We will use the same x and y vectors of the previous example. The following R code will calculate

the sample correlation:

> cor(x,y)

[1] 0.5796604

The sample correlation is given as 0.5796604 showing a reasonably strong positive linear

association between the two vectors, as expected.

8.3 Stationarity in Time Series

Now that we have outlined the definitions of expectation, variance, standard deviation, covariance

and correlation we are in a position to discuss how they apply to time series data.

Firstly, we will discuss a concept known as stationarity. This is an extremely important

aspect of time series and much of the analysis carried out on financial time series data will

concern stationarity. Once we have discussed stationarity we are in a position to talk about

serial correlation and construct some correlogram plots.

We will begin by trying to apply the above definitions to time series data, starting with the

mean/expectation:

Definition 8.3.1. Mean of a Time Series. The mean of a time series x t , µ(t), is given as the

expectation E(x t ) = µ(t).

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

Saved successfully!

Ooh no, something went wrong!