November 2013 Newsletter – ChaosHunter Pairs Trading in NeuroShell Trader

November 12, 2013

 
ChaosHunter Pairs Trading in NeuroShell Trader
by Marge Sherald, CEO

 

I have previously written about using a neural network to find instrument pairs in order to create a market neutral trading system.  (See the article “Neural Network Pair Trading” in the February 2010 issue ofTechnical Analysis of STOCKS & COMMODITIES magazine.)  This type of system is based on the belief that future prices of two similar securities will converge if they are out of alignment.  Once a pair is identified, you buy one security and sell the other short when they are out of alignment to keep the trading system neutral.

The system described in the article used a neural network to find a suitable pair from a basket of securities that move in the same direction, even though the prices don’t cross.

The neural network chose the close of one of the candidate stocks as an input to the model that predicted the price of the base stock.

The next step compared the predicted value with the actual price of the base stock an calculated the spread.  The optimizer in NeuroShell Trader found the entry and exit spreads that generated the most profit.

Consolidated Edison, the base stock shown in green, is flanked by Amer Electric shown in blue and Duke Energy shown in pink.  Even though Amer Electric and Duke Energy rarely cross Consolidated Edison, they still may be pair traded with Edison using ChaosHunter.

 ChaosHunter as an Alternative

I wanted to know if ChaosHunter could create a formula for that prediction rather than using a neural network.  I developed the pair trading system in two steps.  First I built a ChaosHunter prediction for the price of Edison based on another stock in the same sector.  (In the process ChaosHunter chose which stock to pair trade with Edison.)

Next I let the optimizer in NeuroShell Trader evaluate the spread between the actual and predicted values of the stock to generate simultaneous buy/sell hedging signals.  

How It Works

I created a chart in NeuroShell Trader for Consolidated Edison (ED) and added the close for both Amer Electric Pwr (AEP) and Duke Energy (DUK) and exported the data for use in ChaosHunter.

The inputs for the ChaosHunter model were the close of Duke Energy and Amer Electric and the output was the close of Consolidated Edison.  As you can see from the chart, the prices did not cross naturally but they did follow one another.  I wanted ChaosHunter to find a formula that relates the price of Duke or Amer Electric to Edison.

This relationship had to be a simple linear relationship (that is, each stock is multiplied by a constant plus another optional constant).  Therefore I only selected functions in ChaosHunter from the arithmetic category:  plus, minus, multiply, or divide.

ChaosHunter found the following formula:

Predicted = (7.211195 – ((-6.670421) – (0.5390008 * Duke Energy Corporation Close))) – (-9.102246)

If you are familiar with ChaosHunter you know that it generates many formulas as it runs.  ChaosHunter found some formulas that included both Duke and Amer Electric, but I chose a formula which only included Duke to make trading simpler.  The mean squared error for many of the formulas was very close, so it did not make a difference in the outcome which formula was used for the prediction.

In order to trade the pairs, I brought the ChaosHunter prediction formula back over to NeuroShell Trader by means of the Trader’s ability to call ChaosHunter formulas.  I added the formula to the chart by selecting the ChaosHunter Scientific Output indicator from the External Program and Library Calls category, and then chose the ChaosHunter model file with the .md extension.

The chart displays the actual and predicted values for Edison as well as the absolute value of the difference between the two values.

I added a chart page for Duke Energy to the Edison chart in order to trade both instruments.

To gauge the value of the spread between the actual and predicted values for use in the trading rules, I inserted the Absolute value indicator from the Arithmetic category and subtracted the ChaosHunter predicted value of Edison from the actual value of Edison.

NeuroShell Trader generated the trading signals based on the spread of the predicted and actual values of Consolidated Edison. 

On the same chart, I added a Trading Strategy, and used the ProxyEntry and ProxyExit indicators from Advanced Indicator Set 3 to create the trading rules.  These are unique indicators that cause the Trader to go long on one stock and simultaneously short on another stock.  (Normally the NeuroShell Trader creates models for each stock that trade independently from one another.)

Long and Short entry rules: 

 Insert the Relational Indicator A = B. 

A = ProxyEntry indicator. 

B = 1 for the Long Entry and B = -1 for the Short Entry.

The B values are used to keep track of the simultaneous trades on both stocks and should not be optimized.

All entries use the same ProxyEntry parameters in order for the trades to occur simultaneously.

Proxy Entry Parameters:

Close = Close of the current chart page

Price 1 = Consolidated Edison

Price 2 = Duke Energy

Proxy1 = actual value of the Consolidated Edison close

Proxy2 = ChaosHunter predicted value of the Consolidated Edison close

Spread = 3 (Entry Spread set according to the difference between the actual and predicted values)

The ProxyEntry indicator uses the close of the current chart page and compares it with the close of Price 1 (Consolidated Edison) and Price 2 (Duke Energy) to keep track of which stock is being traded. Proxy1 and Proxy2 refer to the actual and predicted values of ED.  The spread is the difference between those values and tells the system when to trade.

I linked the LongEntry and Short Entry spread values with the name “Entry Spread” so the chart would trade both stocks in the pair at the same time.

Long and short exit rules:

On the exit side, I linked the Exit Spread and Stop Spread parameters for the same reason.

 Long and Short Exit Rule:

 Proxy Exit parameters:

Close = close of the current chart page

Proxy1 = Actual value of the Consolidated Edison close

Proxy2 = ChaosHunter predicted value of the Consolidated Edison close

Spread = 1 (Exit spread)

Stopspread = 7 (Stop spread)

The ProxyExit indicator uses the close of the current chart page to keep track of which stock is being traded.  Proxy1 and Proxy2 refer to the actual close of Edison and the predicted value from ChaosHunter.  The exit spread is the difference between those values where you want to exit a trade. The stop spread is the emergency exit.

Setting the Spread Values Correctly

When you establish the ranges for the different spread values in the Proxy indicators, it is important that the following relationship is maintained:

Exit spread  < entry spread < stop spread.

In this chart I set the range for the exit spread from 0.1 to 1.99, the range for the entry spread from 2 to 4, and the stop spread from 5.1 to 7.

 Note:  It is important that the same stocks are listed in the same order on all trading conditions.  The same applies to Proxy 1 and 2.  Listing the stocks in alphabetical order is an easy method to remember the order.   Also, do not add any other trading rules or protective stops to this trading system in order to keep the pair trading balanced.
Proof of Concept
The chart showed that I could use a ChaosHunter model in place of a neural network in order to create a successful pair trading system for two stocks that don’t normally cross very often.  The NeuroShell Trader and ChaosHunter files for this example will be posted on www.ward.net under examples in both the Trader and ChaosHunter sections.

Was this article helpful?

Related Articles