Pairs Trading

Synergy data mining application developed by AdaptiveTradingSystems.com
Post Reply
jamess
Site Admin
Posts: 55
Joined: Wed Jan 04, 2017 9:52 pm

Pairs Trading

Post by jamess » Thu Apr 13, 2017 1:29 pm

I have started to look into pairs trading using Synergy. I noticed that the ratio chart of ZT (CME live cattle futures) and ZZ (CME lean hogs futures) looked interesting and thought I'd start with those markets.
zt-zw_ratio_chart.PNG
zt-zw_ratio_chart.PNG (78.82 KiB) Viewed 3660 times
The following points describe what I've done to date.

1. Created a CSV file containing the ratio of the ZT to ZZ closing prices and did a modeling run using the ratio as the traded security. The ratio was easy to model and the models appeared to be very robust. To create the CSV file I loaded ZT and ZZ in Synergy, exported the data, computed the ratio in Excel and then saved the result to a CSV file. The file had 2 columns which were the Date and ZT-ZZ_Close.

2. Next I wanted to create an index that would be representative of trading the pair. The approach to trading the pair was to go long and short the same dollar amounts. At this point I'm not concerned with the fact that they are futures contracts and it may not be possible to go long and short the exact same dollar amounts. The index that I ended up using isn't perfect, but was reasonable as an initial test of the concept. File ZT-ZZ.csv is the data file that I used and is attached to this post.

3. The ZT-ZZ index was fairly easy to model and robust models were produced. The modeling run has been uploaded to the Synergy online database.
zt-zw_example_model_stats.PNG
zt-zw_example_model_stats.PNG (102.68 KiB) Viewed 3660 times
Computing the returns accurately is easy enough for pairs, but Synergy isn't setup for that at the moment. At the moment I'm leaning towards creating a second application for trading synthetic securities. A synthetic security could be a pair or could involve more than 2 securities. One motivation is to find and model pairs that others are discarding. I will explain further later.

Kind Regards,

James
Attachments
ZT-ZZ.zip
(55.79 KiB) Downloaded 216 times

CarlosR
Posts: 51
Joined: Sun Jan 08, 2017 10:52 pm

Re: Pairs Trading

Post by CarlosR » Fri Apr 14, 2017 1:15 pm

James, this looks very interesting indeed. I'm looking forward to playing with the concept.

I would vote for keeping the functionality in Synergy, at least for the time being. I'm not sure it needs a separate product. But I'll have a more educated opinion once I've had a chance to experiment with it.

jamess
Site Admin
Posts: 55
Joined: Wed Jan 04, 2017 9:52 pm

Re: Pairs Trading

Post by jamess » Sat Apr 15, 2017 1:05 am

It would be nice to build support for modeling synthetic securities into Synergy. It would require substantial changes. Something like the following on the Data tab. Note that I'm using terminology from FOREX trading. If anyone has better terminology to use then please let me know.

- List for the Base securities.
- List for the Quote securities.
- Drag and drop data sources into these lists, or right click and add to base or quote list.
- Still have what is currently the Loaded Data list for data series that can be used by the models.

If modeling a pair then there would be 1 base security and 1 quote security. You could have 1 base security and 2 quote securities or 2 and 2 etc.

If you had 1 base security and 2 quote securities and you were going long the synthetic security then you would be going long x$ of the base security and going short x$/2 of the quote securities. That is, in dollar terms we are long the same total amount as we are short. That's assuming we don't start applying weights to each of the component securities. Weightings would normally be based on relative volatility of the components. Not sure that we need to go down that path.

Kind Regards,

James

jamess
Site Admin
Posts: 55
Joined: Wed Jan 04, 2017 9:52 pm

Re: Pairs Trading

Post by jamess » Sat Apr 15, 2017 1:45 am

A common approach to pairs trading is to compute an n bar moving average of the ratio between the 2 securities and standard deviation lines at +-2.5 and +-1. When the ratio exceeds +-2.5 standard deviations open a trade and then close it when the ratio crosses +-1 standard deviations. There are function blocks in Synergy along these lines. The ZSmaScore combined with the ExtremesTrader is similar.

Using what I'm calling the common approach, you would get about 3 trading signals per pair per year. That's a rough estimate. The common approach relies heavily on mean reversion. The Johansen test for cointegration is used to identify pairs where reversion to the mean has been occurring historically. The Johansen test basically fits one series to the other and models the residuals (difference) to see if the residuals are stationary. If the residuals are strongly stationary then they are mean reverting. Pairs trading in stocks was first done in the early 1900's as far as I know. Pairs trading is brilliant because many signals are removed without introducing lag. Long-term economic factors etc. are largely removed.

My thoughts are that we don't want to take the exact same approach. The goal of creating a synthetic security would be to reduce the complexity of the resulting series relative to any of it's components. You can imagine a market price history as being composed of a number of signals. Trend signals, signals from related markets, semi-periodic fluctuations, random shocks, etc. I'd like to cancel out the majority of signals to produce a series that is relatively easy to model and trade. As long as the resulting time series is easy to model, I don't care about cointegration tests etc. Also, I'm looking to produce models that are always in the market versus only entering trades when ratios are at extremes relative to the average.

Kind Regards,

James

jamess
Site Admin
Posts: 55
Joined: Wed Jan 04, 2017 9:52 pm

Re: Pairs Trading

Post by jamess » Sat Apr 15, 2017 1:58 am

Forgot to mention that the returns reported for the ZT-ZZ model are not going to be accurate. The ZT-ZZ index that I created had many of the properties that I was looking for, but does not result in accurate returns being reported in Synergy. To compute returns I would have to use a spreadsheet. If trading synthetic securities is built into the current version of Synergy then there would be work to do in this regard. The goal used when designing the index was to compute returns on the sum of the absolute value of the dollar amounts. So if going long $50,000 of ZT and short $50,000 of ZZ the 'investment' is $100,000. That's a standard approach. As mentioned, I couldn't quite achieve that with the ZT-ZZ index. Not sure that it is possible within the current Synergy framework.

Kind Regards,

James

jamess
Site Admin
Posts: 55
Joined: Wed Jan 04, 2017 9:52 pm

Re: Pairs Trading

Post by jamess » Wed Apr 19, 2017 3:12 am

I've finished working out how the trade returns will be calculated. Next, I want to prove that the approach is worth pursuing. To help do that I'm going to implement the Johansen Cointegration test. I should be able to make use of the Intel math libraries. Those libraries are highly optimized and I already have C# wrappers for them that I developed when evaluating their use in Synergy.

Kind Regards,

James

Post Reply