Pair Trading Lab Algorithms & Strategies

From Pair Trading Lab WIKI
Revision as of 17:58, 11 May 2013 by Admin (Talk | contribs)

Jump to: navigation, search

Pair Trading Lab offers pair trading algorithms based on various mathematical models. In additional, extra trading rules are available on top of that. All these models are supported in both online backtester and PTL Trader. All extra rules are supported in PTL Trader, only some of them in the online backtester. The backtester will be updated later to support all of them too.


Pair Trading Model

Currently supported models are these:

Ratio Model

This is on 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 parameters:

  • entry threshold for Z-score, typical value range is <1.5, 2.5>, 2.0 is used most often
  • exit threshold for Z-score, typical value is <-0.5, 0.5>, 0 is used most often
  • max Z-score (optional, to filter out extremes, typical value is >4 if used)
  • moving average period (typical range <10, 100>), default = 15
  • moving average type (algorithm), default = exponential
  • standard deviation period (typical range <10, 100>), default = 15
  • entry mode (simple, uptick, downtick)

(todo: detailed description)

Residual Model

Residual mode is based on linear regression. Linear regression of both stocks is constructed in order to fit a linear relationship between both instruments and estimate its best parameters. Then, standard deviation is applied on the regression residuum to estimate its statistical properties and calculate Z-score.

Model parameters:

  • entry threshold for Z-score, typical value range is <1.2, 2.5>, 1.5 is used most often
  • exit threshold for Z-score, typical value is <-0.5, 0.5>, 0 is used most often
  • max Z-score (optional, to filter out extremes, typical value is >4 if used)
  • linear regression period (floating window is used), typical range <15, 100>, default = 15

(todo: detailed description)

Trading Hours For Real-Time Trading


You can define trading hours for real-time trading. You can set:

  • time window for opening new positions (start and end hour/minute)
  • time window for closing existing positions (start and end hour/minute)

Currently, only US stocks are supported so these times are meant in New York time zone, which is EST. In future versions you will be able to select another time zone, too. Default time windows are set from 9:45 AM to 3:55 PM EST, which is proper configuration for users who want to trade pairs through the whole trading day. If you want to trade only and the end of day, you can easily change this.

Trading window settings may be changed anytime in PTL Trader, also if there is a position opened.

Instrument Margins

You need to manually setup margins for all instruments you trade, because PTL Trader has no idea what are particular margin requirements. You specify different margin for each leg. Default setting is 50% (leverage 1:2), which is a correct setting for US stocks on Req-T Margin accounts. So as long you just trade stocks, you don't need to change anything. But if you trade ETFs, especially leveraged ones, you must find out current margin yourself and set it right! For instance, for some triple-leveraged ETF like FAS, FAZ the margin should be set to 90%.

Remark for users having Cash Account (no margin): we don't recommend pair trading to you at all, upgrade your account to margin account first!

Remark #1: This is a critical setting for proper management. If you set this wrong, PTL Trader will open either too big or too small positions.

Remark #2: In general, pair trading strategies keep positions overnight. So if you are going to find out your margins, look at overnight ones (intraday margins are lower, but not relevant for this type of trading)

Margin settings may be changed anytime in PTL Trader, also if there is a position opened (then it will apply to newly opened positions).

Extra Rules


In addition to trading rules determined by mathematical models, some extra useful rules are also supported:

Max Days (Time Stop Loss)

  • Type: Additional Exit Rule
  • Support: PTL Backtester & PTL Trader

This is the most important additional rule. It is a very powerful risk control tool of pair trading. The rule says "close pair position after N days in any case". This rule strictly limits your market exposure by automatically closing your position after N days either in profit or loss.

Its purposes are:

  • get rid of pair positions in loss before the pair diverges too much
  • make space (free slots) for other pairs in the portfolio (we don't want pairs to occupy money management slots for too long)

Default value is 20 (so no pair position can last more than 20 days). Useful range is 10-50 days.

Important remark: This is the only automated risk control method used in PTL Trader. Please you should always use this rule, there are no many reasons to keep losing positions for longer than one month. One month is really enough time for pair to converge back, it usually makes no sense to wait much longer. Of course, if you have good reasons to believe your pairs converge after longer periods, no problem - but we usually don't see many pairs like that and these pairs then block slots for long time.

This rule is enabled by default.

Min Price

  • Type: Entry Signal Filter
  • Support: PTL Trader

This rule is a filter for entry signals. It won't allow opening positions if the absolute price of any leg will drop below a predefined threshold value. You may use this filter, if you trade stocks with lower price and don't want prices to drop to "penny stock range". For instance, we don't trade stocks cheaper than 4-6 USD.

Min Profit/Loss

  • Type: Exit Signal Filter
  • Support: PTL Trader

This is an additional filter for exit signals. It will prevent closing positions if current position absolute profit/loss is lower than predefined value. You may use this filter for instance to prevent closing positions in a loss and wait for the break-even situation (then, you set the threshold value to 0, which means do not close position if the P/L is negative).

For those who think about how it can be the mathematical model may close position in the loss - yes, true, you close position when Z-Score crosses your exit threshold point, but please note than the moving average, standard deviation and linear regression drift every day as model is recalculated. So if you hold a pair positions for many days, closing position at your predefined point may not give you profit. Therefore, this rule allows you to hope that your position will still eventually converge (at least to your predefined P/L mark), so effectively you are shifting the exit point below your original model exit threshold value.

Example: If you set the threshold value to 5, it will ignore exit signals until your position P/L is at least 5 USD.

Important Remark: This rule obviously does not apply to the Max Days rule.

Min Profit Potential

  • Type: Entry Signal Filter
  • Support: PTL Trader

This is an additional entry signal filter. This rule tries to estimate (in real-time) the potential profit of position as it was opened at the moment and closed at exit threshold immediately. So it tries to "simulate" the trade and estimate the profit. The problem is the profit can be any, because pair trading model works with the single metric (Z-Score), but you trade two instruments. So there is an infinite number of combinations how and where prices can go to cross the model exit threshold.

This particular "profit estimator" simulates that both prices drop proportionally to the positive direction to match the exit threshold rule.

Please never really think that your trade will actually gain the estimated profit! It could, but most likely it will not. Better, consider this as the "best screnario" profit it can happen.

The purpose of this filter is to prevent opening pair trades on pairs exhibiting low absolute standard deviation at the moment. It is nice the pair Z-Score is crossing your entry threshold, but if the "best scenario" profit potential is just 10 USD, it is probably better to avoid trading until the pair is more volatile, especially considering your would pay at least 4 USD on commissions. It would be foolish to waste slots and risk the trade for 6 USD of net profit in such a case.

The profit estimate threshold is absolute, in USDs. So setting it to 50 means never enter pair trade if the potential estimate is lower than 50 USD.

This rule is most useful to small investors with accounts lower 25,000 USD, to prevent opening pair trades with insignificant absolute profit potential.

The estimated profit potential is displayed in the PTL Trader in real-time, even if the rule is not enabled.

Remark: The estimate can be negative for Residual Model. This is not a bug - it is correct. It may happen in some situations if the A coefficient is negative. For Ratio model, the estimate is always positive.

All extra rules may be modified anytime in PTL Trader, also if there is a position opened.

(todo: more info about the estimate algorithm)

Personal tools