# Why the spread is calculated on raw prices instead on the price changes?

I'm reading Quantitative Trading With R written by Harry Georgakopoulos. In chapter 6 he exposes a basic quantitative strategy based on setting up a stock spread and buy when it is below a lower threshold and sell when it is above a upper threshold.

Here is where I have my question:

x<- x[time_range] #x is the time series of the price of the stock A
y<- y[time_range] #y is the time series of the price of the stock B

dx<- diff(x) #stock A price changes
dy<- diff(y) #stock B price changes

r<- prcomp( ~ dx + dy) #linear regression using total least squares
beta<- r $$rotation[2,1]/r$$ rotation[1,1]  #slope of the regression line



If we are calculating the regression line between the price changes of the stocks (dx and dy), why we calculate the spread on their raw prices (x and y)? Maybe is an obvious thing, but for me it would be more intuitive to calculate the spread on the price changes.

Thank you.

### That is the concept of Cointegration

Regressing two non-stationary variables results in spurious regression. However, if these two variables are cointegrated, spurious regression no longer arises.

As stated on p. 120,

We call these resulting betas a cointegrating vector.

Cointegration is a statistical property of time series, mainly proposed by Engle/Granger (1987). Assume two time-series $$Y_t$$ and $$X_t$$, which are integrated of order $$d(Y_t, X_t \sim I(d) )$$. If there exists a $$\beta$$ such that $$Y_t - \beta \cdot X_t = u_t$$ ,where $$u_t$$ is integrated of order less than $$d$$ (say $$d-b$$, than $$Y_t$$ and $$X_t$$ are cointegrated of order $$d-b$$.

Especially if $$Y_t$$ and $$X_t$$ are of order 1 (which should be the case for absolute stock prices) and are cointegrated, you do not have to difference the data or use stock return data.

Statistical tests for cointegration are clearly and detailed described in Hayashi (2000), Econometrics and implemented in the R-package urca.