September 2020 Newsletter – Use Neural Nets to Create a Co-integrated Pair Trade

Requires the Advanced Indicator Set 3 Add-On

NeuroShell Trader lets you build pair trading models even when the prices do not cross. The proxy indicators from the Advanced Indicator Set 3 add-on can utilize a neural net to create a co-integrated pair.

The net can “compute” one stock as a linear combination of the other, such that the stocks follow one another in a stable fashion and cross prices.

The ProxyEntry and ProxyExit indicators generate simultaneous buy/sell signals for two different chart pages in the same chart.

Stocks will be used in this example, but other instruments may be pair traded.

The Net Decides Which Stocks to Pair
For example, if you have stock A with a historical price around $20 a share and stock B around $30 a share, their prices are not likely to cross. You can still trade these two stocks as a pair by using the price of Stock A to predict the price of Stock B.

If there are other stocks that might be used to predict Stock B, you can even let the neural net figure out which single stock should be used to predict Stock B.

You begin by setting up a chart for the stock that you are trying to predict, CISCO in this example. (It doesn’t matter which stock is predicted and which one is the input, as long as they follow one another.)

Then you insert as other instrument data the close of the stocks you want to use as inputs to the prediction: in our example, Agilent Tech, Juniper, and Verizon. Next you create a prediction with the close of these other stocks as inputs to the net.

Proxy Predictions:
Training Criteria Require Specific Settings

  1. Output tab – for the predicted value, select Other data/Indicators and then choose the close of the stock you are predicting. Set it to predict 0 trading days into the future.
  1. Inputs tab – choose Input Selection. You can start with several stocks and let the net decide which is the best one to include in the pair, as long as the net has to choose only one input (see 5 below).
  1. Positions tab – select No Trading Positions.
  1. Training tab – for training objective, choose Minimize Mean squared Error, and 0 hidden neurons to create a linear model.
  1. Optimization tab – set the maximum number of inputs to 1. This forces the net to select only one stock as an input to the net.

Which Stock Did the Net Pick?

Once you’ve set up the Training Criteria, you can train the prediction until it has a low mean squared error. You can examine the prediction results and see which input the net used to make the prediction.

The net computes the Cisco close as a linear combination of the Juniper close.

Caution – to assure a good hedge, make sure that the prediction is correlated (moves in the same direction) as the input (Juniper in this case). Sometimes the best fit prediction is an inverse of the input, which destroys the hedge.

Set Up the Trading Strategy

When training is complete, you can use the spread of the predicted price of Cisco with the actual price of Cisco to generate pair trading signals.  The ProxyEntry and ProxyExit indicators will generate simultaneous buy/sell signals for Cisco and Juniper. Look at the second subgraph in the chart above to view the cross.

To begin building the Trading Strategy, you need to add a chart page for Juniper, the winning input to the neural net.

The question then becomes how to make market neutral opposite trades in NeuroShell when both stocks are in the same chart.  Usually NeuroShell creates models for each stock that trade independently from one another. The key is to let NeuroShell distinguish between the two chart pages, and know which one it is processing, so it can determine whether to go long or short.

The proxy pair indicators keep track of which stock is being processed.  The ProxyEntry and ProxyExit indicators are several of a unique class of indicators that produce trading signals that cause the NeuroShell Trader to go long on one stock and simultaneously short on another stock within the same chart.

You insert the proxy indicators into a Trading Strategy as follows:

Relational Indicator A = B
A = ProxyEntry indicator from Advanced Indicator Set 3
B = 1 for Long Entry or -1 for Short Entry

Proxy Entry
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)
Proxy1 = the actual value of the close of the predicted stock (Note: this is not really a proxy in this case)
Proxy2 = the predicted value of the close. (Note: since we are predicting 0 bars ahead, it doesn’t really matter whether you use the prediction or the prediction signal.)
Spread = the amount of spread between proxy1 and proxy2 at which must occur before a trade is entered (this may be optimized)

Note: It doesn’t matter which stock is designated as Price1 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. The same applies to Proxy1 and Proxy2.

When building the Trading Strategy, the ProxyEntry indicator compares the value of the close, which is different for each chart page, to the value of Price1 and Price2 and determines which stock goes long and which stock goes short. The values of Proxy1 and Proxy2 are used to compute the spread between actual and predicted values from the neural net in order to determine an entry point for the trade.

Simply insert the Proxy Exit indicator. Settings are the same for Long Exit and Short Exit.

Proxy Exit
Close = Close (keep the default value)
Proxy1 = the actual close of the predicted stock
Proxy2 = the predicted value of the stock
Spread = the amount of the spread between the actual and predicted value of the stock 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 ProxyEntry. If the spread widens, the stop will occur.

Both the ProxyrEntry and ProxyExit conditions cannot be combined with other rules or trailing or protective stops.  The ProxyExit 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.

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.

The NeuroShell Trader can optimize the spread values for you to find the best entry and exit points. However, for the long and short entries to work in tandem, the spreads need to be the same.

NeuroShell makes it easy to link these values. First set up all trading rules as described above. 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 make the same association on the Short Entry tab. When it comes to choosing a name, 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 ProxyExit 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 predicted and actual values of the close 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 predicted value and actual value of the close 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 trading with proxy pairs requires specific settings for some of the Trading Strategy parameters. These settings are described below:

Dates tab: set according to your preferences.

Sizing tab: select Buy a fixed dollar 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 to pay for both sides of a pair trade.

Costs tabs: set according to your preferences.

Advanced tab: Select the button to optimize across all chart pages 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 to 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 complete, click Finished to display the buy/sell signals on the chart.  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 read the help file for Advanced Indicator Set 3.

Click here to download the example chart.



Was this article helpful?

Related Articles