I'm reading a quantitative trading book"Quantitative Trading with R" by Harry Georgakopoulos.
In the pairs trading section, there's an example that creates the spread and generate buy/sell signals.
y and x are the price changes of two correlated stocks.
data$spread <- y - hedge_ratio*x threshold <- sd(data$spread, na.rm = TRUE) # Generate sell and buy signals buys <- ifelse(data_out$spread > threshold, 1, 0) sells <- ifelse(data_out$spread < -threshold, -1, 0)
I don't understand why do we buy the spread if spread>threshold... In my opinion, if spread>threshold means it is valuable, so we should sell it but in the example, the spread is bought.