Difference between revisions of "Pair Trading Models"
Line 3: | Line 3: | ||
This is one of the standard pair trading models described in literature. It is based in ratio of instrument prices, [http://en.wikipedia.org/wiki/Moving_average moving average] and [http://en.wikipedia.org/wiki/Standard_deviation standard deviation]. In other words, it is based on [http://en.wikipedia.org/wiki/Bollinger_Bands Bollinger Bands] indicator. | This is one of the standard pair trading models described in literature. It is based in ratio of instrument prices, [http://en.wikipedia.org/wiki/Moving_average moving average] and [http://en.wikipedia.org/wiki/Standard_deviation standard deviation]. In other words, it is based on [http://en.wikipedia.org/wiki/Bollinger_Bands Bollinger Bands] indicator. | ||
− | Model | + | === Model Support === |
* in PTL backtester: '''yes''' (max Z-score not supported) | * in PTL backtester: '''yes''' (max Z-score not supported) | ||
* in PTL portfolio backtester: '''yes''' | * in PTL portfolio backtester: '''yes''' | ||
* in PTL Trader: '''yes''' | * in PTL Trader: '''yes''' | ||
− | Model | + | === Model Neutrality === |
+ | We currently support only dollar-neutral version of this model, which means we allocate same amounts of margin to both legs based on current prices at the time of opening the position. | ||
+ | |||
+ | === Model Parameters === | ||
* entry threshold E<sub>n</sub> for Z-score, typical value range is <1.5, 2.5>, 2.0 is used most often | * entry threshold E<sub>n</sub> for Z-score, typical value range is <1.5, 2.5>, 2.0 is used most often | ||
* exit threshold E<sub>x</sub> for Z-score, typical value is <-0.5, 0.5>, 0 is used most often...we allow positive values only for now | * exit threshold E<sub>x</sub> for Z-score, typical value is <-0.5, 0.5>, 0 is used most often...we allow positive values only for now | ||
Line 17: | Line 20: | ||
* entry mode (simple, uptick, downtick) | * entry mode (simple, uptick, downtick) | ||
− | Description | + | === Description === |
* we trade pair of stocks A, B, having price series ''A(t)'', ''B(t)'' | * we trade pair of stocks A, B, having price series ''A(t)'', ''B(t)'' | ||
* we need to calculate ratio time series ''R(t)'' = ''A(t)'' / ''B(t)'' | * we need to calculate ratio time series ''R(t)'' = ''A(t)'' / ''B(t)'' | ||
Line 30: | Line 33: | ||
** these bands are actually the same bands as in [http://en.wikipedia.org/wiki/Bollinger_Bands Bollinger Bands] indicator and we can use crossing of ''R(t)'' and bands as trade signals | ** these bands are actually the same bands as in [http://en.wikipedia.org/wiki/Bollinger_Bands Bollinger Bands] indicator and we can use crossing of ''R(t)'' and bands as trade signals | ||
− | + | === Entering Position === | |
− | * | + | There are certain possible approaches how to interpret model statistics in order to make trading decisions. For entering position, we used to call them '''entry modes'''. This is the list of them and description how they work: |
+ | * entry mode = '''simple''': | ||
** to open short pair position, it is simple enough if the Z-score ''Z(t)'' >= E<sub>n</sub> (equivalent to ''R(t)'' >= ''U<sub>n</sub>(t)'') | ** to open short pair position, it is simple enough if the Z-score ''Z(t)'' >= E<sub>n</sub> (equivalent to ''R(t)'' >= ''U<sub>n</sub>(t)'') | ||
** to open long pair position, it is simple enough if the Z-score ''Z(t)'' <= -E<sub>n</sub> (equivalent to ''R(t)'' <= ''L<sub>n</sub>(t)'') | ** to open long pair position, it is simple enough if the Z-score ''Z(t)'' <= -E<sub>n</sub> (equivalent to ''R(t)'' <= ''L<sub>n</sub>(t)'') | ||
− | * | + | * entry mode = '''uptick''': same as simple, but in addition, previous Z-score must be below the entry band (so we cross the band from inside to outside): |
** to open short pair position, we require ''Z(t)'' >= E<sub>n</sub> (equivalent to ''R(t)'' >= ''U<sub>n</sub>(t)'') '''and''' ''Z(t-1)'' < E<sub>n</sub> (same as ''R(t-1)'' < ''U<sub>n</sub>(t-1)'') | ** to open short pair position, we require ''Z(t)'' >= E<sub>n</sub> (equivalent to ''R(t)'' >= ''U<sub>n</sub>(t)'') '''and''' ''Z(t-1)'' < E<sub>n</sub> (same as ''R(t-1)'' < ''U<sub>n</sub>(t-1)'') | ||
** to open long pair position, we require ''Z(t)'' <= -E<sub>n</sub> (equivalent to ''R(t)'' <= ''L<sub>n</sub>(t)'') '''and''' ''Z(t-1)'' > -E<sub>n</sub> (same as ''R(t-1)'' > ''L<sub>n</sub>(t-1)'') | ** to open long pair position, we require ''Z(t)'' <= -E<sub>n</sub> (equivalent to ''R(t)'' <= ''L<sub>n</sub>(t)'') '''and''' ''Z(t-1)'' > -E<sub>n</sub> (same as ''R(t-1)'' > ''L<sub>n</sub>(t-1)'') | ||
− | * | + | * entry mode = '''downtick''': we wait for the Z-score crossing back the band from outside to inside: |
** to open short pair position, we require ''Z(t)'' < E<sub>n</sub> '''and''' ''Z(t-1)'' >= E<sub>n</sub> '''and''' ''Z(t)'' > E<sub>x</sub> | ** to open short pair position, we require ''Z(t)'' < E<sub>n</sub> '''and''' ''Z(t-1)'' >= E<sub>n</sub> '''and''' ''Z(t)'' > E<sub>x</sub> | ||
** when using bands, it is the same as having ''R(t)'' < ''U<sub>n</sub>(t)'' '''and''' ''R(t-1)'' >= ''U<sub>n</sub>(t-1)'' '''and''' ''R(t)'' > ''U<sub>x</sub>(t)'' | ** when using bands, it is the same as having ''R(t)'' < ''U<sub>n</sub>(t)'' '''and''' ''R(t-1)'' >= ''U<sub>n</sub>(t-1)'' '''and''' ''R(t)'' > ''U<sub>x</sub>(t)'' | ||
Line 43: | Line 47: | ||
** when using bands, it is the same as having ''R(t)'' > ''L<sub>n</sub>(t)'' '''and''' ''R(t-1)'' <= ''L<sub>n</sub>(t-1)'' '''and''' ''R(t)'' < ''L<sub>x</sub>(t)'' | ** when using bands, it is the same as having ''R(t)'' > ''L<sub>n</sub>(t)'' '''and''' ''R(t-1)'' <= ''L<sub>n</sub>(t-1)'' '''and''' ''R(t)'' < ''L<sub>x</sub>(t)'' | ||
− | Why we have the '''simple entry mode'''? In normal situations and backtests, it gives same results as the '''uptick mode'''. But the difference comes up while trading multiple pairs in portfolio. The simple mode allows you to jump in the position immediately after a new slot is freed, regardless of the previous Z-scores. | + | Why do we have the '''simple entry mode'''? In normal situations and backtests, it gives same results as the '''uptick mode'''. But the difference comes up while trading multiple pairs in portfolio. The simple mode allows you to jump in the position immediately after a new slot is freed, regardless of the previous Z-scores. |
+ | |||
+ | '''Which entry mode is better?''' Hard to tell, sometimes the uptick, sometimes the downtick. You have to do your homework and decide, which idea suits your trading style better. In general, uptick/simple mode is more aggressive, as it does not wait for first signs of spread mean reversion. | ||
− | + | === Exiting Position === | |
+ | For exiting position, we always use only these simple rules: | ||
+ | * we exit short position when ''Z(t)'' <= E<sub>x</sub> (equivalent to ''R(t)'' <= ''U<sub>x</sub>(t)'') | ||
+ | * we exit long position when ''Z(t)'' >= -E<sub>x</sub> (equivalent to ''R(t)'' >= ''L<sub>x</sub>(t)'') |
Revision as of 11:51, 26 November 2014
Pair Trading Lab offers pair trading algorithms based on various mathematical models. These are models currently supported in PTL:
Contents |
Ratio Model
This is one of the standard pair trading models described in literature. It is based in ratio of instrument prices, moving average and standard deviation. In other words, it is based on Bollinger Bands indicator.
Model Support
- in PTL backtester: yes (max Z-score not supported)
- in PTL portfolio backtester: yes
- in PTL Trader: yes
Model Neutrality
We currently support only dollar-neutral version of this model, which means we allocate same amounts of margin to both legs based on current prices at the time of opening the position.
Model Parameters
- entry threshold En for Z-score, typical value range is <1.5, 2.5>, 2.0 is used most often
- exit threshold Ex for Z-score, typical value is <-0.5, 0.5>, 0 is used most often...we allow positive values only for now
- max Z-score Emax (optional, to filter out extremes, typical value is >4 if used)
- moving average period Pm (typical range <10, 100>), default = 15
- moving average type T (algorithm), default = exponential
- standard deviation period Ps (typical range <10, 100>), default = 15
- entry mode (simple, uptick, downtick)
Description
- we trade pair of stocks A, B, having price series A(t), B(t)
- we need to calculate ratio time series R(t) = A(t) / B(t)
- let's apply moving average of type T with period Pm on R(t) to get time series M(t)
- let's apply standard deviation with period Ps on R(t) to get time series S(t)
- now we can create Z-score series Z(t) as Z(t) = (R(t) - M(t)) / S(t), this time series can give us z-score to signal trading decision directly
- another common approach (to visualize) is to create bands and put it above the moving average M(t):
- upper entry band Un(t) = M(t) + S(t) * En
- lower entry band Ln(t) = M(t) - S(t) * En
- upper exit band Ux(t) = M(t) + S(t) * Ex
- lower exit band Lx(t) = M(t) - S(t) * Ex
- these bands are actually the same bands as in Bollinger Bands indicator and we can use crossing of R(t) and bands as trade signals
Entering Position
There are certain possible approaches how to interpret model statistics in order to make trading decisions. For entering position, we used to call them entry modes. This is the list of them and description how they work:
- entry mode = simple:
- to open short pair position, it is simple enough if the Z-score Z(t) >= En (equivalent to R(t) >= Un(t))
- to open long pair position, it is simple enough if the Z-score Z(t) <= -En (equivalent to R(t) <= Ln(t))
- entry mode = uptick: same as simple, but in addition, previous Z-score must be below the entry band (so we cross the band from inside to outside):
- to open short pair position, we require Z(t) >= En (equivalent to R(t) >= Un(t)) and Z(t-1) < En (same as R(t-1) < Un(t-1))
- to open long pair position, we require Z(t) <= -En (equivalent to R(t) <= Ln(t)) and Z(t-1) > -En (same as R(t-1) > Ln(t-1))
- entry mode = downtick: we wait for the Z-score crossing back the band from outside to inside:
- to open short pair position, we require Z(t) < En and Z(t-1) >= En and Z(t) > Ex
- when using bands, it is the same as having R(t) < Un(t) and R(t-1) >= Un(t-1) and R(t) > Ux(t)
- to open long pair position, we require Z(t) > -En and Z(t-1) <= -En and Z(t) < -Ex
- when using bands, it is the same as having R(t) > Ln(t) and R(t-1) <= Ln(t-1) and R(t) < Lx(t)
Why do we have the simple entry mode? In normal situations and backtests, it gives same results as the uptick mode. But the difference comes up while trading multiple pairs in portfolio. The simple mode allows you to jump in the position immediately after a new slot is freed, regardless of the previous Z-scores.
Which entry mode is better? Hard to tell, sometimes the uptick, sometimes the downtick. You have to do your homework and decide, which idea suits your trading style better. In general, uptick/simple mode is more aggressive, as it does not wait for first signs of spread mean reversion.
Exiting Position
For exiting position, we always use only these simple rules:
- we exit short position when Z(t) <= Ex (equivalent to R(t) <= Ux(t))
- we exit long position when Z(t) >= -Ex (equivalent to R(t) >= Lx(t))