Pair Trading Implementation in NeuroShell Trader

Requires the Advanced Indicator Set 3 Add-on.

There are many ways that pairs of instruments (usually equities) can be “pair traded” in a market neutral fashion. The purpose of this documentation is not to explain the various theories and their validity, but to demonstrate the use of the pair indicators in NeuroShell Trader.

How to build Trading Strategies with the Pair Indicators
The pair indicators will allow you to build a Trading Strategy (with a protective stop) that goes long on one stock at the same time it goes short on another stock in the same chart. Stocks will be used in this example, but other instruments may be pair traded.

You begin by picking two stocks with prices that closely follow one another over time, and in fact cross one another regularly. In most cases, the comparisons are based on daily data. Agilent (A) and Analog Devices (ADI) are a good illustration of a tradeable pair.

Once you’ve identified the stocks, the question becomes how to make these market neutral opposite trades simultaneously in NeuroShell Trader when both stocks are in the same chart. The key is to let NeuroShell Trader distinguish between the two chart pages, and know which one it is processing, so it can determine whether to go long or short. The pair indicators include several key parameters that keep track of which stock is being processed. The PairEntry and PairExit indicators along with their proxy versions are a unique class of indicators which generate signals that cause the NeuroShell Trader to go long on one stock and simultaneously short on another stock.

If you’re using the Pair indicators, your NeuroShell Trader chart should include a chart page for each stock in the pair. In addition, you need to insert the close of both stocks as other instrument data using the NeuroShell Trader’s Insert Menu. This technique allows both close values to be included in the calculations on each chart page.

Once the chart is set up, you begin building a market neutral system by inserting a Trading Strategy into the chart. By using the Pair indicators, this single Trading Strategy is sufficient to create the opposite buy/sell signals on both chart pages.

Long Entry condition:
Relational indicator A = B
A = PairEntry indicator from Advanced Indicator Set 3.
B = 1   (A value of 1 should be used on a Long Entry and a value of -1 should be used on the Short Entry. These values are used to keep track of the two stocks in the pair trade and should not be optimized.)

Close = Close (Keep the default value. It is used to keep track of the stocks)
Price1 = the close of the first stock in the pairs trade (use the other instrument data version of the close)
Price2 = the close of the second stock in the pairs trade (use the other instrument data version)
Spread = the amount of the spread between the two stock prices which must occur before a trade is entered (this may be optimized).

Note: It doesn’t matter which stock is designated as Price 1 and which stock is designated as Price 2, but it is important that the same stocks be listed in the same order on all of the Long Entry, Long Exit, Short Entry and Short Exit conditions. Listing the stocks in alphabetical order may help you remember the order.

The PairEntry indicator compares the value of the close, which is different for each chart page, to the value of Pricel and Price2 and determines which stock goes long and which stock goes short. The values of Pricel and Price2 are also used to compute the spread between stocks in order to determine an entry point for the trade.

Long Exit condition:

Close = Close (keep the default value)
Pricel = the close of the first stock (other instrument data version, same order as pair entry)
Price2 = the close of the second stock (other instrument data version, same order as pair entry)
Spread = the value of the spread between the stock prices where you want to exit a trade (may be optimized) StopSpread = the “emergency” exit for the trade, equivalent to a stop. This will be a wider spread than the entry spread in the PairEntry. If the spread widens, the stop will occur.

Both the PairEntry and PairExit conditions cannot be combined with other rules or trailing or protective stops. The PairExit indicator includes the StopSpread parameter that can be set as an emergency exit for both stocks. If the StopSpread exit occurs, the trade will not be entered again until the spread falls below the entry spread and then crosses above the entry spread.

Short Entry and Short Exit
Pair trading requires that you enter short entry and exit conditions in addition to the long entry and exits in order to keep the trades in balance. You can copy the PairEntry and PairExit conditions from the Long side and you only need to make one modification. On the Short Entry tab in the A = B rule, change the value of B to -1 (this value should not be optimized). The Short Exit tab uses the same PairExit indicator and values as the rule in the Long Exit tab.

Linking Entry and Exit Spreads
The NeuroShell Trader can optimize the spread values for you in order to find the best entry and exit points. However, in order for the long and short entries to work in tandem, the spreads need to be the same. The NeuroShell Trader makes it easy to link these values. First set up all of the trading rules as described above. Next go to Trading Strategy parameters, Rules tab, and select parameter search. Return to the Long Entry tab and click on the + sign in front of the rule.

Select the spread search space parameter, and then click on the Modify Parameter button.

Choose “Associate with the following parameter optimization link” button and click on the Add new link button. Enter a name such as “Entry Spread” and enter an appropriate range for the stock pair. (More on selecting an appropriate range later.)

Next, you need to make the same selection on the Short Entry tab. When it comes to choosing a name, you can select Entry Spread (click on the down arrow if this name is not visible).

On the Long Exit and Short Exit tabs, you need to add a new link for the Exit Spread and another for the Stop Spread (the emergency exit if the spread trade starts going against you) in the PairExit indicators.

Selecting Spread Ranges
The default values for the spread parameters should be changed based on the specific pairs being traded. Sometimes you can “eyeball” the spreads between the two instruments and set the ranges appropriately.

Suggested Settings:
Highest entry spread < the lowest stop spread

Highest exit spread < lowest entry spread

Another approach is to calculate the absolute value of the differences between the two instruments and use this value plus and minus a few price points to set the entry spread ranges, followed by setting the Exit Spread and Stop Spread ranges according to the rules above. (Both the absolute value and subtraction indicators are in the NeuroShell Trader’s Arithmetic category of indicators.) Experience has shown that setting spread values appropriately can greatly affect a model’s success.

Setting Trading Strategy Parameters
Successful pair trading requires specific settings for some of the Trading Strategy parameters. These settings are described below:

Rules tab: select Parameter search to allow the genetic algorithm to find the best spreads for the entry and exit rules.

Trading tab: select Buy a fixed amount of shares and enter the dollar (or other currency) amount for each one of the pair. For example, if you enter $5000, you must have $10,000 in your account in order to pay for both sides of the pair trade.

Dates and Costs tabs: set according to your preferences.

Optimization tab: it is very important that you select the button to optimize across all chart pages in order for your pair trading system to buy and sell both stocks in tandem. The optimization objective is a matter of preference, but you might want to try maximize net profit rather than maximize return on account * equity curve correlation. The balanced nature of pair trading should account for an overall profitable equity curve.

When optimization is finished, click Finished to display the buy/sell signals on the chart. You’ll note that when you see a buy signal on one chart page, you should see a corresponding sell signal on the other chart page.

Click here to download the example chart.  (You must own Advanced Indicator Set 3 to use the chart.)


Was this article helpful?