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 spread<- y-beta*x
If we are calculating the regression line between the price changes of the stocks (
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.