I am testing a simple pair trading algorithm and I'm having problems if I swap the stocks around. I don't know which stock should be X and which should be Y. When I swap them I get very different results.
I would expect the returns to the be the same when swapped. I may want to long an spread, and if I swap them around would want to short it. Since I swapped, I should still be longing and shorting the same securities.
Here is a tedious example that I worked up in excel:
X Y 164.603 155.845 166.226 156.417 168.312 159.387 164.908 155.588 166.571 156.614
I calculate the slope as slope(y1:y5, x1,x5) which gives me a hedge factor of 0.963. Then I create a spread for each value with the formula Y-hedge*X, which gives me this series:
-2.668778868 -3.659738615 -2.698570426 -3.219495888 -3.794975899
The mean of this series is -3.208 and the standard deviation is 0.52417.
Assume X moves to 164 and y moves to 154. Now my spread value is -3.93309. This gives me a Z value of -1.38271. I want to long Y and short X. I want to exit when the zscore returns to near zero. Assume X moves to 163.40 and Y moves to 154.19. My new zscore is 0.08. So I exit the trade with a profit. (my long went up and my short went down).
Now if I swap X and Y the hedge factor changes, and the mean of my spread is vastly different (16.6 vs -3.2).
When X moves to 154 and y moves to 164 (same as above but swapped) the zscore is 2.13. I would want to sort Y and long X, but since I swapped the order I am longing and short the same as before. Now when X moves to 154.19 and Y moves to 163.40 my zscore moves to 48.03. I don't exit - I am waiting for it to return to near zero.
I think I am missing something simple.