Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pair trade spread increases, but shouldn't.

I am working with a pair trading scenario and I can't figure out why my algorithm thinks the spread has increased.

My mean is 6.5697 and the standard deviation is 4.02. Using sm.OLS(y, x).fit() I get a coefficient for the linear combination of 0.936.

I start with:
x=179.89
y=170.19

These prices give me a spread 1.81. That's (170.19 - (0.936 * 179.89)_.
The zvalue is -1.18. That's ((1.81 - 6.5697)/4.02)
The difference between the raw prices is 9.70.

I make a bet that the spread will increase. Meaning, I go long the spread. I buy a long position of x and I short y.
Intuitively, I would profit if x increases and profit it y decreases. That is also an increasing spread.

Eventually the price gets to:
x=179.85
y=174.71

My long dropped. My short increased. And the raw price different drops to 5.14.
I understand this should be a loser because the difference decreased. However, my algorithm thinks the spread increased and I can't figure out why.

The spread with the final prices is 6.37. That's an increase, but I am not intuitively grasping this.
I use the same coefficient as the start - 0.936, which gives:
That's 174.71 - (0.936 * 179.85) = 6.37.

The spread increased went from 1.81 to 6.37, but the raw difference decreases, and the trade loses money.

Do I have something flipped here?
I have been stuck on this for 2 days.