I'm having a difficulty grasping how to write a pair algorithm using returns instead of prices.

With price differences, I have the mean difference over a long time period. When the current price difference moves away from the mean I open a position. When it moves back to the mean I close then position.

With returns, I have the mean difference in returns between two stocks. What am I looking to move away from this mean? Is it just when a single period returns deviates? If so, when do I close.

A single day may be above the mean so I open. It should come back, but how do I know when its happened? If the next day is below the mean I dont think its time to close. It just working back down, but still pay not be all the way back.


1 Answer 1


Hi Don: The following is a very standard approach. It's basically the use of Bollinger Bands on the log ratio of the two prices.

So, say one stock is y and the other stock is x. Denote the prices as $P_y$ and $P_x$.

Then, you do the following.

1) Keep calculating the moving average of $log(\frac{P_y}{P_x})$ over time along with the moving standard deviation of the same thing.

2) When $log(\frac{P_y}{P_x})$ is $ 2 \sigma$ above the moving average, you go long y and you go short x. When it's $2 \sigma$ below the moving average, you go short y and go long x.

Note that 2) is really what technicians use in Bollinger Bands except that it's on the log price ratio rather than the log price.

3) Exit the position when the log price ratio returns to the moving average.

There are many parameters that you can experiment with:

A) the window size of the moving average in days or hours or minutes or whatever.

B) the scale factor that multiplies sigma. It doesn't have to be 2.

C) Exit rule. You don't have to wait until you return to the moving average. In fact, it could pay to get out earlier than that in order to avoid large losses.

D) Letting position size be proportional to how strong the reversion is.

Obviously, the pairs you use are key to the whole thing and figuring those out is kind of seperate from the step described above. I hope this helped some.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.